Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed steps for multi-machine configuration of mysql database

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Here are the detailed steps for configuring mysql databases on multiple machines. The secret of the text lies in its proximity to the topic. So, gossip will not talk about it, we look directly at the following bar, I believe that after reading the detailed steps of the multi-machine configuration mysql database this article you will certainly benefit.

One-master multi-slave configuration

Environment:

Host A (huangzp2): 172.16.115.157

Host B (huangzp3): 172.16.115.100

Host C (huangzp4): 172.16.115.87

Description: Multiple Slave Cloud Virtual Machine provide backup for a Master Cloud Virtual Machine; still master-slave configuration; at least 3 machines required

I. mysql mysql-server installed on 3 Cloud Virtual Machine

yum install mysql mysql-server -y

II. Modify the configuration file/etc/my.cnf and restart

On host A (master):

On Host B (slave):

Host C(slave):

III. On Master Cloud Virtual Machine A, authorize replication slave to multiple Slave Cloud Virtual Machine (Host B and Host C)

grant replication slave on *.* to 'silen'@'172.16.115.100' identified by '123456';

grant replication slave on *.* to 'silen'@'172.16.115.87' identified by '123456';

show master status;

IV. Write master.info info from above, turn on slave, and view slave status

On Host B (slave):

On Host C (slave):

v. aa is created on the primary Cloud Virtual Machine, see db1 library is also created synchronously from the Cloud Virtual Machine

Master A:

From B:

From C:

Multi-master and one-slave configuration

Environment:

Host A (huangzp2): 172.16.115.157

Host B (huangzp3): 172.16.115.100

Host C (huangzp4): 172.16.115.87

Description: No matter whether it is master/slave, master/slave, or multiple slave, if the master has multiple databases, more slave Cloud Virtual Machine is needed for backup, and the resource overhead is relatively high; Multiple masters and one slave, one slave Cloud Virtual Machine provides backup for multiple master Cloud Virtual Machine, and there are also problems. That is, two mysql processes cannot be opened simultaneously on a slave Cloud Virtual Machine.(mysqld_safe can only open one database process), solve: Instead of mysqld_safe, you need mysqld_multi, a Cloud Virtual Machine that provides multiple mysql processes

I. 3 machines yum install -y mysql mysql-server and modify the configuration file/etc/my.cnf

A:

Main II B:

II. License to Slave Cloud Virtual Machine

A:

grant replication slave on *.* to 'silen'@'172.16.115.87' identified by '123456';

Main II B:

III. Edit the configuration file vim /etc/my.cnf from C Cloud Virtual Machine

[mysqld_multi]

mysqld=/usr/bin/mysqld_safe

mysqladmin=/usr/bin/mysqladmin

user=root

password=123456

log=/tmp/multi.log

[mysqld157]

port=3306

datadir=/var/lib/mysqla

pid-file=/var/lib/mysqla/mysqld.pid

socket=/var/lib/mysqla/mysql.sock

user=mysql

server-id=87

[mysqld100]

port=3307

datadir=/var/lib/mysqlb

pid-file=/var/lib/mysqlb/mysqld.pid

socket=/var/lib/mysqlb/mysql.sock

user=mysql

server-id=87

Description:

Add [mysqld_multi] module, call mysqld_safe again

mysqladmin The location of the password modification tool

log in as root

Define a log file

Add and master a communication module [mysql157], 157 digital custom naming

The specified port is 3306

data repository directory

pid file directory

socket directory

logged-in user

server-id

Except server-id is the same (because id does not conflict in different groups), other and main two cannot be the same

IV. From the Cloud Virtual Machine, initialize mysqla and mysqlb, create the corresponding directories, and modify the owner to mysql, using/usr/bin/mysql_install_db

/usr/bin/mysql_install_db --datadir=/var/lib/mysqla

/usr/bin/mysql_install_db --datadir=/var/lib/mysqlb

chown -R mysql /var/lib/mysqla/

chown -R mysql /var/lib/mysqlb/

v. Start mysql, use mysql_multi, specify configuration file and module

mysqld_multi --defaults-file=/etc/my.cnf start 157

mysqld_multi --defaults-file=/etc/my.cnf start 100

vi. To log in to mysql, specify the port number and socket file

Log in to mysql157 and add master.info to communicate with master one. Open salve and view status:

mysql -P 3306 -S /var/lib/mysqla/mysql.sock

Log in mysql100, and add Master.info to communicate with Master II, open salve, view status:

mysql -P 3307 -S /var/lib/mysqlb/mysql.sock

VII. Master 1 and Master 2 create databases db1 and db2 respectively, log in 157 and 100 from Cloud Virtual Machine respectively, and display synchronized creation.

Master 1 creates db1:

Main 2 Create db2:

From 157 login to view:

mysql -P 3306 -S /var/lib/mysqla/mysql.sock

Log in from 100 to view:

mysql -P 3307 -S /var/lib/mysqlb/mysql.sock

For the above multi-machine configuration mysql database detailed steps related to the content, we still do not understand anything? Or if you want to know more about it, you can continue to pay attention to our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report