Master-Master(双主)
1、测试环境 Master/Slave Master1/Slave1 IP 192.168.1.13 192.168.1.10
为了保持干净的环境:两边服务器
rm -rf /var/lib/mysql/* service mysqld restartIP:192.168.1.13
IP:192.168.1.10
2、主服务器授权
分别在Master/Slave和Master1/Slave1上创建一个用户并授予相应权限。 mysql> grant replication slave on *.* to identified by '123′;mysql> grant replication slave on *.* to identified by '123′;
然后退出mysql控制台,停止mysql服务:
mysql> \q 3、配置Mysql主配置文件/etc/my.cnf 在/etc/my.cnf配置文件[mysqld]模块添加如下参数 Master/Slave(192.168.1.13): [root@bogon ~]# vim /etc/my.cnf server-id = 1 log-bin = mysql-bin master-host = 192.168.1.13 master-user = srepli master-password = 123 master-port = 3306 replicate-ignore-db = mysql
Master1/Slave1(192.168.1.10):
[root@repli1 ~]# vim /etc/my.cnf server-id = 2 log-bin = mysql-bin master-host = 192.168.1.10 master-user = repli master-password = 123 master-port = 3306 replicate-ignore-db = mysql4、查看同步状态
service mysqld restart //两边服务器执行 在Master1/Slave1上查看 mysql> show slave status\G Slave_IO_Running: Yes Slave_SQL_Running: Yes 在master/Slave上查看: mysql> show slave status\G Slave_IO_Running: Yes Slave_SQL_Running: Yes 注:如果没有先启动的服务器Slave_IO_Running: NO mysql> slave stop; mysql> slave start; mysql> show slave status\G 两边服务器建库,建表,插入语句