172.168.10.11  master

172.168.10.12  master

172.168.10.24  slave

两台mysql 互为主,一台充当slave,做好同步功能,这里主要介绍一下mysql-mmm的用法


三台mysql 数据库服务器需要安装:mysql-mmm-agent*,perl-Time-HiRes*

在172.168.10.24  slave 机器上安装mysql-mmm-monitor服务需要安装:mysql-mmm-monitor,perl-Time-HiRes*

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm



mysql-mmm-monitor配置文件:

include mmm_common.conf

    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      172.168.10.11,172.168.10.12,172.168.10.24
    auto_set_online     30
    # 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        root   #监控帐号每台mysql都需要有这个帐号
    monitor_password    xxx

debug 0

mmm_common.conf配置文件,monitor添加好后同步到各mysql mmm-agent下

active_master_role      writer

    cluster_interface       eth0
    pid_path                /var/run/mysql-mmm/mmm_agentd.pid
    bin_path                /usr/libexec/mysql-mmm/
    replication_user        slave001
    replication_password    123456
    agent_user              root
    agent_password          xxx


    ip      172.168.10.11
    mode    master
    peer    db2


    ip      172.168.10.12
    mode    master
    peer    db1


    ip      172.168.10.24
    mode    slave


    hosts   db1, db2
    ips     172.168.10.200
    mode    exclusive
    prefer  db1   #添加此选项后每次DB1正常后都会成为writer


    hosts   db1, db2
    ips     172.168.10.201, 172.168.10.202,172.168.10.203
    mode    balanced

mysql-mmm-agent 配置文件:


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   #

启动mysql 服务,并启动/etc/init.d/mysql-mmm-agentstart

启动/etc/init.d/mysql-mmm-monitorstart 服务

slave db3的主如果出现故障 mon会切换到其它正常的master上


mmm_control 命令用法:

Valid commands are:
    help                              - show this message
   #查看帮助信息
ping                              - ping monitor
#ping监控
show                              - show status
#查看状态信息
checks [|all [|all]] - show checks status
#显示检查状态,包括(ping、mysql、rep_threads、rep_backlog)
set_online                  - set host  online
#设置某host为online状态
set_offline                 - set host  offline
#设置某host为offline状态
mode                              - print current mode.
#打印当前的模式,是ACTIVE、MANUAL、PASSIVE?
#默认ACTIVE模式
set_active                        - switch into active mode.
#更改为active模式
set_manual                        - switch into manual mode.
#更改为manual模式
set_passive                       - switch into passive mode.
#更改为passive模式
    move_role [--force]   - move exclusive role  to host 
       #更改host的模式,比如更改处于slave的mysql数据库角色为write
   (Only use --force if you know what you are doing!)
set_ip                  - set role with ip  to host 
#为host设置ip,只有passive模式的时候才允许更改!