建立双主互备服务器

建立双主互备服务器

   张吉吉     2020年7月18日 05:41     402    

1、然后修改配置文件

masterA:

/etc/my.cnf

[mysqld]

server-id = 1

datadir = /mydata/data

log-bin = /mydata/data/mysql1-bin

binlog_format = ROW

relay_log = /mydata/data/relay-log

auto-increment-increment = 2

auto-increment-offset = 1 设置为奇数ID

sync_binlog = 1

sync_master_info = 1

sync_relay_log = 1

sync_relay_log_info = 1

 

masterB

/etc/my.cnf

[mysqld]

server-id = 2

datadir = /mydata/data

log-bin = /mydata/data/mysql2-bin

binlog_format = ROW

relay_log = /mydata/data/relay-log

auto-increment-increment = 2

auto-increment-offset = 2 设置为偶数ID

sync_binlog = 1

sync_master_info = 1

sync_relay_log = 1

sync_relay_log_info = 1

 

2、在两个数据库上创建复制用户

masterA:

GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'mysync'@'192.168.60.141' IDENTIFIED BY '123456'; FLUSH PRIVILEGES;

masterB:

GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'mysync'@'192.168.60.140' IDENTIFIED BY '123456'; FLUSH PRIVILEGES;

3、查看二进制文件位置并且配置双主

查看二进制文件

SHOW MASTER LOGS;

以下的配置参数MASTER_LOG_FILEMASTER_LOG_POS必须以命令出来的结果为准。

masterA:

CHANGE MASTER TO MASTER_HOST='192.168.60.141',MASTER_USER='mysync',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql2-bin.000001',MASTER_LOG_POS=1112;

START SLAVE;

masterB:

CHANGE MASTER TO

MASTER_HOST='192.168.60.140',MASTER_USER='mysync',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql1-bin.000001',MASTER_LOG_POS=1112;

START SLAVE;

 


文章评论

0

其他文章