centos7下mysql5.6.30配置单机多实例主从半同步复制
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7下mysql5.6.30配置单机多实例主从半同步复制相关的知识,希望对你有一定的参考价值。
1.在master主服务器上执行:
mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME ‘semisync_master.so‘;
Query OK, 0 rows affected (0.30 sec)
mysql> SET GLOBAL rpl_semi_sync_master_enabled = 1;
Query OK, 0 rows affected (0.02 sec)
mysql> SET GLOBAL rpl_semi_sync_master_timeout = 1000;
Query OK, 0 rows affected (0.00 sec)
mysql> show global variables like ‘%rpl%‘;
+------------------------------------+----------+
| Variable_name | Value |
+------------------------------------+----------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 1000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_no_slave | ON |
| rpl_stop_slave_timeout | 31536000 |
+------------------------------------+----------+
5 rows in set (0.00 sec)
2.在slave从服务器上执行:
mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME ‘semisync_slave.so‘;
Query OK, 0 rows affected (0.04 sec)
mysql> SET GLOBAL rpl_semi_sync_slave_enabled = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> STOP SLAVE IO_THREAD;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> START SLAVE IO_THREAD;
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 |
+------------------------------------+----------+
4 rows in set (0.00 sec)
3.上面设置的都是临时的,重启服务器会失效,所以可以把配置添加到/usr/my.cnf 中:
[mysqld_multi]
mysqld=/usr/bin/mysqld_safe
mysqladmin=/usr/bin/mysqladmin
user=root
[mysqld3306]
port=3306
socket=/var/lib/mysql/mysql.sock
pid-file=/var/lib/mysql/localhost.localdomain.pid
datadir=/var/lib/mysql/
user=root
character_set_server=utf8
lower_case_table_names=1
max_connections=300
server-id=1
binlog-do-db=test
log-bin=master-bin
log-bin-index=master-bin.index
rpl_semi_sync_master_enabled=1 #新添加
rpl_semi_sync_master_timeout=1000 #新添加,此单位是毫秒
[mysqld3307]
port=3307
socket=/home/fuyouling/mutl_mysql/mysql_3307/mysql/mysql.sock
pid-file=/home/fuyouling/mutl_mysql/mysql_3307/mysql/localhost.localdomain.pid
datadir=/home/fuyouling/mutl_mysql/mysql_3307/mysql/
user=root
character_set_server=utf8
lower_case_table_names=1
max_connections=300
server_id=2
replicate-do-db=test
relay-log=slave-relay-bin
relay-log-index=slave-relay-bin.index
rpl_semi_sync_slave_enabled=1 #新添加
注意:配置完后记得重启主从mysql。
4.主从半同步配置完毕,以下测试:
在主服务器上执行:
mysql> insert into test.test_table select 4,‘test4‘;
Query OK, 1 row affected (0.02 sec)
Records: 1 Duplicates: 0 Warnings: 0
在从服务器上查询,新添加的记录进来了:
mysql> select * from test.test_table;
+------+----------------+
| id | str |
+------+----------------+
| 1 | this is a test |
| 2 | test2 |
| 3 | test3 |
| 4 | test4 |
+------+----------------+
4 rows in set (0.00 sec)
4.关闭从服务复制进程进行测试
(1)在从服务器上执行STOP SLAVE IO_THREAD;
(2)在主服务器上执行创建表会在超过了超时时间之后再创建表,
时间用了1.07秒:
mysql> create table new_table2(id int,str varchar(100));
Query OK, 0 rows affected (1.07 sec)
(3)此时从服务器上查询,表new_table2 并没有创建
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| hahahaha |
| test_table |
| wochenggongle |
+----------------+
4 rows in set (0.01 sec)
(4)此时在主服务器上再创建一个表,会发现创建时间只用了0.09秒,是因为
一旦超时,会自动降为异步复制,再次执行的时候就不会再等待超时时间
mysql> create table new_table5(id int,str varchar(100));
Query OK, 0 rows affected (0.09 sec)
(5)在从服务器上执行START SLAVE IO_THREAD,再次查询,表new_table已经创建,
一旦再次开启复制进程,就会自动向主服务器复制数据
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| hahahaha |
| new_table2 |
| test_table |
| wochenggongle |
+----------------+
4 rows in set (0.01 sec)
本文出自 “去观海” 博客,请务必保留此出处http://quguanhai.blog.51cto.com/1951497/1794474
以上是关于centos7下mysql5.6.30配置单机多实例主从半同步复制的主要内容,如果未能解决你的问题,请参考以下文章