8.12.3.2 mysql-mmm 架构图
Mysql mmm 特点
优点:高可用性,扩展性好,出现故障自动切换,对于主主同步,在同一时间只提供一台数据库写操作,保证的数据的一致性。
缺点:Monitor节点是单点,可以结合Keepalived实现高可用,对主机的数量有要求,需要实现读写分离,对程序来说是个挑战。
8.12.3.3 mysql-mmm 安装
需要在所有server上都安装mysql-mmm
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm
yum install -y mysql-mmm*
8.12.3.4 mysql-mmm 配置
现在环境已经配置好,我没有忽略 mysql 库和 user 表,所以只要在任意一台主库上执行下面的操作,其他库就都有这俩账号了。
这里我在master1上进行的操作
mysql> grant replication client on . to 'mmm_monitor'@'192.168.0.%'>
mysql> grant super, replication client, process on . to 'mmm_agent'@'192.168.0.%'>
所有服务器均需配置/etc/mysql-mmm/mmm_common.conf
active_master_role writer
cluster_interface eth0
pid_path /var/run/mysql-mmm/mmm_agentd.pid
bin_path /usr/libexec/mysql-mmm/
replication_user rep #同步用户
replication_password oldboy123 #同步密码
agent_user mmm_agent # mmm_agent用户
agent_password oldboy123 # mmm_agent用户的密码
ip 192.168.0.60 # db1 master-1的物理ip
mode master
peer db2
ip 192.168.0.61 # db2 master-2的物理ip
mode master
peer db1
ip 192.168.0.62 # db3 slave的物理ip
mode slave
hosts db1, db2
ips 192.168.0.20 #写入的虚拟IP地址 VIP
mode exclusive
hosts db1, db2, db3
ips 192.168.0.21, 192.168.0.22, 192.168.0.23 #虚拟读取IP地址
mode balanced
所有服务器均需配置/etc/mysql-mmm/mmm_agent.conf
vi /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 #分别修改为本机的主机名,即db1、db2、db3和db4
monitor主机配置/etc/mysql-mmm/mmm_mon.conf [root@mysql-mmm-monitor tools]# cat /etc/mysql-mmm/mmm_mon.conf
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 192.168.0.60,192.168.0.61,192.168.0.62 #监控的IP
auto_set_online 30 #切换浮动IP的时间(默认为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_user mmm_monitor #mmm_monitor 用户
monitor_password oldboy123 #mmm_monitor 密码
debug 0
8.12.3.5 mysql-mmm 启动
1) master-1,master-2,slave启动代理:
所有数据库主机启动mmm-agent:
/etc/init.d/mysql-mmm-agent start
10.204.3.4:9989 0.0.0.0:* LISTEN 2407/mmm_agentd
2) monitor主机启动mmm-monitor
/etc/init.d/mysql-mmm-monitor start
8.12.3.6 mysql-mmm 测试
mmm_control命令监控mysql服务器状态
[root@mysql-mmm-monitor ~]# mmm_control show
db1(192.168.0.60) master/ONLINE. Roles: reader(192.168.0.23), writer(192.168.0.20)
db2(192.168.0.61) master/ONLINE. Roles: reader(192.168.0.22)
db3(192.168.0.62) slave/ONLINE. Roles: reader(192.168.0.21)
测试两个mysql服务器能否实现故障自动切换
将db1的mysql服务停止
[root@mysql-mmm-master1 tools]# /etc/init.d/mysqld stop
Shutting down MySQL... SUCCESS!
等待30秒在mysql-mmm-monitor服务器上进行监控查看
[root@mysql-mmm-monitor ~]# mmm_control show
db1(192.168.0.60) master/HARD_OFFLINE. Roles:
db2(192.168.0.61) master/ONLINE. Roles: reader(192.168.0.22), writer(192.168.0.20)
db3(192.168.0.62) slave/ONLINE. Roles: reader(192.168.0.21), reader(192.168.0.23)
slave检查master_host是否切换到了另一个主库地址:
[root@mysql-mmm-slave ~]# mysql -e "show slave status\G"|egrep "Master_Host:"
Master_Host: 192.168.0.61
恢复master-1(db1)
[root@mysql-mmm-master1 tools]# /etc/init.d/mysqld start
Starting MySQL... SUCCESS!
monitor端检查恢复情况
[root@mysql-mmm-monitor ~]# mmm_control show
db1(192.168.0.60) master/ONLINE. Roles: reader(192.168.0.21)
db2(192.168.0.61) master/ONLINE. Roles: reader(192.168.0.22), writer(192.168.0.20)
db3(192.168.0.62) slave/ONLINE. Roles: reader(192.168.0.23)
我们可以看到当db1恢复后就充当slave的角色了!只有当db2挂了以后db1又会担当起主服务器的写入功能。
8.12.3.7 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模式的时候才允许更改!
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com