部署集羣基礎環境
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
步驟一:準備環境服務器
- [root@master1 ~]# cat /etc/hosts
- 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 192.168.4.10 master1 master1.tarena.com
- 192.168.4.11 master2 master2.tarena.com
- 192.168.4.12 slave1 slave1.tarena.com
- 192.168.4.13 slave2 slave2.tarena.com
- 192.168.4.100 master1 master1.tarena.com
- [root@master1 ~]# ping -c 2 master1
- PING master1 (192.168.4.10) 56(84) bytes of data.
- 64 bytes from master1 (192.168.4.10): icmp_seq=1 ttl=64 time=0.378 ms
- 64 bytes from master1 (192.168.4.10): icmp_seq=2 ttl=64 time=0.396 ms
- --- master1 ping statistics ---
- 2 packets transmitted, 2 received, 0% packet loss, time 1001ms
- rtt min/avg/max/mdev = 0.378/0.387/0.396/0.009 ms
- [root@master1 ~]#
步驟二:部署數據庫主機架構
1)安裝啓動數據庫(4臺數據庫主機master1,master2,slave1,slave2執行如下操做)dom
- [root@master1 ~]# tar xvf MySQL-5.6.15-1.el6.x86_64.rpm-bundle.tar //解壓軟件包
- .. ..
- [root@master1 ~]# rpm -Uvh MySQL-*.rpm //安裝MySQL
- .. ..
- [root@master1 ~]# service mysql start
- Starting MySQL. [肯定]
2)初始化配置數據庫(4臺數據庫主機master1,master2,slave1,slave2執行如下操做)socket
- [root@master1 ~]# cat /root/.mysql_secret //查看隨機生成密碼
- # The random password set for the root user at Thu May 7 22:15:47 2015 (local time): wW1BNAjD
- [root@master1 ~]# mysql -uroot -pwW1BNAjD //使用隨機生成密碼登錄
- Warning: Using a password on the command line interface can be insecure.
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 1
- Server version: 5.6.15
- Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql> set password=password("pwd123"); //修改數據庫root密碼
- Query OK, 0 rows affected (0.49 sec)
- mysql> exit
- Bye
- [root@master1 ~]#
步驟三:部署雙主多從結構ide
1)數據庫受權(4臺數據庫主機master1,master2,slave1,slave2執行如下操做)工具
部署主從同步只須要受權一個主從同步用戶便可,可是咱們要部署MySQL-MMM架構,因此在這裏咱們將MySQL-MMM所需用戶一併進行受權設置。再受權一個測試用戶,在架構搭建完成時測試使用。
- [root@master1 ~]# mysql -uroot -ppwd123
- Warning: Using a password on the command line interface can be insecure.
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 2
- Server version: 5.6.15 MySQL Community Server (GPL)
- Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
數據庫受權部分爲了方便試驗咱們直接容許全部地址訪問了,真實環境需謹慎
- mysql> grant replication slave on *.* to slaveuser@"%" identified by "pwd123"; //主從同步受權
- Query OK, 0 rows affected (0.00 sec)
- mysql> grant replication client on *.* to monitor@"%" identified by "monitor"; //MMM所需架構用戶受權
- Query OK, 0 rows affected (0.06 sec)
- mysql> grant replication client,process,super on *.* to agent@"%" identified by "agent"; //MMM所需架構用戶受權
- Query OK, 0 rows affected (0.00 sec)
- mysql> grant all on *.* to root@"%" identified by "pwd123"; //測試用戶受權
- Query OK, 0 rows affected (0.00 sec)
- mysql>
2)開啓主數據庫binlog日誌、設置server_id(master1,master2)
master1設置:
- [root@master1 ~]# cat /etc/my.cnf
- [mysqld]
- datadir=/var/lib/mysql
- socket=/var/lib/mysql/mysql.sock
- user=mysql
- server_id=10 //設置server_id,該值集羣中不能夠重複
- log-bin //開啓bin-log日誌
- # Disabling symbolic-links is recommended to prevent assorted security risks
- symbolic-links=0
- [mysqld_safe]
- log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid
- [root@master1 ~]# service mysql restart //重啓MySQL服務
- Shutting down MySQL.. [肯定]
- Starting MySQL.. [肯定]
- [root@master1 ~]# ls /var/lib/mysql/master1-bin* //查看binlog日誌是否生成
- /var/lib/mysql/master1-bin.000001 /var/lib/mysql/master1-bin.index
- [root@master1 ~]#
master2設置:
- [root@master2 ~]# cat /etc/my.cnf
- [mysqld]
- datadir=/var/lib/mysql
- socket=/var/lib/mysql/mysql.sock
- user=mysql
- server_id=11
- log-bin
- # Disabling symbolic-links is recommended to prevent assorted security risks
- symbolic-links=0
- [mysqld_safe]
- log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid
- [root@master2 ~]# service mysql restart
- Shutting down MySQL.. [肯定]
- Starting MySQL. [肯定]
- [root@master2 ~]# ls /var/lib/mysql/master2-bin.*
- /var/lib/mysql/master2-bin.000001 /var/lib/mysql/master2-bin.index
3)從庫設置server_id
slave1設置:
- [root@slave1 ~]# cat /etc/my.cnf
- [mysqld]
- datadir=/var/lib/mysql
- socket=/var/lib/mysql/mysql.sock
- user=mysql
- server_id=12
- # Disabling symbolic-links is recommended to prevent assorted security risks
- symbolic-links=0
- [mysqld_safe]
- log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid
- [root@slave1 ~]# service mysql restart
- Shutting down MySQL.. [肯定]
- Starting MySQL.. [肯定]
- [root@slave1 ~]#
slave2設置:
- [root@slave2 ~]# cat /etc/my.cnf
- [mysqld]
- datadir=/var/lib/mysql
- socket=/var/lib/mysql/mysql.sock
- user=mysql
- server_id=13
- # Disabling symbolic-links is recommended to prevent assorted security risks
- symbolic-links=0
- [mysqld_safe]
- log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid
- [root@slave2 ~]# service mysql restart
- Shutting down MySQL.. [肯定]
- Starting MySQL. [肯定]
- [root@slave2 ~]#
4)配置主從從從關係
配置master二、slave一、slave2成爲master1的從服務器
查看master1服務器binlong日誌使用節點信息:
- [root@master1 ~]# mysql -uroot -ppwd123
- .. ..
- mysql> show master status\G
- *************************** 1. row ***************************
- File: master1-bin.000001
- Position: 120
- Binlog_Do_DB:
- Binlog_Ignore_DB:
- Executed_Gtid_Set:
- 1 row in set (0.00 sec)
- mysql>
設置master2爲master1從:
- [root@master2 ~]# mysql -uroot -ppwd123
- .. ..
- mysql> change master to //設置主服務器信息
- -> master_host="192.168.4.10", //設置主服務器IP地址
- -> master_user="slaveuser", //設置主從同步用戶
- -> master_password="pwd123", //設置主從同步密碼
- -> master_log_file="master1-bin.000001", //設置主庫binlog日誌名稱
- -> master_log_pos=120; //設置主從binlog日誌使用節點
- Query OK, 0 rows affected, 2 warnings (0.06 sec)
- mysql> start slave; //啓動同步進程
- Query OK, 0 rows affected (0.00 sec)
- mysql> show slave status\G //查看主從是否成功
- .. ..
啓動同步進程後查看IO節點和SQL節點是否爲Yes若是均爲Yes表示主從正常。
- Slave_IO_Running: Yes //IO節點正常
- Slave_SQL_Running: Yes //SQL節點正常
- .. ..
- mysql>
設置slave1爲master1從:
- [root@slave1 ~]# mysql -uroot -ppwd123
- .. ..
- mysql> change master to
- -> master_host="192.168.4.10",
- -> master_user="slaveuser",
- -> master_password="pwd123",
- -> master_log_file="master1-bin.000001",
- -> master_log_pos=120;
- Query OK, 0 rows affected, 2 warnings (0.12 sec)
- mysql> start slave;
- Query OK, 0 rows affected (0.16 sec)
- mysql> show slave status\G
- .. ..
- Slave_IO_Running: Yes //IO節點正常
- Slave_SQL_Running: Yes //SQL節點正常
- .. ..
- mysql>
設置slave2爲master1從:
- [root@slave2 ~]# mysql -uroot -ppwd123
- .. ..
- mysql> change master to
- -> master_host="192.168.4.10",
- -> master_user="slaveuser",
- -> master_password="pwd123",
- -> master_log_file="master1-bin.000001",
- -> master_log_pos=120;
- Query OK, 0 rows affected, 2 warnings (0.13 sec)
- mysql> start slave;
- Query OK, 0 rows affected (0.27 sec)
- mysql> show slave status\G
- .. ..
- Slave_IO_Running: Yes //IO節點正常
- Slave_SQL_Running: Yes //SQL節點正常
- .. ..
- mysql>
5)配置主主從從關係,將master1配置爲master2的從
查看master2的binlog使用信息:
- [root@master2 ~]# mysql -uroot -ppwd123
- .. ..
- mysql> show master status\G
- *************************** 1. row ***************************
- File: master2-bin.000001
- Position: 120
- Binlog_Do_DB:
- Binlog_Ignore_DB:
- Executed_Gtid_Set:
- 1 row in set (0.00 sec)
- mysql>
設置master1成爲master2的從:
- [root@master1 ~]# mysql -uroot -ppwd123
- .. ..
- mysql> change master to
- -> master_host="192.168.4.11",
- -> master_user="slaveuser",
- -> master_password="pwd123",
- -> master_log_file="master2-bin.000001",
- -> master_log_pos=120;
- Query OK, 0 rows affected, 2 warnings (0.31 sec)
- mysql> start slave;
- Query OK, 0 rows affected (0.27 sec)
- mysql> show slave status\G
- .. ..
- Slave_IO_Running: Yes //IO節點正常
- Slave_SQL_Running: Yes //SQL節點正常
- .. ..
- mysql>
6)測試主從架構是否成功
master1更新數據,查看其它主機是否同步:
- [root@master1 ~]# mysql -uroot -ppwd123
- .. ..
- mysql> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | test |
- +--------------------+
- 4 rows in set (0.00 sec)
- mysql> create database tarena;
- Query OK, 1 row affected (0.06 sec)
- mysql> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | tarena |
- | test |
- +--------------------+
- 5 rows in set (0.00 sec)
- mysql>
master2主機查看:
- [root@master2 ~]# mysql -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 |
- +--------------------+
- [root@master2 ~]#
slave1主機查看:
- [root@slave1 ~]# mysql -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 |
- +--------------------+
- [root@slave1 ~]#
slave2主機查看:
- [root@slave2 ~]# mysql -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 |
- +--------------------+
- [root@slave2 ~]#
2 MySQL-MMM架構部署
2.1 問題
本案例要求熟悉實現MySQL-MMM的架構部署,主要包括如下任務:
- 安裝依賴包
- 安裝軟件包
- 配置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)均需安裝
- [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)安裝MySQL-MMM軟件依賴包(MySQL集羣內5臺服務器master1,master2,slave1,slave2,monitor)均需安裝,軟件包講師提供
安裝安裝Log-Log4perl 類
- [root@mysql-master1 ~]# rpm -ivh perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
- warning: perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY
- Preparing... ######################### [100%]
- 1:perl-Log-Log4perl ######################## [100%]
安裝Algorithm-Diff類
- [root@mysql-master1 ~]# tar -zxvf Algorithm-Diff-1.1902.tar.gz //解壓安裝包
- .. ..
- [root@mysql-master1 ~]# cd Algorithm-Diff-1.1902 //切換到安裝目錄
- [root@mysql-master1 Algorithm-Diff-1.1902]# perl Makefile.PL //生成makefile文件
- Checking if your kit is complete...
- Looks good
- Writing Makefile for Algorithm::Diff
- [root@mysql-master1 Algorithm-Diff-1.1902]# make && make install //編譯,編譯安裝
- .. ..
- [root@mysql-master1 Algorithm-Diff-1.1902]# cd //切換到軟件包目錄
- [root@mysql-master1 ~]#
安裝Proc-Daemon類
- [root@mysql-master1 ~]# tar -zxvf Proc-Daemon-0.03.tar.gz //解壓安裝包
- .. ..
- [root@mysql-master1 ~]# cd Proc-Daemon-0.03 //切換到安裝目錄
- [root@mysql-master1 Proc-Daemon-0.03]# perl Makefile.PL //生成makefile文件
- Checking if your kit is complete...
- Looks good
- Writing Makefile for Proc::Daemon
- [root@mysql-master1 Proc-Daemon-0.03]# make && make install //編譯,編譯安裝
- .. ..
- [root@mysql-master1 Proc-Daemon-0.03]# cd //切換到軟件包目錄
- [root@mysql-master1 ~]#
安裝Net-ARP虛擬IP分配工具:
- [root@mysql-master1 ~]# gunzip Net-ARP-1.0.8.tgz //使用gunzip解壓tgz格式的安裝包
- [root@mysql-master1 ~]# tar xvf Net-ARP-1.0.8.tar //解壓tar安裝包
- .. ..
- [root@mysql-master1 ~]# cd Net-ARP-1.0.8 //切換到安裝目錄
- [root@mysql-master1 Net-ARP-1.0.8]# perl Makefile.PL //生成makefile文件
- Module Net::Pcap is required for make test!
- Checking if your kit is complete...
- Looks good
- Writing Makefile for Net::ARP
- [root@mysql-master1 Net-ARP-1.0.8]# make && make install //編譯,編譯安裝
- .. ..
- [root@mysql-master1 Net-ARP-1.0.8]# cd //切換到軟件包目錄
- [root@mysql-master1 ~]#
安裝Mysql-MMM軟件包:
- [root@mysql-master1 ~]# tar xvf mysql-mmm-2.2.1.tar.gz //解壓安裝包
- .. ..
- [root@mysql-master1 ~]# cd mysql-mmm-2.2.1 //切換到安裝目錄
- [root@mysql-master1 mysql-mmm-2.2.1]# make && make install //編譯,編譯安裝
- .. ..
- [root@mysql-master1 mysql-mmm-2.2.1]#
步驟二:修改配置文件
1)修改公共配置文件
本案例中MySQL集羣的5臺服務器(master一、master二、slave一、slave二、monitor)都須要配置,能夠先配好一臺後使用scp複製。
- [root@master1 ~]# 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>
- [root@master1 ~]#
2)修改管理主機配置文件(monitor主機配置)
- [root@monitor ~]# 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
- [root@monitor ~]#
3)修改客戶端配置文件
master1配置
- [root@master1 ~]# cat /etc/mysql-mmm/mmm_agent.conf
- include mmm_common.conf
- this master1
master2配置
- [root@master2 ~]# cat /etc/mysql-mmm/mmm_agent.conf
- include mmm_common.conf
- this master2
slave1配置
- [root@slave1 ~]# cat /etc/mysql-mmm/mmm_agent.conf
- include mmm_common.conf
- this slave1
slave2配置
- [root@slave2 ~]# cat /etc/mysql-mmm/mmm_agent.conf
- include mmm_common.conf
- 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操做:
- [root@master1 ~]# /etc/init.d/mysql-mmm-agent start
- Daemon bin: '/usr/sbin/mmm_agentd'
- Daemon pid: '/var/run/mmm_agentd.pid'
- Starting MMM Agent daemon... Ok
master2操做:
- [root@master2 ~]# /etc/init.d/mysql-mmm-agent start
- Daemon bin: '/usr/sbin/mmm_agentd'
- Daemon pid: '/var/run/mmm_agentd.pid'
- Starting MMM Agent daemon... Ok
slave1操做:
- [root@master2 ~]# /etc/init.d/mysql-mmm-agent start
- Daemon bin: '/usr/sbin/mmm_agentd'
- Daemon pid: '/var/run/mmm_agentd.pid'
- Starting MMM Agent daemon... Ok
slave2操做:
- [root@slave2 ~]# /etc/init.d/mysql-mmm-agent start
- Daemon bin: '/usr/sbin/mmm_agentd'
- Daemon pid: '/var/run/mmm_agentd.pid'
- Starting MMM Agent daemon... Ok
2)啓動mmm-monitor進程
monitor主機操做:
- [root@monitor ~]# /etc/init.d/mysql-mmm-monitor start
- Daemon bin: '/usr/sbin/mmm_mond'
- Daemon pid: '/var/run/mmm_mond.pid'
- Starting MMM Monitor daemon: Ok
步驟二:設置集羣中服務器爲online狀態
控制命令只能在管理端monitor服務器上執行。
查看當前集羣中各服務器狀態:
- [root@monitor ~]# mmm_control show
- master1(192.168.4.10) master/AWAITING_RECOVERY. Roles:
- master2(192.168.4.11) master/AWAITING_RECOVERY. Roles:
- slave1(192.168.4.12) slave/AWAITING_RECOVERY. Roles:
- slave2(192.168.4.13) slave/AWAITING_RECOVERY. Roles:
設置4臺數據庫主機狀態爲online:
- [root@monitor ~]# mmm_control set_online master1
- OK: State of 'master1' changed to ONLINE. Now you can wait some time and check its new roles!
- [root@monitor ~]# mmm_control set_online master2
- OK: State of 'master2' changed to ONLINE. Now you can wait some time and check its new roles!
- [root@monitor ~]# mmm_control set_online slave1
- OK: State of 'slave1' changed to ONLINE. Now you can wait some time and check its new roles!
- [root@monitor ~]# mmm_control set_online slave2
- OK: State of 'slave2' changed to ONLINE. Now you can wait some time and check its new roles!
- [root@monitor ~]#
再次查看當前集羣中各服務器狀態:
- [root@monitor ~]# 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)
- [root@monitor ~]#
步驟三:測試MySQL-MMM架構
1)客戶機安裝MySQL-client軟件包
- [root@client ~]# tar xvf MySQL-5.6.15-1.el6.x86_64.rpm-bundle.tar
- .. ..
- [root@client ~]# rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm
- .. ..
2)MySQL-MMM虛擬IP訪問測試
- [root@client ~]# 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 |
- +--------------------+
- [root@client ~]#
- [root@client ~]# 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 |
- +--------------------+
- [root@client ~]#
- [root@client ~]# 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 |
- +--------------------+
- [root@client ~]#
3)主數據庫宕機測試
- [root@master1 ~]# service mysql stop //中止master1上服務
- Shutting down MySQL.... [肯定]
- [root@master1 ~]#
- [root@monitor ~]# 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)
- [root@monitor ~]#
- [root@client ~]# 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 |
- +--------------------+
- [root@client ~]#