MySQL+Corosync+Pacemaker+DRBD构建高可用MySQL(3)

五、配置资源
1、Corosync默认启用了Stonith,而当前集群并没有相应的Stonith,会出现以下错误;需要禁用Stonith
[root@nod1 ~]# crm_verify -L -V
  error: unpack_resources:    Resource start-up disabled since no STONITH resources have been defined
  error: unpack_resources:    Either configure some or disable STONITH with the stonith-enabled option
  error: unpack_resources:    NOTE: Clusters with shared data need STONITH to ensure data integrity
Errors found during check: config not valid
  -V may provide more details

######禁用Stonith并查看
[root@nod1 ~]# crm configure property stonith-enabled=false
[root@nod1 ~]# crm configure show
node nod1.allen.com
node nod2.allen.com
property $id="cib-bootstrap-options" \
    dc-version="1.1.8-7.el6-394e906" \
    cluster-infrastructure="classic openais (with plugin)" \
    expected-quorum-votes="2" \
    stonith-enabled="false"

2、查看当前的集群系统支持的类型

[root@nod1 ~]# crm ra classes
lsb
ocf / heartbeat linbit pacemaker RedHat
service
stonith
注释:linbit 资源类型只有安装DRBD服务才会有

3、如何查看某种类型下所用可用的资源代理列表?
crm ra list lsb
crm ra list ocf heartbeat
crm ra list ocf pacemaker
crm ra list stonith
crm ra list ocf linbit

4、配置VIP资源与MySQLd资源

[root@nod1 ~]# crm        #进入crm交互模式
crm(live)# configure
crm(live)configure# property no-quorum-policy="ignore"
crm(live)configure# primitive MyVip ocf:heartbeat:IPaddr params ip="172.16.14.10"    #定义虚拟IP资源
crm(live)configure# primitive Mysqld lsb:mysqld #定义Mysql服务资源
crm(live)configure# verify    #检查语法错误
crm(live)configure# commit    #提交
crm(live)configure# show      #查看配置
node nod1.allen.com
node nod2.allen.com
primitive MyVip ocf:heartbeat:IPaddr \
    params ip="172.16.14.10"
primitive Mysqld lsb:mysqld
property $id="cib-bootstrap-options" \
    dc-version="1.1.8-7.el6-394e906" \
    cluster-infrastructure="classic openais (with plugin)" \
    expected-quorum-votes="2" \
    stonith-enabled="false" \
    no-quorum-policy="ignore"

5、配置DRBD主从资源
crm(live)configure# primitive Drbd ocf:linbit:drbd params drbd_resource="drbd" op monitor interval=10s role="Master" op monitor interval=20s role="Slave" op start timeout=240s op stop timeout=100
crm(live)configure# master My_Drbd Drbd meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show Drbd
primitive Drbd ocf:linbit:drbd \
    params drbd_resource="drbd" \
    op monitor interval="10s" role="Master" \
    op monitor interval="20s" role="Slave" \
    op start timeout="240s" interval="0" \
    op stop timeout="100s" interval="0"
crm(live)configure# show My_Drbd
ms My_Drbd Drbd \
    meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"

6、定义一个文件系统资源
crm(live)configure# primitive FileSys ocf:heartbeat:Filesystem params device="/dev/drbd0" directory="/mydata" fstype="ext4" op start timeout="60s" op stop timeout="60s"
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# show FileSys
primitive FileSys ocf:heartbeat:Filesystem \
    params device="/dev/drbd0" directory="/mydata" fstype="ext4" \
    op start timeout="60s" interval="0" \
    op stop timeout="60s" interval="0"

7、定将资源之间的位置和启动顺序约束

crm(live)configure# colocation FileSys_on_My_Drbd inf: FileSys My_Drbd:Master #让文件系统与DRBD主节点运行在一起
crm(live)configure# order FileSys_after_My_Drbd inf: My_Drbd:promote FileSys:start  #让DRBD服务比文件系统先启动
crm(live)configure# verify
crm(live)configure# colocation Mysqld_on_FileSys inf: Mysqld FileSys #让Mysql服务与文件系统运行在一起
crm(live)configure# order Mysqld_after_FileSys inf: FileSys Mysqld:start #让文件系统比Mysql服务先运行
crm(live)configure# verify
crm(live)configure# colocation MyVip_on_Mysqld inf: MyVip Mysqld #让虚拟IP与Mysql服务运行在一起
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# bye #断开crm交互连接

8、查看服务状态如下:
[root@nod1 ~]# crm status
Last updated: Thu Sep 19 21:18:20 2013
Last change: Thu Sep 19 21:18:06 2013 via crmd on nod1.allen.com
Stack: classic openais (with plugin)
Current DC: nod2.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 ]
 FileSys    (ocf::heartbeat:Filesystem):    Started nod2.allen.com
Failed actions:
    Mysqld_start_0 (node=nod1.allen.com, call=60, rc=1, status=Timed Out): unknown error
    MyVip_start_0 (node=nod2.allen.com, call=47, rc=1, status=complete): unknown error
    Mysqld_start_0 (node=nod2.allen.com, call=13, rc=1, status=complete): unknown error
    FileSys_start_0 (node=nod2.allen.com, call=39, rc=1, status=complete): unknown error
注释:出现以上错误是因为我们在定义资源提交时,期间会检测服务是否运行;如果没有运行可能会尝试启动,而资源还没有完全定义好,所以会报错误;执行如下命令清除错误即可
[root@nod1 ~]# crm resource cleanup Mysqld
[root@nod1 ~]# crm resource cleanup MyVip
[root@nod1 ~]# crm resource cleanup FileSys

9、在上一步清除完错误后再次查看:
[root@nod1 ~]# crm status
Last updated: Thu Sep 19 21:26:49 2013
Last change: Thu Sep 19 21:19:35 2013 via crmd on nod2.allen.com
Stack: classic openais (with plugin)
Current DC: nod2.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: [ nod1.allen.com ]
    Slaves: [ nod2.allen.com ]
 MyVip  (ocf::heartbeat:IPaddr):    Started nod1.allen.com
 Mysqld (lsb:mysqld):  Started nod1.allen.com
 FileSys    (ocf::heartbeat:Filesystem):    Started nod1.allen.com
======================================================================
注释:由上可见,DRBD_Master、MyVip、Mysqld、FileSys都运行在NOD1节点上,也已经正常运行

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

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