免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1941 | 回复: 0
打印 上一主题 下一主题

CentOS MySQL Master Master Replication配置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-23 02:56 |只看该作者 |倒序浏览
1、前期准备:
   A、安装Linux(CentOS系统),MySQL相关软件,本文使用CentOS自带系统。
   B、CentOS-Master1(IP:192.168.227.128),CentOS-Master2(IP:192.168.227.129)两个系统上均关闭防火墙
2、配置MM模式:
   A、在Master1上修改MySQL配置文件(/etc/my.cnf)追加内容如下:
      server-id=1
      master-host=192.168.227.129
      master-user=repl
      master-password=123456
      master-port=3306
      master-connect-retry=60
      log-bin=mysql-bin
      binlog-do-db=test
     并进入MySQL的shell做如下操作:
 mysql> grant replication slave on *.* to 'repl'@192.168.227.128 identified by '123456';
      mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000014 |      782 | test         |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
注:红色字体部分要在Master2上做Chang Master to操作时使用。
mysql> change master to
master_host='192.168.227.129',master_user='repl',master_password='123456',master_log_file='mysql-bin.000009',master_log_pos='1466'
mysql> stop slave;
 
mysql> show slave status\G
*************************** 1. row ***************************
             Slave_IO_State: Waiting for master to send event
                Master_Host: 192.168.227.129
                Master_User: repl
                Master_Port: 3306
              Connect_Retry: 60
            Master_Log_File: mysql-bin.000009
        Read_Master_Log_Pos: 1466
             Relay_Log_File: mysqld-relay-bin.000005
              Relay_Log_Pos: 235
      Relay_Master_Log_File: mysql-bin.000009
           Slave_IO_Running: Yes
          Slave_SQL_Running: Yes
            Replicate_Do_DB:
        Replicate_Ignore_DB:
         Replicate_Do_Table:
     Replicate_Ignore_Table:
    Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
                 Last_Errno: 0
                 Last_Error:
               Skip_Counter: 0
        Exec_Master_Log_Pos: 1466
            Relay_Log_Space: 235
            Until_Condition: None
             Until_Log_File:
              Until_Log_Pos: 0
         Master_SSL_Allowed: No
         Master_SSL_CA_File:
         Master_SSL_CA_Path:
            Master_SSL_Cert:
          Master_SSL_Cipher:
             Master_SSL_Key:
      Seconds_Behind_Master: 0
1 row in set (0.00 sec)
mysql>
   B、在Master2上修改MySQL配置文件(/etc/my.cnf)追加内容如下:
      server-id=2
      master-host=192.168.227.128
      master-user=repl
      master-password=123456
      master-port=3306
      master-connect-retry=60
      log-bin=mysql-bin
      binlog-do-db=test
      并进入MySQL的shell进行如下操作:
     mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000009 | 1466     | test  
      |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
注:红字部分要在Master1上做Chang Master to操作时使用,
在MySQL的shell上做如下操作:
mysql> grant replication slave on *.* to 'repl'@192.168.227.128 identified by '123456';
mysql> change master to
master_host='192.168.227.128,master_user='repl',master_password='123456',master_log_file='mysql-bin.0000014',master_log_pos='782'
mysql> stop slave;
mysql> show slave status\G
*************************** 1. row ***************************
             Slave_IO_State: Waiting for master to send event
                Master_Host: 192.168.227.128
                Master_User: repl
                Master_Port: 3306
              Connect_Retry: 60
            Master_Log_File: mysql-bin.000014
        Read_Master_Log_Pos: 782
             Relay_Log_File: mysqld-relay-bin.000006
              Relay_Log_Pos: 235
      Relay_Master_Log_File: mysql-bin.000014
           Slave_IO_Running: Yes
          Slave_SQL_Running: Yes
            Replicate_Do_DB:
        Replicate_Ignore_DB:
         Replicate_Do_Table:
     Replicate_Ignore_Table:
    Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
                 Last_Errno: 0
                 Last_Error:
               Skip_Counter: 0
        Exec_Master_Log_Pos: 782
            Relay_Log_Space: 235
            Until_Condition: None
             Until_Log_File:
              Until_Log_Pos: 0
         Master_SSL_Allowed: No
         Master_SSL_CA_File:
         Master_SSL_CA_Path:
            Master_SSL_Cert:
          Master_SSL_Cipher:
             Master_SSL_Key:
      Seconds_Behind_Master: 0
1 row in set (0.00 sec)
mysql>
注:以上操作步骤中的信息是操作后才总结的,信息有不匹配的地方。
配置思想总结:
在Node1修改配置信息,并获取Mysql的master status信息,在Node2上使用Node1上的master status信息进行Chang Master to操作,执行show processlist\G及show slave status\G以确认是否正确启动。
在Node2修改配置信息,并获取Mysql的master status信息,在Node1上使用Node2上的master status信息进行Chang Master to操作,执行show processlist\G及show slave status\G以确认是否正确启动。
常见错误说明:
Slave_IO_State: Waiting for master to send event(表示已经正确连接上了)
                为空表示复制没有启动。
                为Connecting to master为没连接上master
mysql> show slave status\G
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
此两项线程显示为yes则正常!
注:配置操作期间参考很多网上资料在此表示感谢。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP