MMM实现MySQL高可用详解(2)

[mysqld] server-id = 2 datadir = /Data/apps/mysql-5.6.36/data log-bin = /Data/apps/mysql-5.6.36/data/mysql-bin binlog_format = ROW relay_log = /Data/apps/mysql-5.6.36/data/relay-log auto-increment-increment = 2 auto-increment-offset = 2 sync_binlog = 1 sync_master_info = 1 sync_relay_log = 1 sync_relay_log_info = 1 max_binlog_size = 100M log_slave_updates = 1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

slave-db1

[mysqld] server-id = 3 datadir = /Data/apps/mysql-5.6.36/data log-bin = /Data/apps/mysql-5.6.36/data/mysql-bin binlog_format = ROW relay_log = /Data/apps/mysql-5.6.36/data/relay-log sync_binlog = 1 sync_master_info = 1 sync_relay_log = 1 sync_relay_log_info = 1 max_binlog_size = 100M log_slave_updates = 1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

slave-db2

[mysqld] server-id = 4 datadir = /Data/apps/mysql-5.6.36/data log-bin = /Data/apps/mysql-5.6.36/data/mysql-bin binlog_format = ROW relay_log = /Data/apps/mysql-5.6.36/data/relay-log sync_binlog = 1 sync_master_info = 1 sync_relay_log = 1 sync_relay_log_info = 1 max_binlog_size = 100M log_slave_updates = 1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

3.重启以上四台mysql服务

service mysqld restart

4.在master-db1上创建mmm架构中需要的用户和权限

[root@master-db1 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.36-log MySQL Community Server (GPL) ....... Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.1.%' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.19 sec) mysql> GRANT SUPER,REPLICATION CLIENT,PROCESS ON *.* TO 'mmm_agent'@'192.168.1.%' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.1.%' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.01 sec)

5.查看二进制日志位置

mysql> FLUSH TABLES WITH READ LOCK; Query OK, 0 rows affected (0.07 sec) mysql> SHOW MASTER STATUS; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 796 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.05 sec)

6.不要关闭这个mysql进程连接,避免锁失效,我们另起一个ssh连接db1服务器,进行数据库备份:

[root@master-db1 ~]# mysqldump --all-databases > /tmp/database-backup.sql

7.回到刚才mysql进程,进行解锁:

mysql> UNLOCK TABLES; Query OK, 0 rows affected (0.05 sec)

8.将database-backup.sql文件复制到其他db节点:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/4a87fd5cd8eca6a3ea21da59ec7da274.html