码迷,mamicode.com
首页 > 数据库 > 详细

部署集群基础环境,MySQL-MMM架构部署,MySQL-MMM架构使用

时间:2018-01-19 20:49:39      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:head   for   algo   offline   diff   部署   cti   loss   名称   

部署集群基础环境

1.1 问题

本案例要求为MySQL集群准备基础环境,完成以下任务操作:

  • 数据库授权
  • 部署MySQL双主多从结构
  • 配置本机hosts解析记录

1.2 方案

使用4台RHEL 6虚拟机,如图-1所示。其中192.168.4.10、192.168.4.11作为MySQL双主服务器,192.168.4.12、192.168.4.13作为主服务器的从服务器。

技术分享图片

图-1

1.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:准备环境

  1. [root@master1 ~]# cat /etc/hosts
  2. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  3. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  4. 192.168.4.10 master1 master1.tarena.com
  5. 192.168.4.11 master2 master2.tarena.com
  6. 192.168.4.12 slave1 slave1.tarena.com
  7. 192.168.4.13 slave2 slave2.tarena.com
  8. 192.168.4.100 master1 master1.tarena.com
  9. [root@master1 ~]# ping -c 2 master1
  10. PING master1 (192.168.4.10) 56(84) bytes of data.
  11. 64 bytes from master1 (192.168.4.10): icmp_seq=1 ttl=64 time=0.378 ms
  12. 64 bytes from master1 (192.168.4.10): icmp_seq=2 ttl=64 time=0.396 ms
  13. --- master1 ping statistics ---
  14. 2 packets transmitted, 2 received, 0% packet loss, time 1001ms
  15. rtt min/avg/max/mdev = 0.378/0.387/0.396/0.009 ms
  16. [root@master1 ~]#

步骤二:部署数据库主机

1)安装启动数据库(4台数据库主机master1,master2,slave1,slave2执行以下操作)

  1. [root@master1 ~]# tar xvf MySQL-5.6.15-1.el6.x86_64.rpm-bundle.tar    //解压软件包
  2. .. ..
  3. [root@master1 ~]# rpm -Uvh MySQL-*.rpm                                //安装MySQL
  4. .. ..
  5. [root@master1 ~]# service mysql start
  6. Starting MySQL. [确定]

2)初始化配置数据库(4台数据库主机master1,master2,slave1,slave2执行以下操作)

  1. [root@master1 ~]# cat /root/.mysql_secret         //查看随机生成密码
  2. # The random password set for the root user at Thu May 7 22:15:47 2015 (local time): wW1BNAjD
  3. [root@master1 ~]# mysql -uroot -pwW1BNAjD        //使用随机生成密码登陆
  4. Warning: Using a password on the command line interface can be insecure.
  5. Welcome to the MySQL monitor. Commands end with ; or \g.
  6. Your MySQL connection id is 1
  7. Server version: 5.6.15
  8. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  9. Oracle is a registered trademark of Oracle Corporation and/or its
  10. affiliates. Other names may be trademarks of their respective
  11. owners.
  12. Type ‘help;‘ or \hfor help. Type \c‘ to clear the current input statement.
  13. mysql> set password=password("pwd123");     //修改数据库root密码
  14. Query OK, 0 rows affected (0.49 sec)
  15. mysql> exit
  16. Bye
  17. [root@master1 ~]#

步骤三:部署双主多从结构

1)数据库授权(4台数据库主机master1,master2,slave1,slave2执行以下操作)

部署主从同步只需要授权一个主从同步用户即可,但是我们要部署MySQL-MMM架构,所以在这里我们将MySQL-MMM所需用户一并进行授权设置。再授权一个测试用户,在架构搭建完成时测试使用。

  1. [root@master1 ~]# mysql -uroot -ppwd123
  2. Warning: Using a password on the command line interface can be insecure.
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 2
  5. Server version: 5.6.15 MySQL Community Server (GPL)
  6. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type ‘help;‘ or \hfor help. Type \c‘ to clear the current input statement.

数据库授权部分为了方便试验我们直接允许所有地址访问了,真实环境需谨慎

  1. mysql> grant replication slave on *.* to slaveuser@"%" identified by "pwd123";                                //主从同步授权
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> grant replication client on *.* to monitor@"%" identified by "monitor";                                         //MMM所需架构用户授权
  4. Query OK, 0 rows affected (0.06 sec)        
  5. mysql> grant replication client,process,super on *.* to agent@"%" identified by "agent";                                 //MMM所需架构用户授权
  6. Query OK, 0 rows affected (0.00 sec)
  7. mysql> grant all on *.* to root@"%" identified by "pwd123"; //测试用户授权
  8. Query OK, 0 rows affected (0.00 sec)
  9. mysql>

2)开启主数据库binlog日志、设置server_id(master1,master2)

master1设置:

  1. [root@master1 ~]# cat /etc/my.cnf
  2. [mysqld]
  3. datadir=/var/lib/mysql
  4. socket=/var/lib/mysql/mysql.sock
  5. user=mysql
  6. server_id=10                        //设置server_id,该值集群中不可以重复
  7. log-bin                            //开启bin-log日志
  8. # Disabling symbolic-links is recommended to prevent assorted security risks
  9. symbolic-links=0
  10. [mysqld_safe]
  11. log-error=/var/log/mysqld.log
  12. pid-file=/var/run/mysqld/mysqld.pid
  13. [root@master1 ~]# service mysql restart                //重启MySQL服务
  14. Shutting down MySQL.. [确定]
  15. Starting MySQL.. [确定]
  16. [root@master1 ~]# ls /var/lib/mysql/master1-bin*        //查看binlog日志是否生成
  17. /var/lib/mysql/master1-bin.000001 /var/lib/mysql/master1-bin.index
  18. [root@master1 ~]#

master2设置:

  1. [root@master2 ~]# cat /etc/my.cnf
  2. [mysqld]
  3. datadir=/var/lib/mysql
  4. socket=/var/lib/mysql/mysql.sock
  5. user=mysql
  6. server_id=11
  7. log-bin
  8. # Disabling symbolic-links is recommended to prevent assorted security risks
  9. symbolic-links=0
  10. [mysqld_safe]
  11. log-error=/var/log/mysqld.log
  12. pid-file=/var/run/mysqld/mysqld.pid
  13. [root@master2 ~]# service mysql restart
  14. Shutting down MySQL.. [确定]
  15. Starting MySQL. [确定]
  16. [root@master2 ~]# ls /var/lib/mysql/master2-bin.*
  17. /var/lib/mysql/master2-bin.000001 /var/lib/mysql/master2-bin.index

3)从库设置server_id

slave1设置:

  1. [root@slave1 ~]# cat /etc/my.cnf
  2. [mysqld]
  3. datadir=/var/lib/mysql
  4. socket=/var/lib/mysql/mysql.sock
  5. user=mysql
  6. server_id=12
  7. # Disabling symbolic-links is recommended to prevent assorted security risks
  8. symbolic-links=0
  9. [mysqld_safe]
  10. log-error=/var/log/mysqld.log
  11. pid-file=/var/run/mysqld/mysqld.pid
  12. [root@slave1 ~]# service mysql restart
  13. Shutting down MySQL.. [确定]
  14. Starting MySQL.. [确定]
  15. [root@slave1 ~]#

slave2设置:

  1. [root@slave2 ~]# cat /etc/my.cnf
  2. [mysqld]
  3. datadir=/var/lib/mysql
  4. socket=/var/lib/mysql/mysql.sock
  5. user=mysql
  6. server_id=13
  7. # Disabling symbolic-links is recommended to prevent assorted security risks
  8. symbolic-links=0
  9. [mysqld_safe]
  10. log-error=/var/log/mysqld.log
  11. pid-file=/var/run/mysqld/mysqld.pid
  12. [root@slave2 ~]# service mysql restart
  13. Shutting down MySQL.. [确定]
  14. Starting MySQL. [确定]
  15. [root@slave2 ~]#

4)配置主从从从关系

配置master2、slave1、slave2成为master1的从服务器

查看master1服务器binlong日志使用节点信息:

  1. [root@master1 ~]# mysql -uroot -ppwd123
  2. .. ..
  3. mysql> show master status\G
  4. *************************** 1. row ***************************
  5. File: master1-bin.000001
  6. Position: 120
  7. Binlog_Do_DB:
  8. Binlog_Ignore_DB:
  9. Executed_Gtid_Set:
  10. 1 row in set (0.00 sec)
  11. mysql>

设置master2为master1从:

  1. [root@master2 ~]# mysql -uroot -ppwd123
  2. .. ..
  3. mysql> change master to                         //设置主服务器信息
  4. -> master_host="192.168.4.10",                //设置主服务器IP地址
  5. -> master_user="slaveuser",                //设置主从同步用户
  6. -> master_password="pwd123",                //设置主从同步密码
  7. -> master_log_file="master1-bin.000001",    //设置主库binlog日志名称
  8. -> master_log_pos=120;                        //设置主从binlog日志使用节点
  9. Query OK, 0 rows affected, 2 warnings (0.06 sec)
  10. mysql> start slave;                            //启动同步进程
  11. Query OK, 0 rows affected (0.00 sec)
  12. mysql> show slave status\G                        //查看主从是否成功
  13. .. ..

启动同步进程后查看IO节点和SQL节点是否为Yes如果均为Yes表示主从正常。

  1. Slave_IO_Running: Yes                //IO节点正常
  2. Slave_SQL_Running: Yes                //SQL节点正常
  3. .. ..
  4. mysql>

设置slave1为master1从:

  1. [root@slave1 ~]# mysql -uroot -ppwd123
  2. .. ..
  3. mysql> change master to
  4. -> master_host="192.168.4.10",
  5. -> master_user="slaveuser",
  6. -> master_password="pwd123",
  7. -> master_log_file="master1-bin.000001",
  8. -> master_log_pos=120;
  9. Query OK, 0 rows affected, 2 warnings (0.12 sec)
  10. mysql> start slave;
  11. Query OK, 0 rows affected (0.16 sec)
  12. mysql> show slave status\G
  13. .. ..
  14. Slave_IO_Running: Yes                //IO节点正常
  15. Slave_SQL_Running: Yes                //SQL节点正常
  16. .. ..
  17. mysql>

设置slave2为master1从:

  1. [root@slave2 ~]# mysql -uroot -ppwd123
  2. .. ..
  3. mysql> change master to
  4. -> master_host="192.168.4.10",
  5. -> master_user="slaveuser",
  6. -> master_password="pwd123",
  7. -> master_log_file="master1-bin.000001",
  8. -> master_log_pos=120;
  9. Query OK, 0 rows affected, 2 warnings (0.13 sec)
  10. mysql> start slave;
  11. Query OK, 0 rows affected (0.27 sec)
  12. mysql> show slave status\G
  13. .. ..
  14. Slave_IO_Running: Yes                //IO节点正常
  15. Slave_SQL_Running: Yes                //SQL节点正常
  16. .. ..
  17. mysql>

5)配置主主从从关系,将master1配置为master2的从

查看master2的binlog使用信息:

  1. [root@master2 ~]# mysql -uroot -ppwd123
  2. .. ..
  3. mysql> show master status\G
  4. *************************** 1. row ***************************
  5. File: master2-bin.000001
  6. Position: 120
  7. Binlog_Do_DB:
  8. Binlog_Ignore_DB:
  9. Executed_Gtid_Set:
  10. 1 row in set (0.00 sec)
  11. mysql>

设置master1成为master2的从:

  1. [root@master1 ~]# mysql -uroot -ppwd123
  2. .. ..
  3. mysql> change master to
  4. -> master_host="192.168.4.11",
  5. -> master_user="slaveuser",
  6. -> master_password="pwd123",
  7. -> master_log_file="master2-bin.000001",
  8. -> master_log_pos=120;
  9. Query OK, 0 rows affected, 2 warnings (0.31 sec)
  10. mysql> start slave;
  11. Query OK, 0 rows affected (0.27 sec)
  12. mysql> show slave status\G
  13. .. ..
  14. Slave_IO_Running: Yes                //IO节点正常
  15. Slave_SQL_Running: Yes                //SQL节点正常
  16. .. ..
  17. mysql>

6)测试主从架构是否成功

master1更新数据,查看其它主机是否同步:

  1. [root@master1 ~]# mysql -uroot -ppwd123
  2. .. ..
  3. mysql> show databases;
  4. +--------------------+
  5. | Database |
  6. +--------------------+
  7. | information_schema |
  8. | mysql |
  9. | performance_schema |
  10. | test |
  11. +--------------------+
  12. 4 rows in set (0.00 sec)
  13. mysql> create database tarena;
  14. Query OK, 1 row affected (0.06 sec)
  15. mysql> show databases;
  16. +--------------------+
  17. | Database |
  18. +--------------------+
  19. | information_schema |
  20. | mysql |
  21. | performance_schema |
  22. | tarena |
  23. | test |
  24. +--------------------+
  25. 5 rows in set (0.00 sec)
  26. mysql>

master2主机查看:

  1. [root@master2 ~]# mysql -uroot -ppwd123 -e "show databases"
  2. Warning: Using a password on the command line interface can be insecure.
  3. +--------------------+
  4. | Database |
  5. +--------------------+
  6. | information_schema |
  7. | mysql |
  8. | performance_schema |
  9. | tarena |
  10. | test |
  11. +--------------------+
  12. [root@master2 ~]#

slave1主机查看:

  1. [root@slave1 ~]# mysql -uroot -ppwd123 -e "show databases"
  2. Warning: Using a password on the command line interface can be insecure.
  3. +--------------------+
  4. | Database |
  5. +--------------------+
  6. | information_schema |
  7. | mysql |
  8. | performance_schema |
  9. | tarena |
  10. | test |
  11. +--------------------+
  12. [root@slave1 ~]#

slave2主机查看:

  1. [root@slave2 ~]# mysql -uroot -ppwd123 -e "show databases"
  2. Warning: Using a password on the command line interface can be insecure.
  3. +--------------------+
  4. | Database |
  5. +--------------------+
  6. | information_schema |
  7. | mysql |
  8. | performance_schema |
  9. | tarena |
  10. | test |
  11. +--------------------+
  12. [root@slave2 ~]#

2 MySQL-MMM架构部署

2.1 问题

本案例要求熟悉实现MySQL-MMM的架构部署,主要包括以下任务:

  1. 安装依赖包
  2. 安装软件包
  3. 配置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台服务器master1,master2,slave1,slave2,monitor)均需安装

  1. [root@master1 ~]# 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. .. ..

2)安装MySQL-MMM软件依赖包(MySQL集群内5台服务器master1,master2,slave1,slave2,monitor)均需安装,软件包讲师提供

安装安装Log-Log4perl 类

  1. [root@mysql-master1 ~]# rpm -ivh perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
  2. warning: perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY
  3. Preparing... ######################### [100%]
  4. 1:perl-Log-Log4perl ######################## [100%]

安装Algorithm-Diff类

  1. [root@mysql-master1 ~]# tar -zxvf Algorithm-Diff-1.1902.tar.gz //解压安装包
  2. .. ..
  3. [root@mysql-master1 ~]# cd Algorithm-Diff-1.1902                //切换到安装目录
  4. [root@mysql-master1 Algorithm-Diff-1.1902]# perl Makefile.PL    //生成makefile文件
  5. Checking if your kit is complete...
  6. Looks good
  7. Writing Makefile for Algorithm::Diff
  8. [root@mysql-master1 Algorithm-Diff-1.1902]# make && make install        //编译,编译安装
  9. .. ..
  10. [root@mysql-master1 Algorithm-Diff-1.1902]# cd                //切换到软件包目录
  11. [root@mysql-master1 ~]#

安装Proc-Daemon类

  1. [root@mysql-master1 ~]# tar -zxvf Proc-Daemon-0.03.tar.gz    //解压安装包
  2. .. ..
  3. [root@mysql-master1 ~]# cd Proc-Daemon-0.03                    //切换到安装目录
  4. [root@mysql-master1 Proc-Daemon-0.03]# perl Makefile.PL    //生成makefile文件
  5. Checking if your kit is complete...
  6. Looks good
  7. Writing Makefile for Proc::Daemon
  8. [root@mysql-master1 Proc-Daemon-0.03]# make && make install    //编译,编译安装
  9. .. ..
  10. [root@mysql-master1 Proc-Daemon-0.03]# cd                    //切换到软件包目录
  11. [root@mysql-master1 ~]#

安装Net-ARP虚拟IP分配工具:

  1. [root@mysql-master1 ~]# gunzip Net-ARP-1.0.8.tgz    //使用gunzip解压tgz格式的安装包
  2. [root@mysql-master1 ~]# tar xvf Net-ARP-1.0.8.tar            //解压tar安装包
  3. .. ..
  4. [root@mysql-master1 ~]# cd Net-ARP-1.0.8                    //切换到安装目录
  5. [root@mysql-master1 Net-ARP-1.0.8]# perl Makefile.PL        //生成makefile文件
  6. Module Net::Pcap is required for make test!
  7. Checking if your kit is complete...
  8. Looks good
  9. Writing Makefile for Net::ARP
  10. [root@mysql-master1 Net-ARP-1.0.8]# make && make install    //编译,编译安装
  11. .. ..
  12. [root@mysql-master1 Net-ARP-1.0.8]# cd                        //切换到软件包目录
  13. [root@mysql-master1 ~]#

安装Mysql-MMM软件包:

  1. [root@mysql-master1 ~]# tar xvf mysql-mmm-2.2.1.tar.gz        //解压安装包
  2. .. ..
  3. [root@mysql-master1 ~]# cd mysql-mmm-2.2.1                    //切换到安装目录
  4. [root@mysql-master1 mysql-mmm-2.2.1]# make && make install    //编译,编译安装
  5. .. ..
  6. [root@mysql-master1 mysql-mmm-2.2.1]#

步骤二:修改配置文件

1)修改公共配置文件

本案例中MySQL集群的5台服务器(master1、master2、slave1、slave2、monitor)都需要配置,可以先配好一台后使用scp复制。

  1. [root@master1 ~]# vim /etc/mysql-mmm/mmm_common.conf
  2. active_master_role    writer
  3. <host default>
  4.     cluster_interface        eth0                //设置主从同步的用户
  5.     pid_path                /var/run/mmm_agentd.pid
  6.     bin_path                /usr/lib/mysql-mmm/
  7. replication_user slaveuser            //设置主从同步的用户
  8. replication_password pwd123            //设置主从同步用户密码
  9.     agent_user            agent                //mmm-agent控制数据库用户
  10.     agent_password        agent                //mmm-agent控制数据库用户密码
  11. </host>
  12. <host master1>                            //设置第一个主服务器
  13.     ip                    192.168.4.10            //master1 IP 地址
  14.     mode                    master
  15.     peer                    master2                //指定另外一台主服务器
  16. </host>
  17. <host master2>                            //指定另外一台主服务器
  18.     ip                    192.168.4.11
  19.     mode                    master
  20.     peer                    master1
  21. </host>
  22. <host slave1>                                //设置第一台从服务器
  23.     ip                    192.168.4.12            //slave1 IP 地址
  24.     mode                    slave                //本段落配置的是slave服务器
  25. </host>
  26. <host slave2>
  27.     ip                    192.168.4.13
  28.     mode                    slave
  29. </host>
  30. <role writer>                                //设置写入服务器工作模式
  31.     hosts                master1,master2        //提供写的主服务器
  32.     ips                    192.168.4.200        //设置VIP地址
  33.     mode                    exclusive            //排他模式
  34. </role>
  35. <role reader>                                //设置读取服务器工作模式
  36.     hosts                slave1,slave2        //提供读的服务器信息
  37.     ips                    192.168.4.201,192.168.4.202    //多个虚拟IP
  38.     mode                    balanced                        //均衡模式
  39. </role>
  40. [root@master1 ~]#

2)修改管理主机配置文件(monitor主机配置)

  1. [root@monitor ~]# vim /etc/mysql-mmm/mmm_mon.conf
  2. include mmm_common.conf
  3. <monitor>
  4.     ip                        192.168.4.100        //设置管理主机IP地址
  5.     pid_path                /var/run/mmm_mond.pid
  6.     bin_path                /usr/lib/mysql-mmm/
  7.     status_path                /var/lib/misc/mmm_mond.status
  8.     ping_ips                192.168.4.10,192.168.4.11,192.168.4.12,192.168.4.13
  9.                                                 //设置被监控数据库
  10. </monitor>
  11. <host default>
  12.     monitor_user            monitor                    //监控数据库MySQL用户     monitor_password        monitor                    //监控数据库MySQL用户密码
  13. </host>
  14. debug 0
  15. [root@monitor ~]#

3)修改客户端配置文件

master1配置

  1. [root@master1 ~]# cat /etc/mysql-mmm/mmm_agent.conf
  2. include mmm_common.conf
  3. this master1

master2配置

  1. [root@master2 ~]# cat /etc/mysql-mmm/mmm_agent.conf
  2. include mmm_common.conf
  3. this master2

slave1配置

  1. [root@slave1 ~]# cat /etc/mysql-mmm/mmm_agent.conf
  2. include mmm_common.conf
  3. this slave1

slave2配置

  1. [root@slave2 ~]# cat /etc/mysql-mmm/mmm_agent.conf
  2. include mmm_common.conf
  3. this slave2

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操作:

  1. [root@master1 ~]# /etc/init.d/mysql-mmm-agent start
  2. Daemon bin: ‘/usr/sbin/mmm_agentd‘
  3. Daemon pid: ‘/var/run/mmm_agentd.pid‘
  4. Starting MMM Agent daemon... Ok

master2操作:

  1. [root@master2 ~]# /etc/init.d/mysql-mmm-agent start
  2. Daemon bin: ‘/usr/sbin/mmm_agentd‘
  3. Daemon pid: ‘/var/run/mmm_agentd.pid‘
  4. Starting MMM Agent daemon... Ok

slave1操作:

  1. [root@master2 ~]# /etc/init.d/mysql-mmm-agent start
  2. Daemon bin: ‘/usr/sbin/mmm_agentd‘
  3. Daemon pid: ‘/var/run/mmm_agentd.pid‘
  4. Starting MMM Agent daemon... Ok

slave2操作:

  1. [root@slave2 ~]# /etc/init.d/mysql-mmm-agent start
  2. Daemon bin: ‘/usr/sbin/mmm_agentd‘
  3. Daemon pid: ‘/var/run/mmm_agentd.pid‘
  4. Starting MMM Agent daemon... Ok

2)启动mmm-monitor进程

monitor主机操作:

  1. [root@monitor ~]# /etc/init.d/mysql-mmm-monitor start
  2. Daemon bin: ‘/usr/sbin/mmm_mond‘
  3. Daemon pid: ‘/var/run/mmm_mond.pid‘
  4. Starting MMM Monitor daemon: Ok

步骤二:设置集群中服务器为online状态

控制命令只能在管理端monitor服务器上执行。

查看当前集群中各服务器状态:

  1. [root@monitor ~]# mmm_control show
  2. master1(192.168.4.10) master/AWAITING_RECOVERY. Roles:
  3. master2(192.168.4.11) master/AWAITING_RECOVERY. Roles:
  4. slave1(192.168.4.12) slave/AWAITING_RECOVERY. Roles:
  5. slave2(192.168.4.13) slave/AWAITING_RECOVERY. Roles:

设置4台数据库主机状态为online:

  1. [root@monitor ~]# mmm_control set_online master1
  2. OK: State of ‘master1‘ changed to ONLINE. Now you can wait some time and check its new roles!
  3. [root@monitor ~]# mmm_control set_online master2
  4. OK: State of ‘master2‘ changed to ONLINE. Now you can wait some time and check its new roles!
  5. [root@monitor ~]# mmm_control set_online slave1
  6. OK: State of ‘slave1‘ changed to ONLINE. Now you can wait some time and check its new roles!
  7. [root@monitor ~]# mmm_control set_online slave2
  8. OK: State of ‘slave2‘ changed to ONLINE. Now you can wait some time and check its new roles!
  9. [root@monitor ~]#

再次查看当前集群中各服务器状态:

  1. [root@monitor ~]# mmm_control show
  2. master1(192.168.4.10) master/ONLINE. Roles: writer(192.168.4.200)
  3. master2(192.168.4.11) master/ONLINE. Roles:
  4. slave1(192.168.4.12) slave/ONLINE. Roles: reader(192.168.4.201)
  5. slave2(192.168.4.13) slave/ONLINE. Roles: reader(192.168.4.202)
  6. [root@monitor ~]#

步骤三:测试MySQL-MMM架构

1)客户机安装MySQL-client软件包

  1. [root@client ~]# tar xvf MySQL-5.6.15-1.el6.x86_64.rpm-bundle.tar
  2. .. ..
  3. [root@client ~]# rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm
  4. .. ..

2)MySQL-MMM虚拟IP访问测试

  1. [root@client ~]# mysql -h192.168.4.200 -uroot -ppwd123 -e "show databases"
  2. Warning: Using a password on the command line interface can be insecure.
  3. +--------------------+
  4. | Database |
  5. +--------------------+
  6. | information_schema |
  7. | mysql |
  8. | performance_schema |
  9. | tarena |
  10. | test |
  11. +--------------------+
  12. [root@client ~]#
  13. [root@client ~]# mysql -h192.168.4.200 -uroot -ppwd123 -e "show databases"
  14. Warning: Using a password on the command line interface can be insecure.
  15. +--------------------+
  16. | Database |
  17. +--------------------+
  18. | information_schema |
  19. | mysql |
  20. | performance_schema |
  21. | tarena |
  22. | test |
  23. +--------------------+
  24. [root@client ~]#
  25. [root@client ~]# mysql -h192.168.4.202 -uroot -ppwd123 -e "show databases"
  26. Warning: Using a password on the command line interface can be insecure.
  27. +--------------------+
  28. | Database |
  29. +--------------------+
  30. | information_schema |
  31. | mysql |
  32. | performance_schema |
  33. | tarena |
  34. | test |
  35. +--------------------+
  36. [root@client ~]#

3)主数据库宕机测试

  1. [root@master1 ~]# service mysql stop                    //停止master1上服务
  2. Shutting down MySQL.... [确定]
  3. [root@master1 ~]#
  4. [root@monitor ~]# mmm_control show                        //查看集群内服务器状态

通过输出信息可以看到虚拟IP从master1切换到master2:

  1. master1(192.168.4.10) master/HARD_OFFLINE. Roles:
  2. master2(192.168.4.11) master/ONLINE. Roles: writer(192.168.4.200)
  3. slave1(192.168.4.12) slave/ONLINE. Roles: reader(192.168.4.201)
  4. slave2(192.168.4.13) slave/ONLINE. Roles: reader(192.168.4.202)
  5. [root@monitor ~]#
  6. [root@client ~]# mysql -h192.168.4.200 -uroot -ppwd123 -e "show databases"    //访问虚拟IP测试
  7. Warning: Using a password on the command line interface can be insecure.
  8. +--------------------+
  9. | Database |
  10. +--------------------+
  11. | information_schema |
  12. | mysql |
  13. | performance_schema |
  14. | tarena |
  15. | test |
  16. +--------------------+
  17. [root@client ~]#

部署集群基础环境,MySQL-MMM架构部署,MySQL-MMM架构使用

标签:head   for   algo   offline   diff   部署   cti   loss   名称   

原文地址:https://www.cnblogs.com/xiaoren112/p/8318716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!