部署集羣基礎環境,MySQL-MMM架構部署,MySQL-MMM架構使用

部署集羣基礎環境

1.1 問題

本案例要求爲MySQL集羣準備基礎環境,完成如下任務操做:mysql

  • 數據庫受權
  • 部署MySQL雙主多從結構
  • 配置本機hosts解析記錄

1.2 方案

使用4臺RHEL 6虛擬機,如圖-1所示。其中192.168.4.十、192.168.4.11做爲MySQL雙主服務器,192.168.4.十二、192.168.4.13做爲主服務器的從服務器。sql

圖-1數據庫

1.3 步驟

實現此案例須要按照以下步驟進行。vim

步驟一:準備環境服務器

  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執行如下操做)dom

  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執行如下操做)socket

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

步驟三:部署雙主多從結構ide

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 '\h' for 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)配置主從從從關係

配置master二、slave一、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.十、192.168.4.11做爲MySQL雙主服務器,192.168.4.十二、 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臺服務器(master一、master二、slave一、slave二、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 ~]#
相關文章
相關標籤/搜索