搭建mysql半复制(Semisynchronous Replication)

(1)规划主从机
主机:10.10.54.86
从机:10.10.54.85

(2)安装plugin
主机:
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.02 sec)

从机:
mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.07 sec)

(3)配置主机从机参数
主机:
[root@nan86 tmp]# vim /etc/my.cnf 
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000

从机:
[root@nan85 ~]# vim /etc/my.cnf 
rpl_semi_sync_slave_enabled=1

查看是否安装:
主机:
mysql> select * from mysql.plugin;
+----------------------+--------------------+
| name                 | dl                 |
+----------------------+--------------------+
| rpl_semi_sync_master | semisync_master.so |
+----------------------+--------------------+

从机:
mysql> select * from mysql.plugin;
+---------------------+-------------------+
| name                | dl                |
+---------------------+-------------------+
| rpl_semi_sync_slave | semisync_slave.so |
+---------------------+-------------------+

(3)重启slave
mysql> stop slave io_thread;
Query OK, 0 rows affected (0.07 sec)

mysql> start slave io_thread;
Query OK, 0 rows affected (0.00 sec)

##############
测试
主:10.10.54.86
从:10.10.54.85 

(1)关闭slave上的I/O
mysql> slave stop;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 10.10.54.86
                  Master_User: slave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000023
          Read_Master_Log_Pos: 336799606
               Relay_Log_File: nan85-relay-bin.000012
                Relay_Log_Pos: 168399958
        Relay_Master_Log_File: master-bin.000023
             Slave_IO_Running: No
            Slave_SQL_Running: No

(2)禁止从主上传送数据
从上:
[root@nan85 ~]# iptables -A INPUT -s 10.10.54.86 -j DROP
主上
[root@nan86 tmp]# ping 10.10.54.85
PING 10.10.54.85 (10.10.54.85) 56(84) bytes of data.

(3)
在主上导入数据库
mysql> source employees.sql

(4)
在从上关闭防火墙
[root@nan85 ~]# iptables -F
打开slave
mysql> slave start;
mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.54.86
                  Master_User: slave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000023
          Read_Master_Log_Pos: 620231568
               Relay_Log_File: nan85-relay-bin.000017
                Relay_Log_Pos: 29269779
        Relay_Master_Log_File: master-bin.000023
             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: 544691926
              Relay_Log_Space: 283432519
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: Yes
           Master_SSL_CA_File: /usr/local/mysql/ssl/cacert.pem
           Master_SSL_CA_Path: 
              Master_SSL_Cert: /usr/local/mysql/ssl/slave.crt
            Master_SSL_Cipher: 
               Master_SSL_Key: /usr/local/mysql/ssl/slave.key
        Seconds_Behind_Master: 108

注意前面 Seconds_Behind_Master: 108
有延迟。

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
####
mysql> show variables like 'rpl_semi_sync%';
mysql> show status like 'rpl_semi_sync%';


你可能感兴趣的:(搭建mysql半复制(Semisynchronous Replication))