/usr/local/mysql/bin/mysql
------------------------------------------------->
GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.19.%' IDENTIFIED BY '123456';
GRANT SUPER,REPLICATION CLIENT,PROCESS ON *.* TO 'mmm_agent'@'192.168.19.%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.19.%' IDENTIFIED BY '123456'
4.查看二进制日志位置:
FLUSH TABLES WITH READ LOCK; //施加锁
SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| mysql1-bin.000004 | 936 | | |
+-------------------+----------+--------------+------------------+
5.不要关闭这个mysql进程连接,避免锁失效,我们另起一个ssh连接db1服务器,进行数据库备份:
/usr/local/mysql/bin/mysqldump --all-databases > /tmp/database-backup.sql
6.回到刚才mysql进程,进行解锁:
UNLOCK TABLES;
7.将database-backup.sql文件复制到其他db节点:
scp /tmp/database-backup.sql db2:/tmp/
scp /tmp/database-backup.sql db3:/tmp/
scp /tmp/database-backup.sql db4:/tmp/
8.db2-4主机导入sql文件,并刷新权限:
/usr/local/mysql/bin/mysql < /tmp/database-backup.sql
/usr/local/mysql/bin/mysql
------------------------------------------------->
FLUSH PRIVILEGES;
三、设置复制
1.在db2-4上操作,将db1设置为db2-4的主:
CHANGE MASTER TO MASTER_HOST='192.168.19.66',MASTER_USER='replication',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql1-bin.000004',MASTER_LOG_POS=936;
START SLAVE;
2.查看状态:
SHOW SLAVE STATUS\G
3.查看db2的master日志位置:
SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| mysql2-bin.000001 | 313 | | |
+-------------------+----------+--------------+------------------+
4.在db1上操作,将db2设置为db1的主:
CHANGE MASTER TO MASTER_HOST='192.168.19.74',MASTER_USER='replication',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql2-bin.000001',MASTER_LOG_POS=313;
START SLAVE;
SHOW SLAVE STATUS\G
四、安装MMM
1.创建用户:
useradd -s /sbin/nologin mmmd
2.在mon上安装:
yum -y install mysql-mmm-monitor
3.在db1-4上安装:
yum -y install mysql-mmm-agent
4.编写配置文件,五台主机必须一致:
vim /etc/mysql-mmm/mmm_common.conf
-------------------------------------------------------->
active_master_role writer
<host default>
cluster_interface eth0
pid_path /var/run/mysql-mmm/mmm_agentd.pid
bin_path /usr/libexec/mysql-mmm/
replication_user replication //用于复制的用户
replication_password 123456 //复制用户的密码
agent_user mmm_agent //用于改变模式的用户
agent_password 123456 //改变模式用户的密码
</host>