如何設置半同步複製, mysql
# 在主服務器上作如下配置 mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so'; mysql> SET GLOBAL rpl_semi_sync_master_enabled = 1; mysql> SET GLOBAL rpl_semi_sync_master_timeout = 1000; #vim /etc/my.cnf [mysqld] rpl_semi_sync_master_enabled=1 rpl_semi_sync_master_timeout=1000 #在從服務器上作如下配置 mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so'; mysql> SET GLOBAL rpl_semi_sync_slave_enabled = 1; mysql> STOP SLAVE IO_THREAD; START SLAVE IO_THREAD; #vim /etc/my.cnf [mysqld] rpl_semi_sync_slave_enabled=1
設置半同步步驟:sql
在Master和Slave的mysql命令行運行以下代碼:vim
# On Master 服務器
mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so'; ide
mysql> SET GLOBAL rpl_semi_sync_master_enabled = 1; spa
mysql> SET GLOBAL rpl_semi_sync_master_timeout = 1000; 插件
# On Slave 命令行
mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so'; 日誌
mysql> SET GLOBAL rpl_semi_sync_slave_enabled = 1; orm
mysql> STOP SLAVE IO_THREAD; START SLAVE IO_THREAD;
在Master和Slave的my.cnf中編輯:
# On Master
[mysqld]
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000 # 1 second
# On Slave
[mysqld]
rpl_semi_sync_slave_enabled=1
# 也可經過設置全局變量的方式來設置,以下:
set global rpl_semi_sync_master_enabled=1
# 取消加載插件
mysql> UNINSTALL PLUGIN rpl_semi_sync_master;
==============================================
查看從服務器上的semi_sync是否開啓:
mysql> SHOW GLOBAL STATUS LIKE 'rpl_semi%';
查看主服務器上的semi_sync是否開啓,注意clients 變爲1 ,證實主從半同步複製鏈接成功:
mysql> SHOW GLOBAL STATUS LIKE 'rpl_semi%';
設置主-主複製:
一、在兩臺服務器上各自創建一個具備複製權限的用戶;
二、修改配置文件:
# 主服務器上
[mysqld]
server-id = 10
log-bin = mysql-bin
relay-log = relay-mysql
relay-log-index = relay-mysql.index
auto-increment-increment = 2
auto-increment-offset = 1
# 從服務器上
[mysqld]
server-id = 20
log-bin = mysql-bin
relay-log = relay-mysql
relay-log-index = relay-mysql.index
auto-increment-increment = 2
auto-increment-offset = 2
三、若是此時兩臺服務器均爲新創建,且無其它寫入操做,各服務器只需記錄當前本身二進制日誌文件及事件位置,以之做爲另外的服務器複製起始位置便可
server1|mysql> SHOW MASTER STATUS\G
************************** 1. row ***************************
File: mysql-bin.000001
Position: 710
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)
server2|mysql> SHOW MASTER STATUS\G
mysql> SHOW MASTER STATUS\G
*************************** 1. row ***************************
File: mysql-bin.000003
Position: 811
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)
四、各服務器接下來指定對另外一臺服務器爲本身的主服務器便可:
server1|mysql> CHANGE MASTER TO ...,MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=811
server2|mysql> CHANGE MASTER TO ...,MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=710