mysql-5.6.x半同步複製配置

本文環境  
主庫:CentOS6.5 x64 192.168.0.65 mysql-5.6.29    
備庫:CentOS6.5 x64 192.168.0.66 mysql-5.6.29

接上文: mysql-5.6主從同步配置示例http://koumm.blog.51cto.com/703525/1764093

半同步複製的概念:    
mysql5.5.x以上版本支持半同步複製,當Slave主機連接到Master時,能夠查看其是否處於半同步複製的機制。當Master上開啓半同步複製的功能時,至少應該有一個Slave開啓其功能。此時,一個線程在Master上提交事務將受到阻塞,直到得知一個已開啓半同步複製功能的Slave已收到此事務的所有事件,或等待超時。當一個事務的事件都已寫入其relay-log中且已刷新到磁盤上,Slave纔會告知已收到。如果等待超時,也就是Master沒被告知已收到,此時Master會自動轉換爲異步複製的機制。當至少一個半同步的Slave趕上了,Master與其Slave自動轉換爲半同步複製的機制。半同步複製的功能要在Master,Slave都開啓,半同步複製纔會起作用;否則,只開啓一邊,它依然爲異步複製。


一、半同步主服務器配置

1. mysql主服務器配置

(1) 在主服務器上加入半自動配置文件參數

# vi /etc/my.cnf

[mysqld]  
log-bin                = master-bin    
log-bin-index          = master-bin.index    
binlog_format          = mixed    
server-id              = 1    
expire-logs-days       = 7    
rpl_semi_sync_master_enabled = 1    
rpl_semi_sync_master_timeout = 1000 # 1 second


(2) 安裝半同步配置插件

mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';

(3) 配置半同步插件

mysql> show global variables like '%rpl%';  
+------------------------------------+-------+    
| Variable_name                      | Value |    
+------------------------------------+-------+    
| rpl_recovery_rank                  | 0     |    
| rpl_semi_sync_master_enabled       | OFF   |    
| rpl_semi_sync_master_timeout       | 10000 |    
| rpl_semi_sync_master_trace_level   | 32    |    
| rpl_semi_sync_master_wait_no_slave | ON    |    
+------------------------------------+-------+

(4) 啓用半同步插件

mysql> set global rpl_semi_sync_master_enabled =1;


(5) 配置超時

mysql> set rpl_semi_sync_master_timeout 1000;

mysql> show global status like 'rpl_semi%';  
+--------------------------------------------+-------+    
| Variable_name                              | Value |    
+--------------------------------------------+-------+    
| Rpl_semi_sync_master_clients               | 0     |    
| Rpl_semi_sync_master_net_avg_wait_time     | 0     |    
| Rpl_semi_sync_master_net_wait_time         | 0     |    
| Rpl_semi_sync_master_net_waits             | 0     |    
| Rpl_semi_sync_master_no_times              | 0     |    
| Rpl_semi_sync_master_no_tx                 | 0     |    
| Rpl_semi_sync_master_status                | ON    |    
| Rpl_semi_sync_master_timefunc_failures     | 0     |    
| Rpl_semi_sync_master_tx_avg_wait_time      | 0     |    
| Rpl_semi_sync_master_tx_wait_time          | 0     |    
| Rpl_semi_sync_master_tx_waits              | 0     |    
| Rpl_semi_sync_master_wait_pos_backtraverse | 0     |    
| Rpl_semi_sync_master_wait_sessions         | 0     |    
| Rpl_semi_sync_master_yes_tx                | 0     |    
+--------------------------------------------+-------+    
14 rows in set (0.00 sec)

其它一些性能及相關參數:


2. 重啓主服務器,使配置文件生效

# service mysqld restart 


二、半同步從服務器配置


1. mysql從服務器配置

(1) 加入如下半同步配置。

# vi /etc/my.cnf

[mysqld]  
log-bin                = mysql-bin    
binlog_format          = mixed    
server-id              = 11    
relay-log              = slave-relay-bin    
relay-log-index        = slave-relay-bin.index    
replicate_wild_ignore_table = mysql.%    
rpl_semi_sync_slave_enabled = 1


(2) 安裝半同步配置插件

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


(3) 配置半同步插件

mysql> show global variables like '%rpl%';  
+---------------------------------+----------+    
| Variable_name                   | Value    |    
+---------------------------------+----------+    
| rpl_semi_sync_slave_enabled     | ON       |    
| rpl_semi_sync_slave_trace_level | 32       |    
| rpl_stop_slave_timeout          | 31536000 |    
+---------------------------------+----------+    
3 rows in set (0.00 sec)

(4) 啓用半同步插件

mysql> set global rpl_semi_sync_master_enabled =1;  
Query OK, 0 rows affected (0.00 sec)

mysql> show global variables like '%rpl%';  
+---------------------------------+----------+    
| Variable_name                   | Value    |    
+---------------------------------+----------+    
| rpl_semi_sync_slave_enabled     | ON       |    
| rpl_semi_sync_slave_trace_level | 32       |    
| rpl_stop_slave_timeout          | 31536000 |    
+---------------------------------+----------+    
3 rows in set (0.00 sec)


(5) 重啓同步進程

mysql> stop slave;  
Query OK, 0 rows affected (0.02 sec)

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

mysql> show slave status \G;  
*************************** 1. row ***************************    
               Slave_IO_State: Waiting for master to send event    
                  Master_Host: 192.168.0.65    
                  Master_User: repl    
                  Master_Port: 3306    
                Connect_Retry: 60    
              Master_Log_File: master-bin.000005    
          Read_Master_Log_Pos: 120    
               Relay_Log_File: testdb-relay-bin.000012    
                Relay_Log_Pos: 284    
        Relay_Master_Log_File: master-bin.000005    
             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: mysql.%    
                   Last_Errno: 0    
                   Last_Error:    
                 Skip_Counter: 0    
          Exec_Master_Log_Pos: 120    
              Relay_Log_Space: 622    
              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    
Master_SSL_Verify_Server_Cert: No    
                Last_IO_Errno: 0    
                Last_IO_Error:    
               Last_SQL_Errno: 0    
               Last_SQL_Error:    
  Replicate_Ignore_Server_Ids:    
             Master_Server_Id: 1    
                  Master_UUID: c8bb22a1-024e-11e6-a1e8-000c29225fa0    
             Master_Info_File: /usr/local/mysql-5.6.29-linux-glibc2.5-x86_64/data/master.info    
                    SQL_Delay: 0    
          SQL_Remaining_Delay: NULL    
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it    
           Master_Retry_Count: 86400    
                  Master_Bind:    
      Last_IO_Error_Timestamp:    
     Last_SQL_Error_Timestamp:    
               Master_SSL_Crl:    
           Master_SSL_Crlpath:    
           Retrieved_Gtid_Set:    
            Executed_Gtid_Set:    
                Auto_Position: 0    
1 row in set (0.00 sec)


2. 在主服務器上可以查看有1個從服務器連接過來

mysql> show global status like 'rpl_semi%';  
+--------------------------------------------+-------+    
| Variable_name                              | Value |    
+--------------------------------------------+-------+    
| Rpl_semi_sync_master_clients               | 1     |    
| Rpl_semi_sync_master_net_avg_wait_time     | 0     |    
| Rpl_semi_sync_master_net_wait_time         | 0     |    
| Rpl_semi_sync_master_net_waits             | 0     |    
| Rpl_semi_sync_master_no_times              | 0     |    
| Rpl_semi_sync_master_no_tx                 | 0     |    
| Rpl_semi_sync_master_status                | ON    |    
| Rpl_semi_sync_master_timefunc_failures     | 0     |    
| Rpl_semi_sync_master_tx_avg_wait_time      | 0     |    
| Rpl_semi_sync_master_tx_wait_time          | 0     |    
| Rpl_semi_sync_master_tx_waits              | 0     |    
| Rpl_semi_sync_master_wait_pos_backtraverse | 0     |    
| Rpl_semi_sync_master_wait_sessions         | 0     |    
| Rpl_semi_sync_master_yes_tx                | 0     |    
+--------------------------------------------+-------+    
14 rows in set (0.00 sec)

3. 重啓從服務器,使配置文件生效

# service mysqld restart 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章