Mysql 5.1 配置双主

xiaoxiao2021-02-27  248

双主的配置,其实就是做两次主从,主要是解决双主自增 id 不能重复的问题,用 auto-increment-increment 和 auto-increment-offset 来避免出现混乱。 auto-increment-increment 写主Master机器的数量,aotu-increment-offset 是默认的开始值,如果是 4 太机器做主, auto-increment-increment = 4 aotu-increment-offset 后面的值,四个机器分别是 1 2 3 4,就能避开重复。 mysql 5.1 安装步骤参考 5.1 主从 环境说明:两台机器 ,centos 6.5,mysql 5.1 第一台机器:hostname: centos2      ip: 192.168.32.142 第二台机器:hostname: centos3      ip: 192.168.32.143 Centos 2  配置文件 # vim /etc/my.cnf server-id       = 1 log-bin=mysql-bin auto-increment-increment=2 auto-increment-offset=1 log-slave-updates auto-increment 两行的配置,使 centos 2 字段产生的数值是 奇数1,3,5,7 下面的centos 3 产生的是 2,4,6,8 等,这样会避开双主 id 重复的问题。 mysql> grant replication slave on *.* to 'user143'@'192.168.32.143' identified by 'user143'; mysql> flush privileges; mysql> show master status; +------------------+----------+--------------+------------------+ | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 |      350 |              |                  | +------------------+----------+--------------+------------------+ Centos 3 配置文件 server-id       = 101 log-bin=mysql-bin auto-increment-increment=2 auto-increment-offset=2 log-slave-updates mysql> grant replication slave on *.* to 'user142'@'192.168.32.142' identified by 'user142'; mysql> flush privileges; mysql> show master status; +------------------+----------+--------------+------------------+ | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 |      350 |              |                  | +------------------+----------+--------------+------------------+ 1 row in set (0.01 sec)
Centos 2 SQL 授权 mysql> change master to master_host='192.168.32.143', master_user='user142', master_password='user142',master_log_file='mysql-bin.000001', master_log_pos=350; Query OK, 0 rows affected (0.10 sec) Centos 3 授权 > change master to master_host='192.168.32.142', master_user='user143', master_password='user143', master_log_file='master-bin.000001', master_log_pos=350; Query OK, 0 rows affected (0.13 sec)                                                                                                              
转载请注明原文地址: https://www.6miu.com/read-8663.html

最新回复(0)