MySQL cluster master-slave and multi-master

basic environment

System: linux
mysql version: 5.5
Master server IP: 192.168.1.101
Slave server IP: 192.168.1.102

1. The master server (master) should open the binary log
2. The slave server (slave) should open the relay log
3. Establish a replcation account on the master server (master) to authorize the slave server (slave)
4. Modify the slave server (slave) master server
5. Start slave

Steps:

1. Operation of the main library

vim /etc/my.cnf

Then add the following configuration under [mysqld]

# Give the server a unique id
server-id=1
#Enable binary log
log-bin=mysql-bin
#Specify the log format
binlog-format=mixed

Restart mysql after saving

2. Operation from the library

vim /etc/my.cnf

Then add the following configuration under [mysqld]

# Give the server a unique id
server-id=2
#Relay log from server
relay-log=mysql-relay

Restart mysql after saving

3. Create the corresponding replication account on the master server

grant replication client,replication slave on *.* to replName@’192.168.%.%’ identified by ‘123456’;

Among them, replName is the account name, 123456 is the password, both of which can be modified by yourself

4. On the slave server, specify the master server to be replicated through the statement (note that one master and multiple slaves can be used, not one slave and multiple masters).

change master to
master_host=’192.168.1.101’, 
master_user=’replName’, 
master_password=’123456’, 
master_log_file=’mysql-bin.000001’, 
master_log_pos=0;

//There is no such setting as slaveof

Description:
master_host is the master server IP
master_user is the master server replication account
just set master_password is the master server replication account password just set
master_log_file is the master server binary log file
master_log_pos is the starting point for copying the binary file
master_log_pos and master_log_file can be passed in the master database Execute show master status; get

5. Start slave

slave start

Pay attention to firewall settings

master master configuration

After the master-slave configuration is completed, the master-master configuration is very simple,

The basic idea:

1: Both servers are set up with binary logs and relay logs
2: Both are set up with replcation replication accounts
3: Both are set up with each other as their own master

 

 

MySQL provides mature master-master replication, combined with keepalived dynamic IP , two nodes can be ready to provide services at the same time, and when any one fails, the other one immediately takes over seamlessly.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326358109&siteId=291194637