天天看点

mysql (双主,互主)

Master-Master(双主)

1、测试环境

        Master/Slave                           Master1/Slave1 

IP    192.168.1.13                          192.168.1.10

为了保持干净的环境:两边服务器

rm -rf /var/lib/mysql/*

service mysqld restart

IP:192.168.1.13

<a href="http://blog.51cto.com/attachment/201304/150159455.jpg" target="_blank"></a>

 IP:192.168.1.10

<a href="http://blog.51cto.com/attachment/201304/150401419.jpg" target="_blank"></a>

 2、主服务器授权

分别在Master/Slave和Master1/Slave1上创建一个用户并授予相应权限。

<a href="http://blog.51cto.com/attachment/201304/150946216.jpg" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201304/151347593.jpg" target="_blank"></a>

然后退出mysql控制台,停止mysql服务:

mysql&gt; \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

<a href="http://blog.51cto.com/attachment/201304/153905767.jpg" target="_blank"></a>

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     = mysql

<a href="http://blog.51cto.com/attachment/201304/153645976.jpg" target="_blank"></a>

4、查看同步状态

service mysqld restart //两边服务器执行

在Master1/Slave1上查看

mysql&gt; show slave status\G

           Slave_IO_Running: Yes

           Slave_SQL_Running: Yes

在master/Slave上查看:

          Slave_IO_Running: Yes

          Slave_SQL_Running: Yes

注:如果没有先启动的服务器Slave_IO_Running: NO

mysql&gt; slave stop;

mysql&gt; slave start;

两边服务器建库,建表,插入语句

本文转自zhang25yun51CTO博客,原文链接:http://blog.51cto.com/1585654/1182110 ,如需转载请自行联系原作者

继续阅读