Top

NSD RDBMS2 DAY01

  1. 案例1:MySQL一主一从
  2. 案例2:配置一主多从结构
  3. 案例3:配置主从从结构
  4. 案例4:配置半同步复制模式

1 案例1:MySQL一主一从

1.1 问题

1.2 方案

使用2台虚拟机,如图-1所示。其中192.168.4.51是主服务器,另一台192.168.4.52作为从服务器,通过调取主服务器上的binlog日志,在本地重做对应的库、表,实现与主服务器的数据同步。

图-1

主机51和主机52分别运行MySQL数据库服务,且管理员root用户可以本机登录;主机50作为客户机 只需有命令行连接命令mysql即可。

1.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:配置主服务器192.168.4.51

1)启用binlog日志

  1. ]# vim /etc/my.cnf
  2. [mysqld]
  3. server_id=51            //server_id
  4. log-bin=master51        //日志名
  5. :wq
  6. ]# systemctl restart mysqld

2)用户授权

用户名自定义、客户端地址使用% 或 只指定 从服务器的地址 都可以、只给复制数据的权限即可。

  1. ]# mysql -uroot -p密碼
  2. mysql> grant replication slave on *.* to repluser@"%" identified by "123qqq...A";
  3.  
  4. mysql>quit;

3)查看binlog日志信息

查看日志文件名 和 偏移量位置。

mysql> show master status\G;

*************************** 1. row ***************************

File: master51.000001 //日志名

Position: 441 //偏移量

Binlog_Do_DB:

Binlog_Ignore_DB:

Executed_Gtid_Set:

1 row in set (0.00 sec)

步骤二:配置从服务器192.168.4.52

1)指定server_id

Server_id值可以自定义,但不可以与主服务器相同。

  1. ]# vim /etc/my.cnf
  2. [mysqld]
  3. server_id=52 //server_id值
  4. :wq
  5. ]# systemctl restart mysqld //重启服务

2)确保与主服务器数据一致(如果是使用2台新部署的数据库服务器配置主从同步,此操作可以忽略)

  1. ]# mysqldump -uroot –p密码 --master-data 数据库名 > /allbak.sql //在主服务器上备份数据
  2. ]# scp /allbak.sql root@192.168.4.52:/root/ //将备份文件拷贝给从服务器
  3.  
  4. mysql> create database 数据库名 ; //在从服务器上创建与主服务器同名的数据库
  5.  
  6. ]# mysql -uroot –p密码 数据库名 < /root/allbak.sql //从服务器使用备份文件恢复数据
  7.  
  8. ]# vim /root/allbak.sql //在从服务器查看备份文件中的binlog日志信息
  9. ......
  10. ......
  11. CHANGE MASTER TO MASTER_LOG_FILE='master51.000001', MASTER_LOG_POS=441; //日志名与偏移量

3)指定主服务器信息

数据库管理员root本机登录,指定主服务器信息,其中日志文件名和偏移量 写allbak.sql文件记录的。

  1. ]# mysql -uroot –p密码 //管理员root 本机登录
  2. mysql> show slave status; //查看状态信息,还不是从服务器
  3. Empty set (0.00 sec)
  4.  
  5.  
  6. mysql> change master to //指定主服务器
  7. -> master_host=192.168.4.51, //主服务器ip地址
  8. -> master_user=“repluser”, //主服务器授权用户
  9. -> master_password=“123qqq…A”, //主服务器授权用户密码
  10. -> master_log_file=“master51-bin.000001,//主服务器日志文件
  11. -> master_log_pos=441;          //主服务器日志偏移量
  12.  
  13.  
  14.  
  15. mysql> start slave;
  16. mysql> show slave status\G; //查看状态信息
  17. *************************** 1. row ***************************
  18. Slave_IO_State: Waiting for master to send event
  19. Master_Host: 192.168.4.51 //主服务器ip地址
  20. Master_User: repluser
  21. Master_Port: 3306
  22. Connect_Retry: 60
  23. Master_Log_File: master51.000001
  24. Read_Master_Log_Pos: 437
  25. Relay_Log_File: host52relay-bin.000002
  26. Relay_Log_Pos: 604
  27. Relay_Master_Log_File: master51.000001
  28. Slave_IO_Running: Yes        //IO线程yes状态
  29. Slave_SQL_Running: Yes        //SQL线程yes状态
  30. Replicate_Do_DB:
  31. Replicate_Ignore_DB:
  32. Replicate_Do_Table:
  33. Replicate_Ignore_Table:
  34. Replicate_Wild_Do_Table:
  35. Replicate_Wild_Ignore_Table:
  36. Last_Errno: 0
  37. Last_Error:
  38. Skip_Counter: 0
  39. Exec_Master_Log_Pos: 437
  40. Relay_Log_Space: 812
  41. Until_Condition: None
  42. Until_Log_File:
  43. Until_Log_Pos: 0
  44. Master_SSL_Allowed: No
  45. Master_SSL_CA_File:
  46. Master_SSL_CA_Path:
  47. Master_SSL_Cert:
  48. Master_SSL_Cipher:
  49. Master_SSL_Key:
  50. Seconds_Behind_Master: 0
  51. Master_SSL_Verify_Server_Cert: No
  52. Last_IO_Errno: 0
  53. Last_IO_Error:
  54. Last_SQL_Errno: 0
  55. Last_SQL_Error:
  56. Replicate_Ignore_Server_Ids:
  57. Master_Server_Id: 50
  58. Master_UUID: 4881ee4b-8800-11e9-830a-525400001e32
  59. Master_Info_File: /var/lib/mysql/master.info
  60. SQL_Delay: 0
  61. SQL_Remaining_Delay: NULL
  62. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  63. Master_Retry_Count: 86400
  64. Master_Bind:
  65. Last_IO_Error_Timestamp:
  66. Last_SQL_Error_Timestamp:
  67. Master_SSL_Crl:
  68. Master_SSL_Crlpath:
  69. Retrieved_Gtid_Set:
  70. Executed_Gtid_Set:
  71. Auto_Position: 0
  72. Replicate_Rewrite_DB:
  73. Channel_Name:
  74. Master_TLS_Version:
  75. 1 row in set (0.00 sec)

步骤三:客户端测试配置

1)在主服务器添加访问数据的连接用户

授权用户对所有数据有增删改查的权限即可

  1. ]# mysql –uroot –p密码
  2. mysql> grant select,insert,update,delete on *.* to admin@"%" identified by "123qqq...A";
  3. Query OK, 0 rows affected, 1 warning (0.03 sec)
  4.  
  5. mysql> quit

2)客户端连接主服务器访问数据

在50主机 使用主服务器51的授权用户连接

  1. ]# mysql -h192.168.4.51-uadmin -p123qqq...A
  2. mysql> show grants;
  3. +------------------------------------------------------------+
  4. | Grants for admin@% |
  5. +------------------------------------------------------------+
  6. | GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'admin'@'%' |
  7. +------------------------------------------------------------+
  8. 1 row in set (0.00 sec)
  9.  
  10. mysql> insert into db3.user(name,uid) values("lili",288); //db3库和user表是主从同步之前主服务器已有的。
  11. Query OK, 1 row affected (0.05 sec)
  12.  
  13. mysql> insert into db3.user(name,uid) values("lili",288);
  14. Query OK, 1 row affected (0.28 sec)
  15.  
  16. mysql> insert into db3.user(name,uid) values("lili",288);
  17. Query OK, 1 row affected (0.05 sec)
  18.  
  19. mysql> select name,uid from db3.user where name="lili";
  20. +------+------+
  21. | name | uid |
  22. +------+------+
  23. | lili | 288 |
  24. | lili | 288 |
  25. | lili | 288 |
  26. +------+------+
  27. 3 rows in set (0.00 sec)

3) 客户端连接从服务器访问数据

客户端50主机使用授权用户连接从服务器可以看到和主服务器同样的数据

  1. ]# mysql -h192.168.4.52 –uadmin -p123qqq…A
  2. mysql> select name,uid from db3.user where name="lili";
  3. +------+------+
  4. | name | uid |
  5. +------+------+
  6. | lili | 288 |
  7. | lili | 288 |
  8. | lili | 288 |
  9. +------+------+
  10. 3 rows in set (0.00 sec)

2 案例2:配置一主多从结构

2.1 问题

2.2 方案

创建1台新虚拟机,配置ip地址为192.168.4.53、运行数据库服务,且数据库管理员root用户可以本机登录。具体结构,如图-2所示。

图-2

2.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:配置从服务器192.168.4.53

1)启用binlog日志

  1. ]# vim /etc/my.cnf
  2. [mysqld]
  3. server_id=53        //server_id
  4. :wq
  5. ]# systemctl restart mysqld

2)确保与主服务器数据一致

在主服务器51 备份所有数据 并把备份文件拷贝给53服务器。

  1. ]# mysqldump -uroot –p123qqq…A –-master-data –B db4 db3 > /root/twodb.sql
  2. ]# scp /root/twodb.sql root@192.168.4.53:/root/

在53主机使用备份文件恢复数据,并查看备份文件记录的日志名和偏移量

  1. ]# mysql -uroot –p123qqq…A < /root/twodb.sql
  2. ]# grep mater51 /root/twodb.sql
  3. CHANGE MASTER TO MASTER_LOG_FILE='master51.000001', MASTER_LOG_POS=1098; //日志名与偏移量

3)指定主服务器信息

填写备份文件里显示的日志文件名 和 偏移量位置。

  1. mysql> change master to //指定主服务器
  2. -> master_host=192.168.4.51, //主服务器ip地址
  3. -> master_user=“repluser”, //主服务器授权用户
  4. -> master_password=“123qqq…A”, //主服务器授权用户密码
  5. -> master_log_file=“master51.000001,//主服务器日志文件
  6. -> master_log_pos=1098;          //主服务器日志偏移量
  7. mysql> start slave;

查看状态信息

  1. ]# mysql –uroot –p123qqq…A –e “show slave status\G” | grep –i yes
  2. Slave_IO_Running: Yes        //IO线程yes状态
  3. Slave_SQL_Running: Yes        //SQL线程yes状态
  4. ]# mysql –uroot –p123qqq…A –e “show slave status\G” | grep –i “master_host”
  5. Master_Host: 192.168.4.51 //主服务器ip地址

步骤二:客户端测试(192.168.4.50)

1)连接主服务器插入新记录

  1. ]# mysql -h192.168.4.51-uadmin -p123qqq...A
  2. mysql> insert into db3.user(name,uid) values("lucy",888); //db3库和user表是主从同步之前主服务器已有的。
  3. Query OK, 1 row affected (0.05 sec)

2)在从服务器本机53 可以查询到新插入的数据

  1. ]# mysql -uroot –p123qqq…A
  2. mysql> select name,uid from db3.user;
  3. +------+------+
  4. | name | uid |
  5. +------+------+
  6. | lili | 288 |
  7. | lucy | 888 |
  8. +------+------+
  9. 2 rows in set (0.00 sec)

3 案例3:配置主从从结构

3.1 问题

3.2 方案

使用3台虚拟机,分别运行mysql数据库服务,且管理员root可以本机登录;主机192.168.4.53为主服务器;主机192.168.4.54为从服务器;主机192.168.4.55为从服务器。如图-3所示。

图-3

3.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:环境准备

为了在启用binlog日志及同步之前保持主、从库的一致性,主从同步未配置之前,要保证从库上要有主库上的数据,禁用selinux,关闭防火墙服务,保证物理连接正常

1)关闭防火墙,禁用selinux,已关可忽略:

  1. ]# systemctl stop firewalld
  2. ]# setenforce 0

步骤二:配置主服务器192.168.4.53

2)用户授权

  1. ]# mysql -uroot -p123456
  2. mysql> grant replication slave on *.* to yaya@"%" identified by "123qqq…A“;
  3. Query OK, 0 rows affected, 1 warning (0.03 sec)

3)启用binlog日志,修改/etc/my.cnf配置,重新启动MySQL服务程序

指定服务器ID号、允许日志同步:

  1. ]# vim /etc/my.cnf
  2. [mysqld]
  3. log_bin=db53                     //启用binlog日志,并指定文件名前缀
  4. server_id=53                 //指定服务器ID号

4)重启mysql服务:

  1. ]# systemctl restart mysqld

5)确保/var/lib/mysql下面有两个文件:

  1. ]# ls /var/lib/mysql/db51.*
  2. /var/lib/mysql/db53.000001 /var/lib/mysql/db53.index

6)查看主服务正在使用的日志信息

查看主服务器状态,记录下当前的日志文件名、偏移的位置(下面SLAVE发起复制时需要用到):

  1. mysql> show master status;
  2. +-------------+----------+--------------+------------------+-------------------+
  3. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
  4. +-------------+----------+--------------+------------------+-------------------+
  5. | db53.000001 |437 | | | |
  6. +-------------+----------+--------------+------------------+-------------------+
  7. 1 row in set (0.00 sec)

步骤三:配置从服务器192.168.4.54

1)在服务器192.168.4.53上做用户授权(数据同步使用的连接用户)

  1. ]# mysql -uroot -p123456
  2. mysql> grant replication slave on *.* to user55@”%” identified by “654321;

2)修改/etc/my.cnf配置,启用binlog日志,指定server_id 和 允许级联复制

  1. ]# vim /etc/my.cnf
  2. [mysqld]
  3. server_id=54
  4. log-bin=db54
  5. log_slave_updates //允许级联复制

3)配置完成后,重启mysql服务:

  1. ]# systemctl restart mysqld

4)确保/var/lib/mysql下面有两个文件:

  1. ]# ls /var/lib/mysql/db52.*
  2. /var/lib/mysql/db54.000001 /var/lib/mysql/db54.index

5)查看正在使用的日志信息

  1. ]# mysql -uroot -p123456
  2. mysql> show master status;
  3. +-------------+----------+--------------+------------------+-------------------+
  4. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
  5. +-------------+----------+--------------+------------------+-------------------+
  6. |db54.000001 | 154 |
  7. +-------------+----------+--------------+------------------+-------------------+
  8. 1 row in set (0.00 sec) //查看日志文件名、偏移的位置

6)验证主服务器的的授权用户

]# mysql -h192.168.4.53 -uyaya -p123456

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.17-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  1. mysql> //验证成功

7)通过change master语句指定master服务器的IP地址、同步用户名/密码、起始日志文件、偏移位置(参考master上的状态输出):

]# mysql -uroot -p123456

mysql> change master to

-> master_host="192.168.4.53”;

-> master_user="yaya",

-> master_password="123456",

-> master_log_file="db53.000001”;

-> master_log_pos=437;

Query OK, 0 rows affected, 2 warnings (0.43 sec)

8)启动slave进程

mysql> start slave;

Query OK, 0 rows affected (0.03 sec)

9)查看进程状态信息,通过show slave status语句可查看从服务器状态,确认其中的IO线程、SQL线程正常运行,才能成功同步,IO线程和SQL线程必须是Yes

mysql> show slave status \G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

  1. Master_Host: 192.168.4.53 //主服务器IP地址

Master_User: yaya

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: db53.000001

Read_Master_Log_Pos: 437

Relay_Log_File: db54-relay-bin.000001

Relay_Log_Pos: 315

Relay_Master_Log_File: db54.000001

  1. Slave_IO_Running: Yes    //IO线程状态YES
  2. Slave_SQL_Running: Yes //SQL线程状态YES

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 437

Relay_Log_Space: 521

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: 51

Master_UUID: 81a13101-aa66-11e8-ad11-525400019e62

Master_Info_File: /var/lib/mysql/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates

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

Replicate_Rewrite_DB:

Channel_Name:

Master_TLS_Version:

1 row in set (0.00 sec)

步骤四:配置从服务器192.168.4.55

1)验证主库的授权用户

  1. ]# mysql -h192.168.4.54 -uuser54 -p654321
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 7
  5. Server version: 5.7.17-log MySQL Community Server (GPL)
  6.  
  7. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  8.  
  9. Oracle is a registered trademark of Oracle Corporation and/or its
  10. affiliates. Other names may be trademarks of their respective
  11. owners.
  12.  
  13. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  14.  
  15. mysql> //验证成功

2)指定server_id

  1. ]# vim /etc/my.cnf
  2. [mysqld]
  3. server_id=55
  4. :wq

3)重新启动服务

  1. ]# systemctl restart mysqld

4)管理员登录指定主库信息

  1. ]# mysql -uroot -p123456
  2. mysql> change master to
  3. -> master_host="192.168.4.54”;
  4. -> master_user="user55”;
  5. -> master_password="654321",
  6. -> master_log_file=" db54.000001”;
  7. -> master_log_pos=154;
  8. Query OK, 0 rows affected, 2 warnings (0.37 sec)

5)启动slave进程

  1. mysql> start slave;
  2. Query OK, 0 rows affected (0.04 sec)

6)查看进程状态信息

  1. mysql> show slave status\G
  2. *************************** 1. row ***************************
  3. Slave_IO_State: Waiting for master to send event
  4. Master_Host: 192.168.4.54
  5. Master_User: user55
  6. Master_Port: 3306
  7. Connect_Retry: 60
  8. Master_Log_File: db54.000001
  9. Read_Master_Log_Pos: 154
  10. Relay_Log_File: db55-relay-bin.000001
  11. Relay_Log_Pos: 315
  12. Relay_Master_Log_File: db54.000001
  13. Slave_IO_Running: Yes
  14. Slave_SQL_Running: Yes

步骤五:客户端验证配置

在主库授权访问数据的连接用户;户端连接主库执行与权限匹配的sql操作;

授权用户连接第1台从库,可以看到主库的数据;权用户连接第2台从库,可以看到主库的数据

1)在主服务器上在主库上授权访问gamedb库的用户

  1. ]# mysql -uroot -p123456
  2. mysql> grant all on gamedb.* to dada@"%" identified by "123456";
  3. Query OK, 0 rows affected, 1 warning (0.03 sec)

2)客户端使用授权用户连接主库,建库、表、插入记录

  1. ]# mysql -h192.168.4.53 -udada -p123456
  2. Welcome to the MariaDB monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 7
  4. Server version: 5.7.17-log MySQL Community Server (GPL)
  5.  
  6. Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
  7.  
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  9.  
  10. MySQL [(none)]> //验证成功
  11. MySQL [(none)]> create database gamedb; //创建测试库
  12. Query OK, 1 row affected (0.04 sec)
  13. MySQL [(none)]> create table gamedb.t1(id int); //在gamedb下创建t1表
  14. Query OK, 0 rows affected (0.17 sec)
  15. MySQL [(none)]> insert into gamedb.t1 values(8888); //在t1表中插入数值
  16. Query OK, 1 row affected (0.22 sec)

3)客户端使用授权用户连接2台从库时,也可以看到主库上新的库表记录

  1. ]# mysql -h192.168.4.54 -udada -p123456 //验证54主机的状态
  2. Welcome to the MariaDB monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 10
  4. Server version: 5.7.17-log MySQL Community Server (GPL)
  5.  
  6. Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
  7.  
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  9. MySQL [(none)]> select * from gamedb.t1; //查询插入的表格
  10. +------+
  11. | id |
  12. +------+
  13. | 8888 |
  14. +------+
  15. 1 row in set (0.00 sec)
  16. MySQL [(none)]> exit
  17. [root@room9pc01 ~]# mysql -h192.168.4.55 -udada -p123456 //验证55主机的状态
  18. Welcome to the MariaDB monitor. Commands end with ; or \g.
  19. Your MySQL connection id is 6
  20. Server version: 5.7.17 MySQL Community Server (GPL)
  21.  
  22. Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
  23.  
  24. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  25.  
  26. MySQL [(none)]> select * from gamedb.t1;
  27. +------+
  28. | id |
  29. +------+
  30. | 8888 |
  31. +------+
  32. 1 row in set (0.00 sec)

4 案例4:配置半同步复制模式

4.1 问题

4.2 方案

以案例2从服务器192.168.4.54 为例演示配置,54主机既做主服务器又做从服务器,所以两种角色的半同步复制模块和功能都要启用。

4.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:查看是否允许动态加载模块。

1)查看是否允许动态加载模块(默认允许)

  1. mysql> show variables like 'have_dynamic_loading';
  2. +----------------------+-------+
  3. | Variable_name | Value |
  4. +----------------------+-------+
  5. | have_dynamic_loading | YES |
  6. +----------------------+-------+
  7. 1 row in set (0.01 sec)

2)命令行加载插件

  1. mysql> install plugin rpl_semi_sync_master SONAME ”semisync_master.so”; //加载master模块
  2. mysql> install plugin rpl_semi_sync_slave SONAME 'semisync_slave.so'; //加载slave模块

查看模块是否安装成功:

  1. mysql> select plugin_name, plugin_status from information_schema.plugins where plugin_name like '%semi%';
  2. +----------------------+---------------+
  3. | PLUGIN_NAME | PLUGIN_STATUS |
  4. +----------------------+---------------+
  5. | rpl_semi_sync_master | ACTIVE |        //模块安装成功
  6. | rpl_semi_sync_slave | ACTIVE |        
  7. +----------------------+---------------+
  8. 2 rows in set (0.00 sec)

3)启用半同步复制 (在安装完插件后,半同步复制默认是关闭的)

  1. mysql> set global rpl_semi_sync_master_enabled = 1; //启用master半同步复制
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> set global rpl_semi_sync_slave_enabled = 1; //启用slave半同步复制
  4. Query OK, 0 rows affected (0.00 sec)

查看半同步复制模式是否启用:

  1. mysql> show variables like "rpl_semi_sync_%_enabled";
  2. +------------------------------+-------+
  3. | Variable_name | Value |
  4. +------------------------------+-------+
  5. | rpl_semi_sync_master_enabled | ON |    //模块已启用
  6. | rpl_semi_sync_slave_enabled | ON |
  7. +------------------------------+-------+
  8. 2 rows in set (0.00 sec)

4)修改配置文件,永久启用半同步复制

  1. [root@master51 ~]# vim /etc/my.cnf
  2. [mysqld]
  3. plugin-load="rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
  4. rpl-semi-sync-master-enabled = 1
  5. rpl-semi-sync-slave-enabled = 1
  6. :wq

5)重启数据库服务,并查看状态信息

  1. ]# mystemctl restart mysqld
  2. ]# mysql -uroot -p123qqq...A
  3. mysql> select plugin_name, plugin_status from information_schema.plugins where plugin_name like '%semi%';
  4. +----------------------+---------------+
  5. | plugin_name | plugin_status |
  6. +----------------------+---------------+
  7. | rpl_semi_sync_master | ACTIVE | //模块已加载
  8. | rpl_semi_sync_slave | ACTIVE |
  9. +----------------------+---------------+
  10. 2 rows in set (0.00 sec)
  11.  
  12. mysql> show variables like "rpl_semi_sync_%_enabled";
  13. +------------------------------+-------+
  14. | Variable_name | Value |
  15. +------------------------------+-------+
  16. | rpl_semi_sync_master_enabled | ON | //模式已启用
  17. | rpl_semi_sync_slave_enabled | ON |
  18. +------------------------------+-------+
  19. 2 rows in set (0.00 sec)