mysql-mmm文档下载地址
http://down.51cto.com/data/339582
部署环境
操作系统:Red Hat Enterprise Linux Server release 6.1
Master1:192.168.5.73
Master2:192.168.5.76
Monitor:192.168.5.77
安装步骤
1、假设mysql Mater-Master模式已经配置成功,可以参考mysql master-slave配置文章
http://360537539.blog.51cto.com/3803422/781612
为了避免master-master AUTO_INCREMENT列值重复情况,需要在my.cnf配置中配置如下内容
master1:
- auto_increment_increment = 2
- auto_increment_offset = 1
master2:
- auto_increment_increment = 2
- auto_increment_offset = 2
有关auto_increment_increment和auto_increment_offset参考
http://blog.csdn.net/wh62592855/article/details/6726724
2、安装mysql-mmm-agent mysql-mmm-common mysql-mmm-mon,redhat和centos系统通过yum方式安装比较方便(省去了很多依赖包的安装),但是默认的centos软件仓库默认不包含这些rpm包,需要epel-release的支持。
1)安装epel-release包
#rpm -Uvh http://mirror.xfes.ru/fedora-epel/6/i386/epel-release-6-5.noarch.rpm,不同的系统版本注意选择对应的镜像位置
2)安装mysql-mmm系列包
yum install mysql-mmm* -y
3)创建mysql 用户并赋予权限
条件:
monitor user
A MySQL user with privileges REPLICATION CLIENT for MMM monitor.
agent user
A MySQL user with privileges SUPER, REPLICATION CLIENT, PROCESS for
MMM agent.
replication user
A MySQL user with privileges REPLICATION SLAVE used for replication.
运行命令
- mysql>GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.%' IDENTIFIED BY 'ictsoft';
- mysql> GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.%' IDENTIFIED BY 'ictsoft';
- mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.%' IDENTIFIED BY 'ictsoft';
4、配置mysql-mmm
vi /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 rep
- replication_password ictsoft
- agent_user mmm_agent
- agent_password ictsoft
- </host>
- <host db1>
- ip 192.168.5.73
- mode master
- peer db2
- </host>
- <host db2>
- ip 192.168.5.76
- mode master
- peer db1
- </host>
- <role writer>
- hosts db1, db2
- ips 192.168.5.80
- mode exclusive
- </role>
- <role reader>
- hosts db1, db2
- ips 192.168.5.84, 192.168.5.82
- mode balanced
- </role>
192.168.5.73 192.168.5.76为anget的ip地址
192.168.5.80 192.168.5.82 192.168.5.84是3个浮动ip,192.168.5.84, 192.168.5.82对应’读’角色,192.168.5.80对应’写’角色,浮动ip会根据mysql服务的情况进行漂移,后面会详细介绍。
将配置文件拷贝到monitor和agent的响应目录下(/etc/mysql-mmm/mysql-common.conf)
修改mysql-mmm-agent.conf
vi /etc/mysql-mmm/mmm_agent.conf
- include mmm_common.conf
- this db1
注意此处this的值要和common中的配置相对应
修改mysql-mmm-monitor.conf
- include mmm_common.conf
- <monitor>
- ip 127.0.0.1
- pid_path /var/run/mmm_mond.pid
- bin_path /usr/lib/mysql-mmm/
- status_path /var/lib/misc/mmm_mond.status
- ping_ips 192.168.5.73
- </monitor>
- <host default>
- monitor_user mmm_monitor
- monitor_password ictsoft
- </host>
- debug 1
5、启动mysql-mmm-agent和mysql-mmm-monitor服务
#/etc/init.d/mysql-mmm-agent start
#/etc/init.d/mysql-mmm-monitor start
6、检测状态
monitor端
- #mmm_control show
- b1(192.168.5.73) master/AWAITING_RECOVERY. Roles:
- db2(192.168.5.76) master/AWAITING_RECOVERY. Roles:
对两台db做set_online操作
- #mmm_control set_online db1
- #mmm_control set_online db2
查看状态
- #mmm_control show
- db1(192.168.5.73) master/ONLINE. Roles: reader(192.168.5.82), writer(192.168.5.80)
- db2(192.168.5.76) master/ONLINE. Roles: reader(192.168.5.84)
7、测试
停掉db1的mysql,在monitor端查看状态
- #mmm_control show
- db1(192.168.5.73) master/HARD_OFFLINE. Roles:
- db2(192.168.5.76) master/ONLINE. Roles: reader(192.168.5.82), reader(192.168.5.84), writer(192.168.5.80)
发现原来在db1上的读和写角色(ip)都漂移到了db2,启动db1的mysql后角色重新分配