1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| 1、搭建主从复制 master:主 [root@master ~] [root@master ~] [mysqld] server_id=6 binlog_format=row log_bin skip_name_resolve [root@master ~] MariaDB [(none)]> grant replication slave on *.* to repluser@'192.168.2.%' identified by '123456';
slave:从 [root@slave ~] [root@slave ~] [mysqld] read-only server_id=16 skip_name_resolve binlog_format=row [root@slave ~] MariaDB [(none)]> CHANGE MASTER TO -> MASTER_HOST='192.168.2.6', -> MASTER_USER='repluser', -> MASTER_PASSWORD='123456', -> MASTER_PORT=3306, -> MASTER_LOG_FILE='mariadb-bin.000001', -> MASTER_LOG_POS=245; Query OK, 0 rows affected (0.02 sec) MariaDB [(none)]> start slave; MariaDB [(none)]> show slave status\G
2、测试主从同步是否正常 master: MariaDB [(none)]> create database db1;
slave: MariaDB [(none)]> show databases;
3、安装插件 master:主 MariaDB [(none)]> INSTALL PLUGIN rpl_semi_sync_master SONAME -> 'semisync_master.so'; Query OK, 0 rows affected (0.01 sec)
slave:从 MariaDB [(none)]> INSTALL PLUGIN rpl_semi_sync_slave SONAME -> 'semisync_slave.so'; Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show plugins;
4、修改配置文件,启用插件 master: [root@master ~] [mysqld] rpl_semi_sync_master_enabled [root@master ~] systemctl restart mariadb
slave: [root@slave ~] [mysqld] rpl_semi_sync_slave_enabled [root@slave ~]
5、测试 slave: MariaDB [(none)]> stop slave;
master: MariaDB [(none)]> create database db12; Query OK, 1 row affected (6.00 sec)
slave: MariaDB [(none)]> start slave; Query OK, 0 rows affected (0.00 sec)
|