DRBD+Corosync+Pacemaker实现MySQL服务器的高可用性群集(6)

5,配置资源的各种约束:

集群拥有所有必需资源,但它可能还无法进行正确处理。资源约束则用以指定在哪些群集节点上运行资源,以何种顺序装载资源,以及特定资源依赖于哪些其它资源。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.linuxidc.com \

attributes standby="off"

node node2.linuxidc.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="192.168.2.100"

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.88181.com - partition with quorum

Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87

2 Nodes configured, 2 expected votes

4 Resources configured.

============

Online: [ node1.88181.com node2.88181.com ]

Master/Slave Set: MS_mysqldrbd

Masters: [ node1.linuxidc.com ]

Slaves: [ node2.linuxidc.com ]

MysqlFS

(ocf::heartbeat:Filesystem): Started node1.linuxidc.com

myip

(ocf::heartbeat:IPaddr): Started node1.linuxidc.com

mysqlserver

(lsb:mysqld):

Started node1.linuxidc.com

可见,服务现在在node1上正常运行:

在node1上的操作,查看mysql的运行状态:

# service mysqld status

MySQL running (5345)                                      [  OK  ]

查看是否自动挂载

[root@node1 corosync]# mount

/dev/hdc on /media/RHEL_5.4 i386 DVD type iso9660 (ro,noexec,nosuid,nodev,uid=0)

/dev/hdc on /mnt/cdrom type iso9660 (ro)

/dev/drbd0 on /mysqldata type ext3 (rw)

查看目录:

# ls /mysqldata/

data  lost+found

查看vip的状态

[root@node1 corosync]# ifconfig

eth0 Link encap:Ethernet HWaddr 00:0C:29:13:51:ED

inet addr:192.168.2.10 Bcast:192.168.2.255 Mask:255.255.255.0

eth0:0 Link encap:Ethernet HWaddr 00:0C:29:13:51:ED

inet addr:192.168.2.100 Bcast:192.168.2.255 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

Interrupt:67 Base address:0x2000

继续测试:

在node1上操作,让node1下线:

# crm node standby

查看集群运行的状态:

# crm status

============

Last updated: Sat Apr 21 02:07:40 2012

Stack: openais

Current DC: node1.linuxidc.com - partition with quorum

Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87

2 Nodes configured, 2 expected votes

4 Resources configured.

============

Node node1.linuxidc.com: standby

Online: [ node2.linuxidc.com ]

Master/Slave Set: MS_mysqldrbd

Masters: [ node2.linuxidc.com ]

Stopped: [ mysqldrbd:1 ]

MysqlFS

(ocf::heartbeat:Filesystem): Started node2.linuxidc.com

myip

(ocf::heartbeat:IPaddr): Started node2.linuxidc.com

mysqlserver

(lsb:mysqld):

Started node2.linuxidc.com

可见我们的资源已经都切换到了node2上:

查看node2的运行状态:

# service mysqld status

MySQL running (7585)                                       [  OK  ]

查看目录:

# ls /mysqldata

data  lost+found

ok,现在一切正常,我们可以验证mysql服务是否能被正常访问:

我们定义的是通过VIP:192.168.2.100来访问mysql服务,现在node2上建立一个可以让某个网段主机能访问的账户(这个内容会同步drbd设备同步到node1上):

mysql> grant all on *.* to test@'192.168.%.%' identified by '123456';

Query OK, 0 rows affected (0.08 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

然后我们通过另一台主机进行访问:

# mysql –u test –h 192.168.2.100 -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>

说明:这样我们的mysql的高可用性的群集就实现成功啦。实验中遇到啦一些小问题,但是历时一天的时间最终还是解决啦。

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

转载注明出处:http://www.heiqu.com/8b6c538d0c48b67533fce40236229b65.html