集群:DRBD+corosync+pacemaker实现MySQL服务高可用(6)

4,配置资源的各种约束:
集群拥有所有必需资源,但它可能还无法进行正确处理。资源约束则用以指定在哪些群集节点上运行资源,以何种顺序装载资源,以及特定资源依赖于哪些其它资源。pacemaker共给我们提供了三种资源约束方法:
1)Resource Location(资源位置):定义资源可以、不可以或尽可能在哪些节点上运行
2)Resource Collocation(资源排列):排列约束用以定义集群资源可以或不可以在某个节点上同时运行
3)Resource Order(资源顺序):顺序约束定义集群资源在节点上启动的顺序
 
定义约束时,还需要指定分数。各种分数是集群工作方式的重要组成部分。其实,从迁移资源到决定在已降级集群中停止哪些资源的整个过程是通过以某种方式修改分数来实现的。分数按每个资源来计算,资源分数为负的任何节点都无法运行该资源。在计算出资源分数后,集群选择分数最高的节点。INFINITY(无穷大)目前定义为 1,000,000。加减无穷大遵循以下3个基本规则:
1)任何值 + 无穷大 = 无穷大
2)任何值 - 无穷大 = -无穷大
3)无穷大 - 无穷大 = -无穷大
 
定义资源约束时,也可以指定每个约束的分数。分数表示指派给此资源约束的值。分数较高的约束先应用,分数较低的约束后应用。通过使用不同的分数为既定资源创建更多位置约束,可以指定资源要故障转移至的目标节点的顺序。
 
我们要定义如下的约束:
# crm
crm(live)# configure
crm(live)configure# colocation MySQLFS_with_mysqldrbd inf: MysqlFS MS_mysqldrbd:Master myip mysqlserver
crm(live)configure# order MysqlFS_after_mysqldrbd inf: MS_mysqldrbd:promote MysqlFS:start
crm(live)configure# order myip_after_MysqlFS mandatory: MysqlFS myip
crm(live)configure# order mysqlserver_after_myip  mandatory: myip mysqlserver
验证是否有错:
crm(live)configure# verify
提交:
crm(live)configure# commit
crm(live)configure# exit
 
查看配置信息:
# crm configure show
node node1.magedu.com \
attributes standby="off"
node node2.magedu.com \
attributes standby="off"
primitive MysqlFS ocf:heartbeat:Filesystem \
params device="/dev/drbd0" directory="/mydata" fstype="ext3" \
op start interval="0" timeout="60s" \
op stop interval="0" timeout="60s"
primitive myip ocf:heartbeat:IPaddr \
params ip="172.16.30.1"
primitive mysqldrbd ocf:heartbeat:drbd \
params drbd_resource="mysql" \
op monitor interval="30s" role="Master" \
op monitor interval="31s" role="Slave" \
op start interval="0" timeout="240s" \
op stop interval="0" timeout="100s"
primitive mysqlserver lsb:mysqld
ms MS_mysqldrbd mysqldrbd \
meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
colocation MysqlFS_with_mysqldrbd inf: MysqlFS MS_mysqldrbd:Master myip mysqlserver
order MysqlFS_after_mysqldrbd inf: MS_mysqldrbd:promote MysqlFS:start
order myip_after_MysqlFS inf: MysqlFS myip
order mysqlserver_after_myip inf: myip mysqlserver
property $id="cib-bootstrap-options" \
dc-version="1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false" \
no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
resource-stickiness="100"
 
查看运行状态:
# crm status
============
Last updated: Sat Apr 21 02:05:49 2012
Stack: openais
Current DC: node1.magedu.com - partition with quorum
Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87
2 Nodes configured, 2 expected votes
4 Resources configured.
============
 
Online: [ node1.magedu.com node2.magedu.com ]
 
 Master/Slave Set: MS_mysqldrbd
     Masters: [ node1.magedu.com ]
     Slaves: [ node2.magedu.com ]
 MysqlFS (ocf::heartbeat:Filesystem): Started node1.magedu.com
 myip (ocf::heartbeat:IPaddr): Started node1.magedu.com
 mysqlserver (lsb:mysqld): Started node1.magedu.com
 
可见,服务现在在node1上正常运行:
在node1上的操作,查看mysql的运行状态:
# service mysqld status
MySQL running (25651)                                      [  OK  ]
查看目录:
# ls /mydata/
data  lost+found
 
 
继续测试:
在node1上操作,让node1下线:
# crm node standby
查看集群运行的状态:
# crm status
============
Last updated: Sat Apr 21 02:07:40 2012
Stack: openais
Current DC: node1.magedu.com - partition with quorum
Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87
2 Nodes configured, 2 expected votes
4 Resources configured.
============
 
Node node1.magedu.com: standby
Online: [ node2.magedu.com ]
 
 Master/Slave Set: MS_mysqldrbd
     Masters: [ node2.magedu.com ]
     Stopped: [ mysqldrbd:1 ]
 MysqlFS (ocf::heartbeat:Filesystem): Started node2.magedu.com
 myip (ocf::heartbeat:IPaddr): Started node2.magedu.com
 mysqlserver (lsb:mysqld): Started node2.magedu.com
 
可见我们的资源已经都切换到了node2上:
查看node2的运行状态:
# service mysqld status
MySQL running (7585)                                       [  OK  ]
查看目录:
# ls /mydata
data  lost+found
 
ok,现在一切正常,我们可以验证mysql服务是否能被正常访问:
我们定义的是通过VIP:172.16.30.1来访问mysql服务,现在node2上建立一个可以让某个网段主机能访问的账户(这个内容会同步drbd设备同步到node1上):
mysql> grant all on *.* to jia@'172.16.%.%' identified by '123456';
Query OK, 0 rows affected (0.08 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
然后我们通过另一台主机进行访问:
# mysql -ujia -h172.16.30.1 -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.20-log MySQL Community Server (GPL)
 
Copyright (c) 2000, 2011, 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>
 
显示我们的登陆完全正常,那么我们的实验就大功告成!
注:我们可以让node2下线,node1上线资源自动转移到node1上,然后再用一台mysql客户端使用jia这个账号来访问mysql服务器,同样也能访问,这就是我们drbd设备的作用,实现了写操作的高可用!而corosync+pacemaker的安装,实现了mysql服务的健康状态监测,实现mysql服务的高可用性!

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/709138dbd9e2d012447a43387685b28f.html