一、MMM简介:MMM即Master-Master Replication Manager for MySQL(mysql主主复制管理器)关于mysql主主复制配置的监控、故障转移和管理的一套可伸缩的脚本套件(在任何时候只有一个节点可以被写入),这个套件也能对居于标准的主从配置的任意数量的从服务器进行读负载均衡,所以你可以用它来在一组居于复制的服务器启动虚拟ip,除此之外,它还有实现数据备份、节点之间重新同步功能的脚本。MySQL本身没有提供replication failover的解决方案,通过MMM方案能实现服务器的故障转移,从而实现mysql的高可用。MMM项目来自 Google:http://code.google.com/p/mysql-master-master官方网站为:http://mysql-mmm.orgMmm主要功能由下面三个脚本提供l mmm_mond 负责所有的监控工作的监控守护进程,决定节点的移除等等l mmm_agentd 运行在mysql服务器上的代理守护进程,通过简单远程服务集提供给监控节点l mmm_control 通过命令行管理mmm_mond进程 二、mysql-mmm架构的搭建1、 先介绍下本文的环境:系统环境:CentOS release 5.4(32bit)server1 ip: 192.168.1.161 virtual read ip:192.168.1.111
server2 ip: 192.168.1.162 virtual read ip:192.168.1.112
server3 ip: 192.168.1.163 virtual write ip: 192.168.1.1132、 mysql-mmm架构配置简介:u 在server1、server2上安装mysql,并配置为master-master架构(就是互为主从)----------配置很简单,就不对着部分进行详细解释。u 在server1、server2,server3上安装mmm,并配置:mmm_common.conf、mmm_agent.conf以及mmm_mon.conf文件3、 Mysql-mmm实战前提:server1和server2上已经配置好mysql主主同步u 安装mysql-mmmCentOS软件仓库默认是不含这些软件的,必须要有epel这个包的支持。故我们必须先安装epel:wget http://download.Fedora.RedHat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpmrpm -Uvh epel-release-5-4.noarch.rpmyum -y install mysql-mmm*u 配置mmm代理和监控账号的权限在server1和server2上分别执行:GRANT REPLICATION CLIENT ON *.* TO "mmm_monitor"@"192.168.1.%" IDENTIFIED BY "monitor_password";GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO "mmm_agent"@"192.168.1.%" IDENTIFIED BY "agent_password";flush privileges;u 配置mysql-mmm所有的配置选项都集合在了一个叫/etc/mysql-mmm/mmm_common.conf的单独文件中,系统中所有主机的该文件内容都是一样的, 配置完后不要忘记了拷贝这个文件到所有的主机(包括监控主机)!,内容如下:active_master_role writer <host default> cluster_interface eth0 pid_path /var/run/mysql-mmm/mmm_agentd.pidbin_path /usr/libexec/mysql-mmm/#同步的帐号(这些要和前面设置的保持一致!) replication_user replication replication_password 123456 #同步的密码 agent_user mmm_agent #mmm-agent用户名 agent_password agent_password #mmm-agent用户密码</host> <host db1> ip 192.168.1.161 #db1的ip mode master peer db2</host> <host db2> ip 192.168.1.162 #db2的ip mode master peer db1</host> <role writer> hosts db1, db2 ips 192.168.1.113 #设置写如的虚拟IP mode exclusive</role> <role reader> hosts db1, db2 ips 192.168.1.111, 192.168.1.112 #设置读取的虚拟IP mode balanced</role> 在数据库主机上我们需要编辑/etc/mysql-mmm/mmm_agent.conf文件,根据其他主机的不同更改db1的值(db2就将db1更改成db2):include mmm_common.conf
this db1 在监控主机上我们需要编辑/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.1.161,192.168.1.162 #监控服务器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_monitor #mmm_monitor用户名 monitor_password monitor_password #mmm_monitor密码</host> debug 0 u 启动MMM启动代理:(在数据库服务器上server1、2)编辑/etc/default/mysql-mmm-agent来开启:ENABLED=1然后启动它:/etc/init.d/mysql-mmm-agent start启动监控(在监控机上):/etc/init.d/mysql-mmm-monitor startu 利用mmm_control监控mysql服务器状态:[root@server3 mysql-mmm]# mmm_control show db1(192.168.1.161) master/ONLINE. Roles: reader(192.168.1.112), writer(192.168.1.113) db2(192.168.1.162) master/ONLINE. Roles: reader(192.168.1.111) u 测试看两个mysql服务器能否实现故障自动切换停掉作为写的db1上的mysql,查看写的服务器会不会自动转移到db2上去停掉几秒钟后用mmm_control show查看:[root@server3 mysql-mmm]# mmm_control show db1(192.168.1.161) master/HARD_OFFLINE. Roles: db2(192.168.1.162) master/ONLINE. Roles: reader(192.168.1.111), reader(192.168.1.112), writer(192.168.1.113)我们可以看到已经把db2当作主写服务器 再来看看db1恢复后会是什么情况:[root@server3 mysql-mmm]# mmm_control show db1(192.168.1.161) master/ONLINE. Roles: reader(192.168.1.111) db2(192.168.1.162) master/ONLINE. Roles: reader(192.168.1.112), writer(192.168.1.113)我们可以看到当db1恢复后就充当slave的角色了!只有当db2挂了以后db1又会担当起主服务器的写入功能 u mmm_control命令简介[root@server3 mysql-mmm]# mmm_control helpValid commands are: help - show this message #查看帮助信息ping - ping monitor#ping监控show - show status#查看状态信息checks [<host>|all [<check>|all]] - show checks status#显示检查状态,包括(ping、mysql、rep_threads、rep_backlog)set_online <host> - set host <host> online#设置某host为online状态set_offline <host> - set host <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] <role> <host> - move exclusive role <role> to host <host> #更改host的模式,比如更改处于slave的mysql数据库角色为write (Only use --force if you know what you are doing!)set_ip <ip> <host> - set role with ip <ip> to host <host>#为host设置ip,只有passive模式的时候才允许更改!使用MySQL Migration Toolkit快速将Oracle数据导入MySQLVMware下Linux的MySQL安装和升级相关资讯 CentOS
- CentOS虚拟机NAT静态IP设置 (07/04/2013 17:09:32)
- CentOS 格式化新硬盘并设置开机自 (07/04/2013 16:50:50)
- 服务器为何用CentOS不用Ubnutu (02/24/2013 15:19:10)
| - CentOS /usr/libexec/gconf-sanity (07/04/2013 17:07:42)
- 为什么我们选择CentOS而不是Debian (06/06/2013 06:19:40)
- 在CentOS下搭建Android 开发环境 (02/18/2013 09:14:14)
|
本文评论 查看全部评论 (0)