(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%';