本文环境
主库:centos6.5 x64 192.168.0.65 mysql-5.6.29
备库:centos6.5 x64 192.168.0.66 mysql-5.6.29
半同步复制的概念:
mysql5.5.x以上版本支持半同步复制,当slave主机连接到master时,能够查看其是否处于半同步复制的机制。当master上开启半同步复制的功能时,至少应该有一个slave开启其功能。此时,一个线程在master上提交事务将受到阻塞,直到得知一个已开启半同步复制功能的slave已收到此事务的所有事件,或等待超时。当一个事务的事件都已写入其relay-log中且已刷新到磁盘上,slave才会告知已收到。如果等待超时,也就是master没被告知已收到,此时master会自动转换为异步复制的机制。当至少一个半同步的slave赶上了,master与其slave自动转换为半同步复制的机制。半同步复制的功能要在master,slave都开启,半同步复制才会起作用;否则,只开启一边,它依然为异步复制。
# 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
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
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 |
+------------------------------------+-------+
mysql> set global rpl_semi_sync_master_enabled =1;
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)
其它一些性能及相关参数:
# service mysqld restart
log-bin = mysql-bin
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
mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
query ok, 0 rows affected (0.00 sec)
+---------------------------------+----------+
| 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)
mysql> set global rpl_semi_sync_master_enabled =1;
mysql> stop slave;
query ok, 0 rows affected (0.02 sec)
mysql> start slave;
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)
| rpl_semi_sync_master_clients | 1 |