mysql的主主(M-M)复制配置

mysqlde 主主复制架构
 
一、环境描述
 
服务器 master1:   192.168.0.124
 
服务器 master2:   192.168.0.129
 
 
二、主主配置过程
 
 
1 、创建同步用户:
 
服务器 master1
 
grant replication slave,file on *.* to 'master'@'192.168.0.129' identified by '123456';
 
flush privileges;
 
服务器 master2
 
grant replication slave,file on *.* to 'master'@'192.168.0.124' identified by '123456';
 
flush privileges;
 
 
2 、修改 mysql 配置文件
 
master1 vim /etc/my.cnf
 
              log-bin=mysql-bin
              server-id  = 10
              replicate-do-db=mysql
              replicate-ignore-db=test
              auto_increment_increment=2
              auto_increment_offset=1
       service mysqld restart
 
master2
              log-bin=mysql-bin
              server-id  = 20
              replicate-do-db= mysql
              replicate-ignore-db=test
              auto_increment_increment=2
              auto_increment_offset=2
 
       service mysqld restart
     
 
3 、重启 mysql 服务后,进入 mysql 命令行
 
master1:
 
mysql> flush tables with read lock;
 
mysql> show master status; 记录二进制文件位置和 pos
------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000005 |      106 |              |                  |
+------------------+----------+--------------+------------------+
 
mysql> unlock tables;
 
mysql> change master to    
 > master_host='192.168.0.129',master_user='master',master_password='123456',master_log_file='mysql-bin.000004',      > master_log_pos=106;
 
mysql> start slave;
 
master2:
 
mysql> flush tables with read lock;
 
mysql> show master status;
------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 |      106 |              |                  |
+------------------+----------+--------------+------------------+
 
mysql> unlock tables;
mysql> change master to     
     > master_host='192.168.0.124',master_user='master',master_password='123456',
     > master_log_file='mysql-bin.000005', master_log_pos=106;
 
mysql> start slave;
 
 
4 、查看 master1 master2 的服务器的状态:
 
mysql> show slave status\G;
 
查看: Slave_IO_Running: Yes
 
           Slave_SQL_Running: Yes
 
都显示yes为状态正常,直接进行数据测试即可
 

你可能感兴趣的:(数据库,mysql,职场,休闲)