案例應用:紅帽企業羣集和存儲管理之node
mysql服務器的HA集羣之corosync+drbd+pacemaker實現-下篇mysql
上篇地址:web
http://xjzhujunjie.blog.51cto.com/3582724/886317
接上篇!!!數據庫
5.1 配置羣集的工做屬性 bootstrap
[root@node1 ~]# crm configure property stonith-enabled=false服務器
[root@node2 ~]# crm configure property stonith-enabled=falsessh
[root@node1 ~]# crm configure property no-quorum-policy=ignoreide
[root@node2 ~]# crm configure property no-quorum-policy=ignoresqlserver
INFINITY:若是不是因節點不適合運行資源(節點關機、節點待機、達到migration-threshold 或配置更改)而強制資源轉移,資源老是留在當前位置。此選項的做用幾乎等同於徹底禁用自動故障回覆;
[root@node1 ~]# crm configure rsc_defaults resource-stickiness=100
[root@node2 ~]# crm configure rsc_defaults resource-stickiness=100
5.2 定義羣集服務及資源
5.2.1 改變drbd的狀態
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
0:mysql Connected Secondary/Secondary UpToDate/UpToDate C r----
0:mysql Connected Secondary/Secondary UpToDate/UpToDate C r----
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
5.2.2 配置drbd爲羣集資源
property $id="cib-bootstrap-options" \
dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false" \
2、將已經配置好的DRBD設備/dev/drbd0定義爲集羣服務;
[root@node1 ~]# ssh node2 'chkconfig drbd off'
3、配置drbd爲集羣資源:
drbd
4、查看drbd的資源代理的相關信息:
as a master/slave resource. DRBD is a shared-nothing replicated storage
Parameters (* denotes required, [] the default):
The name of the drbd resource from the drbd.conf file.
drbdconf (string, [/etc/drbd.conf]): Path to drbd.conf
Full path to the drbd.conf file.
start timeout=240
promote timeout=90
demote timeout=90
notify timeout=90
stop timeout=100
monitor_Slave interval=20 timeout=20 start-delay=1m
monitor_Master interval=10 timeout=20 start-delay=1m
5、drbd須要同時運行在兩個節點上,但只能有一個節點(primary/secondary模型)是Master,而另外一個節點爲Slave;所以,它是一種比較特殊的集羣資源,其資源類型爲多狀態(Multi-state)clone類型,即主機節點有Master和Slave之分,且要求服務剛啓動時兩個節點都處於slave狀態。
crm(live)configure# primitive mysqldrbd ocf:heartbeat:drbd params drbd_resource="mysql" op monitor role="Master" interval="30s" op monitor role="Slave" interval="31s" op start timeout="240s" op stop timeout="100s"
crm(live)configure# ms MS_mysqldrbd mysqldrbd meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify="true"
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"
meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
肯定無誤後,提交:
6、查看當前集羣運行狀態:
Current DC: node1.junjie.com - partition with quorum
Masters: [ node1.junjie.com ]
Slaves: [ node2.junjie.com ]
Primary/Secondary
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
crm(live)configure# primitive MysqlFS ocf:heartbeat:Filesystem params device="/dev/drbd0" directory="/mnt/mysqldata" fstype="ext3" op start timeout=60s op stop timeout=60s
params device="/dev/drbd0" directory="/mnt/mysqldata" fstype="ext3" \
op start interval="0" timeout="60s" \
op stop interval="0" timeout="60s"
7、mysql資源的定義(node1上操做)
[root@node1 ~]# crm configure primitive myip ocf:heartbeat:IPaddr params ip=192.168.101.88
[root@node1 ~]# crm configure primitive mysqlserver lsb:mysqld
Current DC: node1.junjie.com - partition with quorum
Masters: [ node1.junjie.com ]
Slaves: [ node2.junjie.com ]
8、配置資源的各類約束:
1)Resource Location(資源位置):定義資源能夠、不能夠或儘量在哪些節點上運行
2)Resource Collocation(資源排列):排列約束用以定義集羣資源能夠或不能夠在某個節點上同時運行
3)Resource Order(資源順序):順序約束定義集羣資源在節點上啓動的順序。
1)任何值 + 無窮大 = 無窮大
2)任何值 - 無窮大 = -無窮大
3)無窮大 - 無窮大 = -無窮大
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
colocation MysqlFS_with_mysqldrbd inf: MysqlFS MS_mysqldrbd:Master myip mysqlserver
order MysqlFS_after_mysqldrbd inf: MS_mysqldrbd:promote MysqlFS:start
order mysqlserver_after_myip inf: myip mysqlserver
9.查看配置信息和狀態,並測試:
params device="/dev/drbd0" directory="/mnt/mysqldata" fstype="ext3" \
op start interval="0" timeout="60s" \
op stop interval="0" timeout="60s"
params ip="192.168.101.88"
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"
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 mysqlserver_after_myip inf: myip mysqlserver
property $id="cib-bootstrap-options" \
dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false" \
Current DC: node1.junjie.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
Masters: [ node1.junjie.com ]
Slaves: [ node2.junjie.com ]
可見,服務如今在node1上正常運行:
在node1上的操做,查看羣集的運行狀態:
/dev/drbd0 on /mnt/mysqldata type ext3 (rw)
drwxr-xr-x 5 mysql mysql 4096 Feb 8 00:05 data
-rw-r--r-- 1 root root 4 Feb 7 21:28 f1
-rw-r--r-- 1 root root 0 Feb 7 21:28 f2
drwx------ 2 root root 16384 Feb 7 21:26 lost+found
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:AE:83:D1
inet addr:192.168.101.88 Bcast:192.168.101.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:67 Base address:0x2000
在node2上的操做,查看羣集的運行狀態:
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:D1:D4:32
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:67 Base address:0x2000
10.繼續測試羣集:
Current DC: node1.junjie.com - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
Node node1.junjie.com: standby
Stopped: [ mysqldrbd:0 ]
在node2上的操做,查看羣集的運行狀態:
可見咱們的資源已經都切換到了node2上:
/dev/drbd0 on /mnt/mysqldata type ext3 (rw)
drwxr-xr-x 5 mysql mysql 4096 Feb 8 00:16 data
-rw-r--r-- 1 root root 4 Feb 7 21:28 f1
-rw-r--r-- 1 root root 0 Feb 7 21:28 f2
drwx------ 2 root root 16384 Feb 7 21:26 lost+found
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:D1:D4:32
inet addr:192.168.101.88 Bcast:192.168.101.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:67 Base address:0x2000
mysql> grant all on *.* to user1@'192.168.%.%' identified by '123456';
客戶端訪問測試
192.168.101.100客戶Ping測試192.168.101.88
192.168.101.100客戶訪問mysql數據庫192.168.101.88(成功訪問)
至此:使用corosync+drbd+pacemaker實現mysql服務器的高可用集羣成功完成!.
《完》
--xjzhujunjie
--2012/06/03
上篇地址:
http://xjzhujunjie.blog.51cto.com/3582724/886317
接上篇!!!