3. 在db1和db2 上分别建立复制,监控用户
GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.0.136' IDENTIFIED BY 'monitor';
GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.0.%' IDENTIFIED BY 'agent';
GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.%' IDENTIFIED BY 'replication';
4. 把db1和db2互相设置成master和slave
4.1 在db1上执行,mysql命令
CHANGE MASTER TO master_host='192.168.0.137', master_port=3306, master_user='replication',master_password='replication', master_log_file='mysql-bin.000006', master_log_pos=106; 注意:html">master_log_file和master_log_pos的值通过如下命令察看 在db2上执行如下mysql命令 show master status4.2 在db2上执行,mysql命令CHANGE MASTER TO master_host='192.168.0.135', master_port=3306, master_user='replication',master_password='replication', master_log_file='mysql-bin.000006', master_log_pos=106; 注意:master_log_file和master_log_pos的值通过如下命令察看 在db1上执行如下mysql命令 show master status5. 在db1和db2上安装mysql-mmm-agent
yum install mysql-mmm-agent*
6. 在monitor上安装mysql-mmm-monitor
yum install mysql-mmm-monitor*
7. 修改配置文件
在db1,db2和monitor上修改
/etc/mysql-mmm/mmm_common.conf,修改内容如下
active_master_role writer修改配置文件cluster_interface eth0 pid_path /var/run/mysql-mmm/mmm_agentd.pid bin_path /usr/libexec/mysql-mmm/ replication_user replication replication_password replication agent_user mmm_agent agent_password agent ip 192.168.0.135 mode master peer db2 ip 192.168.0.137 mode master peer db1 hosts db1,db2 ips 192.168.0.138 mode exclusive hosts db1,db2 ips 192.168.0.139,192.168.0.140 mode balanced /etc/mysql-mmm/mmm_agent.conf
db1上的内容如下
include mmm_common.conf # The 'this' variable refers to this server. Proper operation requires # that 'this' server (db1 by default), as well as all other servers, have the # proper IP addresses set in mmm_common.conf. this db1db2上的内容如下include mmm_common.conf # The 'this' variable refers to this server. Proper operation requires # that 'this' server (db1 by default), as well as all other servers, have the # proper IP addresses set in mmm_common.conf. this db2修改配置monitor文件
/etc/mysql-mmm/mmm_mon.conf,内容如下
include mmm_common.confip 192.168.0.136 pid_path /var/run/mysql-mmm/mmm_mond.pid bin_path /usr/libexec/mysql-mmm status_path /var/lib/mysql-mmm/mmm_mond.status ping_ips 192.168.0.135,192.168.0.137 auto_set_online 60 # The kill_host_bin does not exist by default, though the monitor will # throw a warning about it missing. See the section 5.10 "Kill Host # Functionality" in the PDF documentation. # # kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host # monitor_user mmm_monitor monitor_password monitor debug 08.在db1,db2上启动agent
# cd /etc/init.d/ # chkconfig mysql-mmm-agent on # service mysql-mmm-agent start9. 在monitor上启动monitor# cd /etc/init.d/ # chkconfig mysql-mmm-monitor on # service mysql-mmm-monitor start10. 在monitor上察看
mmm_control -show status
10.2 把一台机器上线
mmm_control set_online db1
10.3 试验
把db1上的mysql停掉 service mysqld stop
察看状态mmm_control -show status,db1上的写ip应该飘到db2上
参考
http://blog.csdn.net/