<host db1>
ip 192.168.19.66
mode master
peer db2 //需要监视的“同伴”
</host>
<host db2>
ip 192.168.19.74
mode master
peer db1
</host>
<host db3>
ip 192.168.19.76
mode slave
</host>
<host db4>
ip 192.168.19.79
mode slave
</host>
<role writer>
hosts db1, db2 //可写节点
ips 192.168.19.150 //写操作使用的VIP
mode exclusive //排他模式,此处资源同一时间只能分配给一个主机
</role>
<role reader>
hosts db1, db2, db3, db4 //可读节点
ips 192.168.19.151, 192.168.19.152, 192.168.19.153, 192.168.19.154 //读操作使用的VIP
mode balanced //平衡模式
</role>
5.在db1-4上修改mmm_agent.conf,只需要修改db1这里,是哪台就改成哪台,这里只给出db1的:
vim /etc/mysql-mmm/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 db1 //只改这里
6.配置mon上的mmm_mon.conf:
vim /etc/mysql-mmm/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 192.168.19.50, 192.168.19.66, 192.168.19.74, 192.168.19.76, 192.168.19.79
//用于测试网络可用性的IP地址,其中有一个地址能ping通,就代表网络正常,不要写入本机的ip地址
auto_set_online 60 //是否设置自动上线,如果该值大于0,抖动的主机在抖动的时间范围过后,则设置自动上线
# 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_monitor //用于监控的用户
monitor_password 123456 //监控用户的密码
</host>
debug 0
五、启动测试:
1.在db1-4上启动agents:
chkconfig mysql-mmm-agent on
service mysql-mmm-agent start
2.在mon上启动monitor:
vim /etc/default/mysql-mmm-monitor
--------------------------------------------------->
ENABLED=1
<---------------------------------------------------
service mysql-mmm-monitor start
3.检查集群状态:
mmm_control show
如果服务器状态不是ONLINE,可以用如下命令将服务器上线,例如:
mmm_control set_online db1
4.从刚才图片可以看到,写请求的VIP在db1上,所有从节点也都把db1当做主节点。下面将db1停掉:
service mysqld stop //停掉db1的mysql服务
可以看到写请求的VIP已经转移到db2上了,且从节点的主都指向了db2:
5.最后开启db3、db4的只读:
vim /etc/my.cnf
------------------------------->
[mysqld]
read_only = 1
<-------------------------------
service mysqld restart