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

部署集群基础环境

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. [[email protected] ~]# 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. [[email protected] ~]# 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. [[email protected] ~]#

步骤二:部署数据库主机

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

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

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

  1. [[email protected] ~]# 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. [[email protected] ~]# 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 ‘\h‘ for 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. [[email protected] ~]#

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

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

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

  1. [[email protected] ~]# 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 ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

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

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

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

master1设置:

  1. [[email protected] ~]# 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. [[email protected] ~]# service mysql restart                //重启MySQL服务
  14. Shutting down MySQL.. [确定]
  15. Starting MySQL.. [确定]
  16. [[email protected] ~]# ls /var/lib/mysql/master1-bin*        //查看binlog日志是否生成
  17. /var/lib/mysql/master1-bin.000001 /var/lib/mysql/master1-bin.index
  18. [[email protected] ~]#

master2设置:

  1. [[email protected] ~]# 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. [[email protected] ~]# service mysql restart
  14. Shutting down MySQL.. [确定]
  15. Starting MySQL. [确定]
  16. [[email protected] ~]# ls /var/lib/mysql/master2-bin.*
  17. /var/lib/mysql/master2-bin.000001 /var/lib/mysql/master2-bin.index

3)从库设置server_id

slave1设置:

  1. [[email protected] ~]# 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. [[email protected] ~]# service mysql restart
  13. Shutting down MySQL.. [确定]
  14. Starting MySQL.. [确定]
  15. [[email protected] ~]#

slave2设置:

  1. [[email protected] ~]# 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. [[email protected] ~]# service mysql restart
  13. Shutting down MySQL.. [确定]
  14. Starting MySQL. [确定]
  15. [[email protected] ~]#

4)配置主从从从关系

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

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

  1. [[email protected] ~]# 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. [[email protected] ~]# 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. [[email protected] ~]# 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. [[email protected] ~]# 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. [[email protected] ~]# 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. [[email protected] ~]# 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. [[email protected] ~]# 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. [[email protected] ~]# 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. [[email protected] ~]#

slave1主机查看:

  1. [[email protected] ~]# 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. [[email protected] ~]#

slave2主机查看:

  1. [[email protected] ~]# 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. [[email protected] ~]#

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. [[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. .. ..

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

安装安装Log-Log4perl 类

  1. [[email protected]-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. [[email protected]-master1 ~]# tar -zxvf Algorithm-Diff-1.1902.tar.gz //解压安装包
  2. .. ..
  3. [[email protected]-master1 ~]# cd Algorithm-Diff-1.1902                //切换到安装目录
  4. [[email protected]-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. [[email protected]-master1 Algorithm-Diff-1.1902]# make && make install        //编译,编译安装
  9. .. ..
  10. [[email protected]-master1 Algorithm-Diff-1.1902]# cd                //切换到软件包目录
  11. [[email protected]-master1 ~]#

安装Proc-Daemon类

  1. [[email protected]-master1 ~]# tar -zxvf Proc-Daemon-0.03.tar.gz    //解压安装包
  2. .. ..
  3. [[email protected]-master1 ~]# cd Proc-Daemon-0.03                    //切换到安装目录
  4. [[email protected]-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. [[email protected]-master1 Proc-Daemon-0.03]# make && make install    //编译,编译安装
  9. .. ..
  10. [[email protected]-master1 Proc-Daemon-0.03]# cd                    //切换到软件包目录
  11. [[email protected]-master1 ~]#

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

  1. [[email protected]-master1 ~]# gunzip Net-ARP-1.0.8.tgz    //使用gunzip解压tgz格式的安装包
  2. [[email protected]-master1 ~]# tar xvf Net-ARP-1.0.8.tar            //解压tar安装包
  3. .. ..
  4. [[email protected]-master1 ~]# cd Net-ARP-1.0.8                    //切换到安装目录
  5. [[email protected]-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. [[email protected]-master1 Net-ARP-1.0.8]# make && make install    //编译,编译安装
  11. .. ..
  12. [[email protected]-master1 Net-ARP-1.0.8]# cd                        //切换到软件包目录
  13. [[email protected]-master1 ~]#

安装Mysql-MMM软件包:

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

步骤二:修改配置文件

1)修改公共配置文件

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

  1. [[email protected] ~]# 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. [[email protected] ~]#

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

  1. [[email protected] ~]# 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. [[email protected] ~]#

3)修改客户端配置文件

master1配置

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

master2配置

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

slave1配置

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

slave2配置

  1. [[email protected] ~]# 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. [[email protected] ~]# /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. [[email protected] ~]# /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. [[email protected] ~]# /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. [[email protected]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. [[email protected] ~]# /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. [[email protected] ~]# 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. [[email protected] ~]# 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. [[email protected] ~]# 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. [[email protected] ~]# 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. [[email protected] ~]# 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. [[email protected] ~]#

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

  1. [[email protected] ~]# 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. [[email protected] ~]#

步骤三:测试MySQL-MMM架构

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

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

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

  1. [[email protected] ~]# 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. [[email protected] ~]#
  13. [[email protected] ~]# 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. [[email protected] ~]#
  25. [[email protected] ~]# 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. [[email protected] ~]#

3)主数据库宕机测试

  1. [[email protected] ~]# service mysql stop                    //停止master1上服务
  2. Shutting down MySQL.... [确定]
  3. [[email protected] ~]#
  4. [[email protected] ~]# 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. [[email protected] ~]#
  6. [[email protected] ~]# 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. [[email protected] ~]#

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

时间: 2024-10-10 15:06:09

部署集群基础环境,MySQL-MMM架构部署,MySQL-MMM架构使用的相关文章

Database基础(七):部署集群基础环境、MySQL-MMM架构部署、MySQL-MMM架构使用

一.部署集群基础环境 目标: 本案例要求为MySQL集群准备基础环境,完成以下任务操作: 数据库授权 部署MySQL双主多从结构 配置本机hosts解析记录 方案: 使用4台RHEL 6虚拟机,如下图所示.其中192.168.4.10.192.168.4.11作为MySQL双主服务器,192.168.4.12.192.168.4.13作为主服务器的从服务器. 步骤: 步骤一:准备环境 [[email protected] ~]# cat /etc/hosts    127.0.0.1   loc

实现MySQL读写分离 部署集群基础环境(有图)

实现MySQL读写分离 部署集群基础环境 1 实现MySQL读写分离1.1 问题 本案例要求配置2台MySQL服务器+1台代理服务器,实现MySQL代理的读写分离: 用户只需要访问MySQL代理服务器,而实际的SQL查询.写入操作交给后台的2台MySQL服务器来完成 其中Master服务器允许SQL查询.写入,Slave服务器只允许SQL查询 1.2 方案 使用4台RHEL 7.2虚拟机,如图-1所示.其中192.168.4.10.192.168.4.20分别作为MySQL主.从服务器,是整个服

mysql5.6部署集群基础环境

----------------------------- 部署集群基础环境 MySQL-MMM架构部署 MySQL-MMM架构使用 部署集群基础环境 192.168.4.10     master1 192.168.4.11     master2 192.168.4.12     slave1 192.168.4.13     slave2 192.168.4.100     monitor 使用5台mysql5.6 其中192.168.4.10.192.168.4.11作为mysql双主服

07: MMM集群概述 、 部署集群基础环境 、 MMM集群部署 、 总结和答疑

day07 部署MySQL高可用集群 高可用集群介绍: 主备模式 当主不能提供服务的时候备用主机接替它提供服务,这个过程对于客户端是透明的. 一 配置MySQL主从同步主主结构主从从一主多从 二配置MySQL-mmm perl mmm_monitor 监控服务 运行在管理节点主机上.mmm_agentd 代理服务 运行在所有的数据节点主机上. writer-vip : 192.168.4.100 read -vip : 192.168.4.101/102 2.1 在所有主机上安装mysql-mm

部署mysql集群基础环境

设置slave2为master1从:部署集群基础环境 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 步骤 实现此案例需要按照如下步骤进行. 步骤一:准备环境 [[email p

HPC 高性能集群基础环境安装

HPC 基础环境配置 1.1.操作系统 配置? 操作系统:redhat enterprise linuxt 6? 管理节点:HOSTNAME:desktop IP:192.168.199.132计算节点: HOSTNAME:c1 IP:192.168.199.133 HOSTNAME:c2 IP:192.168.199.134? 网络配置:固定IP,各个节点互通? 配置本地域名解析(所有节点):将所有的节点的IP HOSTNAME 写入到 /etc/hosts 并分发到所有节点. [[email

通过Rancher部署并扩容Kubernetes集群基础篇二

接上一篇通过Rancher部署并扩容Kubernetes集群基础篇一 7. 使用ConfigMap配置redis https://github.com/kubernetes/kubernetes.github.io/blob/master/docs/user-guide/configmap/redis/redis-config redis-config maxmemory 2mb     maxmemory-policy allkeys-lru # kubectl create configma

LVS集群基础知识

LVS集群基础知识 LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一. 优点 1.开源,免费 2.在网上能找到一些相关技术资源 3.具有软件负载均衡的一些优点 缺点 1.最核心的就是没有可靠的支持服务,没有人对其结果负责: 2.功能比较简单,支持复杂应用的负载均衡能力较差,如算法较少等: 3.开启隧道方式需重编译内核: 4.配置复杂: 5.主要应用于LINUX

[转贴]CentOS7.5 Kubernetes V1.13(最新版)二进制部署集群

CentOS7.5 Kubernetes V1.13(最新版)二进制部署集群 http://blog.51cto.com/10880347/2326146 一.概述 kubernetes 1.13 已发布,这是 2018 年年内第四次也是最后一次发布新版本.Kubernetes 1.13 是迄今为止发布间隔最短的版本之一(与上一版本间隔十周),主要关注 Kubernetes 的稳定性与可扩展性,其中存储与集群生命周期相关的三项主要功能已逐步实现普遍可用性. Kubernetes 1.13 的核心