mysql主主及并行复制的搭建

两台机器互为主从。

机器1:192.168.1.160

机器2:192.168.1.164

修改两台机器的my.cnf文件,server-id,log-bin,auto-increment-increment,auto-increment-offset   后面两个参数为防止主键冲突而设置。

主主配置有两个要点:

1、复制账号

2、定位master信息。

所以,在两台机器上分别执行:

show master status;查看二进制文件的名称与位置,然后执行:

机器1:GRANT REPLICATION SLAVE ON *.* TO 'bau1'@'192.168.1.164' IDENTIFIED BY '123456';        change master to master_host='192.168.1.164',master_user='bau1',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=452;      

机器2:GRANT REPLICATION SLAVE ON *.* TO 'bau1'@'192.168.1.160' IDENTIFIED BY '123456';        change master to master_host='192.168.1.160',master_user='bau1',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=452;

在机器 1上创建一个表,在机器2上查看。

在机器2上创建一个表,在机器1上查看。

如果都可以创建,那主主配置完成。

并行复制:

my.cnf配置(主):

gtid_mode=ON

enforce-gtid-consistency

binlog_format=row

my.cnf配置(从):

slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=6
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode=ON
log-slave-updates=ON
enforce-gtid-consistency

binlog_format=row

其他都一样,唯一不一样的地方是:

change master to master_host='192.168.18.102',master_user='backup',master_password='123456',master_port=3306,master_auto_position=1;

 

在实际生产环境中,不会真正用双主写入,主键冲突问题很难解决。

一般来说,把另一个主库作为备库使用。

猜你喜欢

转载自blog.csdn.net/baijiu1/article/details/80363900
今日推荐