六、验证服务运行是否正常
1、在NOD1节点上查看是否已经运行MySQLd服务及配置好虚拟IP地址和文件系统
[root@nod1 ~]# netstat -anpt|grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 22564/mysqld
[root@nod1 ~]# mount | grep drbd0
/dev/drbd0 on /mydata type ext4 (rw)
[root@nod1 ~]# ifconfig eth0:0
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:3D:3F:44
inet addr:172.16.14.10 Bcast:172.16.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
2、登录数据库并创建数据库用于验证
[root@nod1 ~]# mysql
mysql> create database allen;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| allen |
| mysql |
| performance_schema |
| test |
+--------------------+
3、模拟主节点出现故障,将主节点设置为"Standby"状态,查看服务是否转移到备用节点上;当前主节点为:nod1.allen.com 备用节点:nod2.allen.com
[root@nod1 ~]# crm node standby nod1.allen.com
[root@nod1 ~]# crm status
Last updated: Thu Sep 19 22:23:50 2013
Last change: Thu Sep 19 22:23:42 2013 via crm_attribute on nod2.allen.com
Stack: classic openais (with plugin)
Current DC: nod1.allen.com - partition with quorum
Version: 1.1.8-7.el6-394e906
2 Nodes configured, 2 expected votes
5 Resources configured.
Node nod1.allen.com: standby
Online: [ nod2.allen.com ]
Master/Slave Set: My_Drbd [Drbd]
Masters: [ nod2.allen.com ]
Stopped: [ Drbd:1 ]
MyVip (ocf::heartbeat:IPaddr): Started nod2.allen.com
Mysqld (lsb:mysqld): Started nod2.allen.com
FileSys (ocf::heartbeat:Filesystem): Started nod2.allen.com
----------------------------------------------------------------------
######由上可见,所有服务已经切换到NOD2节点服务器上面
4、在NOD2节点上登录Mysql验证是否有"allen"数据库
[root@nod2 ~]# mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| allen |
| mysql |
| performance_schema |
| test |
+--------------------+
5、假如NOD1已修复好重新上线;这时NOD2节点上的服务是不会重新切换回NOD1节点上面的;如果想让切换也不是不可以,这需要设置资源粘性;但建议不要切换,避免服务切换时浪费不必要的资源
[root@nod1 ~]# crm node online nod1.allen.com
[root@nod1 ~]# crm status
Last updated: Thu Sep 19 22:34:55 2013
Last change: Thu Sep 19 22:34:51 2013 via crm_attribute on nod1.allen.com
Stack: classic openais (with plugin)
Current DC: nod1.allen.com - partition with quorum
Version: 1.1.8-7.el6-394e906
2 Nodes configured, 2 expected votes
5 Resources configured.
Online: [ nod1.allen.com nod2.allen.com ]
Master/Slave Set: My_Drbd [Drbd]
Masters: [ nod2.allen.com ]
Slaves: [ nod1.allen.com ]
MyVip (ocf::heartbeat:IPaddr): Started nod2.allen.com
Mysqld (lsb:mysqld): Started nod2.allen.com
FileSys (ocf::heartbeat:Filesystem): Started nod2.allen.com
6、设置资源粘性命令;这里就不在做测试了,如果各位博友有兴趣可以测试一下
crm configure rsc_defaults resource-stickiness=100
由上可见,所有服务都可以正常工作;到这里Mysql高可用已全部完成,而且还验证了Mysql服务的正常运行与数据;在这里感谢广大博友的关注与支持,我会继续努力的!!! 加油 加油 加油