mysql-mmm文档下载地址

http://down.51cto.com/data/339582

部署环境

操作系统:Red Hat Enterprise Linux Server release 6.1

Master1192.168.5.73

Master2192.168.5.76

Monitor192.168.5.77

安装步骤

1、假设mysql Mater-Master模式已经配置成功,可以参考mysql master-slave配置文章

http://360537539.blog.51cto.com/3803422/781612

为了避免master-master AUTO_INCREMENT列值重复情况,需要在my.cnf配置中配置如下内容

 

master1:

 
  
  1. auto_increment_increment = 2 
  2. auto_increment_offset = 1 

 

master2:

 
  
  1. auto_increment_increment = 2  
  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-monredhatcentos系统通过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.

运行命令


 
  
  1. mysql>GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.%' IDENTIFIED BY 'ictsoft'
  2.  
  3. mysql> GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.%' IDENTIFIED BY 'ictsoft'
  4.  
  5. mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.%' IDENTIFIED BY 'ictsoft'

4、配置mysql-mmm

vi /etc/mysql-mmm/mmm_common.conf


 
  
  1. active_master_role      writer 
  2.  
  3.  <host default> 
  4.  
  5.   cluster_interface       eth0 
  6.  
  7.     pid_path                /var/run/mysql-mmm/mmm_agentd.pid 
  8.  
  9.     bin_path                /usr/libexec/mysql-mmm/ 
  10.  
  11.     replication_user        rep 
  12.  
  13.     replication_password    ictsoft 
  14.  
  15.     agent_user              mmm_agent 
  16.  
  17.     agent_password          ictsoft 
  18.  
  19. </host> 
  20.  
  21. <host db1> 
  22.  
  23.     ip      192.168.5.73 
  24.  
  25.     mode    master 
  26.  
  27.     peer    db2 
  28.  
  29. </host> 
  30. <host db2> 
  31.     ip      192.168.5.76 
  32.  
  33.     mode    master 
  34.  
  35.     peer    db1 
  36.  
  37. </host> 
  38. <role writer> 
  39.     hosts   db1, db2 
  40.  
  41.     ips     192.168.5.80 
  42.  
  43.     mode    exclusive 
  44.  
  45. </role> 
  46. <role reader> 
  47.     hosts   db1, db2 
  48.  
  49.     ips     192.168.5.84, 192.168.5.82 
  50.  
  51.     mode    balanced 
  52.  
  53. </role> 

192.168.5.73  192.168.5.76angetip地址

192.168.5.80  192.168.5.82  192.168.5.843个浮动ip192.168.5.84, 192.168.5.82对应角色,192.168.5.80对应角色,浮动ip会根据mysql服务的情况进行漂移,后面会详细介绍。

将配置文件拷贝到monitoragent的响应目录下(/etc/mysql-mmm/mysql-common.conf)

修改mysql-mmm-agent.conf

vi /etc/mysql-mmm/mmm_agent.conf

 
  
  1. include mmm_common.conf 
  2.  
  3. this db1 

注意此处this的值要和common中的配置相对应

修改mysql-mmm-monitor.conf


 
  
  1. include mmm_common.conf 
  2.  

  3. <monitor> 

  4.         ip                                      127.0.0.1 
  5.  
  6.         pid_path                                /var/run/mmm_mond.pid 
  7.  
  8.         bin_path                                /usr/lib/mysql-mmm/ 
  9.  
  10.         status_path                             /var/lib/misc/mmm_mond.status 
  11.  
  12.         ping_ips                                192.168.5.73 
  13.  
  14. </monitor> 
  15.  
  16.  
  17. <host default> 

  18.         monitor_user                    mmm_monitor 
  19.  
  20.         monitor_password                ictsoft 
  21.  
  22. </host> 
  23.  
  24. debug 1 

 

 

5、启动mysql-mmm-agentmysql-mmm-monitor服务

#/etc/init.d/mysql-mmm-agent start

#/etc/init.d/mysql-mmm-monitor start

6、检测状态

monitor 


 
  
  1. #mmm_control show 
  2.  
  3. b1(192.168.5.73) master/AWAITING_RECOVERY. Roles: 
  4.  
  5. db2(192.168.5.76) master/AWAITING_RECOVERY. Roles: 

对两台dbset_online操作


 
  
  1. #mmm_control set_online db1 
  2.  
  3. #mmm_control set_online db2 

查看状态


 
  
  1. #mmm_control show 
  2.  
  3. db1(192.168.5.73) master/ONLINE. Roles: reader(192.168.5.82), writer(192.168.5.80) 
  4.  
  5. db2(192.168.5.76) master/ONLINE. Roles: reader(192.168.5.84) 

7、测试

停掉db1mysql,在monitor端查看状态


 
  
  1. #mmm_control show 
  2.  
  3. db1(192.168.5.73) master/HARD_OFFLINE. Roles: 
  4.  
  5. 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,启动db1mysql后角色重新分配