CENTOS7 mysql5.6.30 Configuration Single-machine multi-instance master-slave semi-synchronous replication

Source: Internet
Author: User

1. Execute on the Master master server:

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. Execute from the server on 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. The above settings are temporary, restarting the server will fail, so you can add the configuration to the/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 #新添加, this unit is milliseconds


[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 #新添加


Note: Remember to restart master-slave mysql When you are finished configuring.


4. master-Slave semi-synchronous configuration is complete, the following tests:

Execute on the primary server:

mysql> INSERT INTO test.test_table Select 4, ' test4 ';

Query OK, 1 row affected (0.02 sec)

Records:1 duplicates:0 warnings:0


In the query from the server, the newly added records come in:

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. Close the test from the service replication process


(1) Execute the Stop SLAVE io_thread from the server;


(2) Executing the CREATE table on the primary server will create the table after the timeout period is exceeded.

Time took 1.07 seconds:

Mysql> CREATE TABLE New_table2 (ID int,str varchar (100));

Query OK, 0 rows affected (1.07 sec)


(3) Query from the server at this time, table New_table2 is not created

Mysql> Show tables;

+----------------+

| Tables_in_test |

+----------------+

| hahahaha |

| test_table |

| Wochenggongle |

+----------------+

4 rows in Set (0.01 sec)


(4) When you create a table on the primary server, you will find that the creation time is only 0.09 seconds, because

Once timed out, it automatically drops to asynchronous replication, and no longer waits for a timeout when executing again

Mysql> CREATE TABLE new_table5 (ID int,str varchar (100));

Query OK, 0 rows affected (0.09 sec)


(5) Execute start SLAVE io_thread from the server, query again, table new_table has been created,

Once the replication process is turned on again, the data is automatically replicated to the primary server


Mysql> Show tables;

+----------------+

| Tables_in_test |

+----------------+

| hahahaha |

| New_table2 |

| test_table |

| Wochenggongle |

+----------------+

4 rows in Set (0.01 sec)




This article is from the "Go to Sea" blog, please be sure to keep this source http://quguanhai.blog.51cto.com/1951497/1794474

CENTOS7 mysql5.6.30 Configuration Single-machine multi-instance master-slave semi-synchronous replication

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.