MySQL-MMM架构部署
2.1 问题
本案例要求熟悉实现MySQL-MMM的架构部署主要包括以下任务
- 安装依赖包
- 安装软件包
- 配置MySQL-MMM
2.2 方案
使用5台RHEL 6虚拟机如图-2所示。其中192.168.4.10、192.168.4.11作为MySQL双主服务器192.168.4.12、192.168.4.13作为主服务器的从服务器192.168.4.100作为MySQL-MMM架构中管理监控服务器实现监控MySQL主从服务器的工作状态及决定故障节点的移除或恢复工作架构搭建完成后使用客户机192.168.4.120进行访问客户机需要安装MySQL-client软件包。
图-2
2.3 步骤
实现此案例需要按照如下步骤进行。
步骤一安装MySQL-MMM
1安装依赖关系MySQL集群内5台服务器master1master2slave1slave2monitor均需安装
- [[email protected] ~]# yum -y install gcc* perl-Date-Manip perl-Date-Manip perl-Date-Manip perl-XML-DOM-XPath perl-XML-Parser perl-XML-RegExp rrdtool perl-Class-Singleton perl perl-DBD-MySQL perl-Params-Validate perl-MailTools perl-Time-HiRes
2安装MySQL-MMM软件依赖包MySQL集群内5台服务器master1master2slave1slave2monitor均需安装软件包讲师提供
安装安装Log-Log4perl 类
- [[email protected]-master1 ~]# rpm -ivh perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
安装Algorithm-Diff类
- [[email protected]-master1 ~]# tar -zxvf Algorithm-Diff-1.1902.tar.gz //解压安装包
- .. ..
- [[email protected]-master1 ~]# cd Algorithm-Diff-1.1902 //切换到安装目录
- [[email protected]-master1 Algorithm-Diff-1.1902]# perl Makefile.PL //生成makefile文件
- [[email protected]-master1 Algorithm-Diff-1.1902]# make && make install //编译编译安装
- .. ..
- [[email protected]-master1 Algorithm-Diff-1.1902]# cd //切换到软件包目录
安装Proc-Daemon类
- [[email protected]-master1 ~]# tar -zxvf Proc-Daemon-0.03.tar.gz //解压安装包
- .. ..
- [[email protected]-master1 ~]# cd Proc-Daemon-0.03 //切换到安装目录
- [[email protected]-master1 Proc-Daemon-0.03]# perl Makefile.PL //生成makefile文件
- Checking if your kit is complete...
- Looks good
- Writing Makefile for Proc::Daemon
- [[email protected]-master1 Proc-Daemon-0.03]# make && make install //编译编译安装
- .. ..
- [[email protected]-master1 Proc-Daemon-0.03]# cd //切换到软件包目录
安装Net-ARP虚拟IP分配工具
- [[email protected]-master1 ~]# gunzip Net-ARP-1.0.8.tgz //使用gunzip解压tgz格式的安装包
- [[email protected]-master1 ~]# tar xvf Net-ARP-1.0.8.tar //解压tar安装包
- .. ..
- [[email protected]-master1 ~]# cd Net-ARP-1.0.8 //切换到安装目录
- [[email protected]-master1 Net-ARP-1.0.8]# perl Makefile.PL //生成makefile文件
- [[email protected]-master1 Net-ARP-1.0.8]# make && make install //编译编译安装
- .. ..
- [[email protected]-master1 Net-ARP-1.0.8]# cd //切换到软件包目录
安装Mysql-MMM软件包
- [[email protected]-master1 ~]# tar xvf mysql-mmm-2.2.1.tar.gz //解压安装包
- .. ..
- [[email protected]-master1 ~]# cd mysql-mmm-2.2.1 //切换到安装目录
- [[email protected]-master1 mysql-mmm-2.2.1]# make && make install //编译编译安装
步骤二修改配置文件
1修改公共配置文件
本案例中MySQL集群的5台服务器master1、master2、slave1、slave2、monitor都需要配置可以先配好一台后使用scp复制。
- [[email protected] ~]# vim /etc/mysql-mmm/mmm_common.conf
- active_master_role writer
- <host default>
- cluster_interface eth0 //设置主从同步的用户
- pid_path /var/run/mmm_agentd.pid
- bin_path /usr/lib/mysql-mmm/
- replication_user slaveuser //设置主从同步的用户
- replication_password pwd123 //设置主从同步用户密码
- agent_user agent //mmm-agent控制数据库用户
- agent_password agent //mmm-agent控制数据库用户密码
- </host>
- <host master1> //设置第一个主服务器
- ip 192.168.4.10 //master1 IP 地址
- mode master
- peer master2 //指定另外一台主服务器
- </host>
- <host master2> //指定另外一台主服务器
- ip 192.168.4.11
- mode master
- peer master1
- </host>
- <host slave1> //设置第一台从服务器
- ip 192.168.4.12 //slave1 IP 地址
- mode slave //本段落配置的是slave服务器
- </host>
- <host slave2>
- ip 192.168.4.13
- mode slave
- </host>
- <role writer> //设置写入服务器工作模式
- hosts master1,master2 //提供写的主服务器
- ips 192.168.4.200 //设置VIP地址
- mode exclusive //排他模式
- </role>
- <role reader> //设置读取服务器工作模式
- hosts slave1,slave2 //提供读的服务器信息
- ips 192.168.4.201,192.168.4.202 //多个虚拟IP
- mode balanced //均衡模式
- </role>
2修改管理主机配置文件monitor主机配置
- [[email protected] ~]# vim /etc/mysql-mmm/mmm_mon.conf
- include mmm_common.conf
- <monitor>
- ip 192.168.4.100 //设置管理主机IP地址
- pid_path /var/run/mmm_mond.pid
- bin_path /usr/lib/mysql-mmm/
- status_path /var/lib/misc/mmm_mond.status
- ping_ips 192.168.4.10,192.168.4.11,192.168.4.12,192.168.4.13
- //设置被监控数据库
- </monitor>
- <host default>
- monitor_user monitor //监控数据库MySQL用户 monitor_password monitor //监控数据库MySQL用户密码
- </host>
- debug 0
3修改客户端配置文件
master1配置
- [[email protected] ~]# cat /etc/mysql-mmm/mmm_agent.conf
- include mmm_common.conf
- this master1
master2配置
- [[email protected] ~]# cat /etc/mysql-mmm/mmm_agent.conf
- include mmm_common.conf
- this master2
slave1配置
- [[email protected] ~]# cat /etc/mysql-mmm/mmm_agent.conf
- include mmm_common.conf
- this slave1
slave2配置
- [[email protected] ~]# cat /etc/mysql-mmm/mmm_agent.conf
3 MySQL-MMM架构使用
3.1 问题
本案例要求基于普通版的MySQL服务器改造MMM架构完成以下任务操作
- 启动MMM集群架构
- 设置集群中服务器为online状态
3.2 方案
MySQL-MMM架构部署完成后需要启动数据库端启动mmm-agent进程管理端启动mmm-monitor进程启动完成后设置所有数据库主机状态为online。
3.3 步骤
实现此案例需要按照如下步骤进行。
步骤一启动MMM集群架构
1启动mmm-agent进程
master1操作
- [[email protected] ~]# /etc/init.d/mysql-mmm-agent start
master2操作
- [[email protected] ~]# /etc/init.d/mysql-mmm-agent start
slave1操作
- [[email protected] ~]# /etc/init.d/mysql-mmm-agent start
slave2操作
- [[email protected] ~]# /etc/init.d/mysql-mmm-agent start
2启动mmm-monitor进程
monitor主机操作
- [[email protected] ~]# /etc/init.d/mysql-mmm-monitor start
步骤二设置集群中服务器为online状态
控制命令只能在管理端monitor服务器上执行。
查看当前集群中各服务器状态
- [[email protected] ~]# mmm_control show
设置4台数据库主机状态为online
- [[email protected] ~]# mmm_control set_online master1
- OK: State of ‘master1‘ changed to ONLINE. Now you can wait some time and check its new roles!
- [[email protected] ~]# mmm_control set_online master2
- OK: State of ‘master2‘ changed to ONLINE. Now you can wait some time and check its new roles!
- [[email protected] ~]# mmm_control set_online slave1
- OK: State of ‘slave1‘ changed to ONLINE. Now you can wait some time and check its new roles!
- [[email protected] ~]# mmm_control set_online slave2
再次查看当前集群中各服务器状态
- [[email protected] ~]# mmm_control show
- master1(192.168.4.10) master/ONLINE. Roles: writer(192.168.4.200)
- master2(192.168.4.11) master/ONLINE. Roles:
- slave1(192.168.4.12) slave/ONLINE. Roles: reader(192.168.4.201)
- slave2(192.168.4.13) slave/ONLINE. Roles: reader(192.168.4.202)
步骤三测试MySQL-MMM架构
1客户机安装MySQL-client软件包
- [[email protected] ~]# tar xvf MySQL-5.6.15-1.el6.x86_64.rpm-bundle.tar
- .. ..
- [[email protected] ~]# rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm
2)MySQL-MMM虚拟IP访问测试
- [[email protected] ~]# mysql -h192.168.4.200 -uroot -ppwd123 -e "show databases"
- Warning: Using a password on the command line interface can be insecure.
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | tarena |
- | test |
- +--------------------+
- [[email protected] ~]#
- [[email protected] ~]# mysql -h192.168.4.200 -uroot -ppwd123 -e "show databases"
- Warning: Using a password on the command line interface can be insecure.
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | tarena |
- | test |
- +--------------------+
- [[email protected] ~]#
- [[email protected] ~]# mysql -h192.168.4.202 -uroot -ppwd123 -e "show databases"
- Warning: Using a password on the command line interface can be insecure.
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | tarena |
- | test |
- +--------------------+
2主数据库宕机测试
- [[email protected] ~]# service mysql stop //停止master1上服务
- Shutting down MySQL.... [确定]
- [[email protected] ~]#
- [[email protected] ~]# mmm_control show //查看集群内服务器状态
通过输出信息可以看到虚拟IP从master1切换到master2
- master1(192.168.4.10) master/HARD_OFFLINE. Roles:
- master2(192.168.4.11) master/ONLINE. Roles: writer(192.168.4.200)
- slave1(192.168.4.12) slave/ONLINE. Roles: reader(192.168.4.201)
- slave2(192.168.4.13) slave/ONLINE. Roles: reader(192.168.4.202)
- [[email protected] ~]#
- [[email protected] ~]# mysql -h192.168.4.200 -uroot -ppwd123 -e "show databases" //访问虚拟IP测试
- Warning: Using a password on the command line interface can be insecure.
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | tarena |
- | test |
- +--------------------+