Mysql-MMM配置安装:

1 环境
   本机IP                          虚拟IP                         角色
10.201.100.213                 10.201.100.250                   mysql-control
10.201.100.214                 10.201.100.251                   mysql-master
10.201.100.215                 10.201.100.252                   mysql-master
在每台机器的配置文件更改主机名 /etc/sysconfig/network
2 软件安装:在三台服务器上分别操作一下步骤
rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-5.noarch.rpm
yum install mysql-mmm              (默认路径/etc/mysql-mmm)
yum install mysql mysql-server 或者手动编译安装mysql
mysql-mmm软件如果是tar安装需要安装以下软件
yum  -y install libproc-daemon-perl libalgorithm-diff-perl libdbi-perl libdbd-mysql-perl iproute
3 把两台mysql-master互为主主
GRANT REPLICATION CLIENT ON *.* TO 'slave'@'10.201.100.%' IDENTIFIED BY 'slave';
Mysql主主配置操作略过.在完成数据同步之后继续下面操作。
4 创建监控代理权限 在三台机器上都操作一遍
GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'10.201.100.%'  IDENTIFIED BY 'mmm_agent';
flush privileges;
5 配置mmm监控代理服务器
1 在10.201.100.213上操作,操作完毕之后将mmm_common.conf分别拷贝到其他两台服务器.不用做任何操作
[root@master 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        slave                      ##mysql同步的账号
    replication_password    slave                      ###mysql同步的密码
    agent_user              mmm_agent                  ###监控代理的账号
    agent_password          mmm_agent                  ###监控代理的账号
</host>
 
<host slave1>                                          ###slave1为10.201.100.214主机名                 
    ip      10.201.100.214
    mode    master
    peer    slave2                                     ###slave2为10.201.100.215主机名 
</host>
<host slave2>                                          ###slave2为10.201.100.215主机名 
    ip      10.201.100.215
    mode    master        
    peer    slave1                                     ###slave1为10.201.100.214主机名 
</host>
#<host db3>
#    ip      192.168.100.51
#    mode    slave
#</host>
<role writer>
    hosts   slave1, slave2
    ips     10.201.100.250                             ###监控代理服务器的虚拟IP
    mode    exclusive
</role>
<role reader>
    hosts   slave1, slave2
    ips     10.201.100.251, 10.201.100.252            ###两台主主服务器的虚拟IP
    mode    balanced
</role>
2 修改mmm_mon.conf文件
[root@master mysql-mmm]#  cat  mmm_mon.conf
include mmm_common.conf
<monitor>
    ip                  127.0.0.1
    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            10.201.100.214,10.201.100.215  ###主主服务器IP
    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>
<host default>
    monitor_user        mmm_agent          ###监控代理的账号
    monitor_password    mmm_agent          ###监控代理的密码
</host>
debug 0
3 在三台服务器上分别修改mmm_agent.conf设置主机名
[root@master mysql-mmm]# cat mmm_agent.conf
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 slave1        ###主机名修改
6 启动MMM
1 启动两台主主服务器
/etc/init.d/mysql-mmm-agent start 
2 启动启动监控(在监控机上):
/etc/init.d/mysql-mmm-monitor start
3 开启完毕查看监控机状态
[root@master mysql-mmm]# mmm_control show
slave1(10.201.100.214) master/ONLINE. Roles: reader(10.201.100.251)
slave2(10.201.100.215) master/ONLINE. Roles: reader(10.201.100.252), writer(10.201.100.250)
7 说明
  1. 以上操作之后的效果是10.201.100.215为读写操作 10.201.100.214读不参与监控端发布的数据写入,
  2. 只同步10.201.100.215的数据库文件(数据库谁先启动先就数据读+写,后启动就为读)</pre>
  3. 当10.201.100.215宕机之后,监控端自动将读写的操作分给10.201.100.214
  4. (如果10.201.100.215后面有若干台从库也会转移给214)