Pacemaker的簡單架構

Pacemaker是一個集羣資源管理器。它利用你喜歡的集羣基礎構件(corosync)提供的消息和成員管理能力來探測並從節點或資源級別的故障中恢復,以實現羣集服務(亦稱資源)的最大可用性。

各服務器IP分配

192.168.2.36 (corosync pacemaker master)

192.168.2.46   (corosync pacemaker slave)

192.168.2.38    192.168.2.39   (realserver)  192.168.2.111 (浮動IP)

軟件包的安裝

crmsh-1.2.6-0.rc2.2.1.x86_64.rpm pssh-2.3.1-2.1.x86_64.rpm
然後yum localinstall * -y
做一下遠程鏈接無需驗證:ssh-keygen 全部摁回車
然後再用這個命令:ssh-copy-id desktop36.example.com 之後就不許要驗證密碼了 把.ssh scp到另一臺虛擬機上desktop46.example.com
#cd /etc/corosync/
#cp corosync.conf.example corosync.conf
然後編輯 #vim corosync.conf
bindnetaddr: 192.168.2.0(填本機ip網段)
mcastaddr: 226.94.1.97(這個隨便改)
mcastport: 3427(這個也是隨意)
service {
        name: pacemaker
        ver:  0

}
把這個文件scp到desktop46 保持一致
啓動 /etc/init.d/corosync start(兩邊都啓動)
用crm node show 看下兩邊節點是不是都起來了
然後再用crm_verify -LV驗證下有沒有錯誤,它會出現這個錯誤:
crm_verify[2195]: 2009/08/27_16:57:12
resources have been defined
crm_verify[2195]: 2009/08/27_16:57:12
the stonith-enabled option
crm_verify[2195]: 2009/08/27_16:57:12
ensure data integrity
Errors found during check: config not
#
ERROR: unpack_resources: Resource start-up disabled since no STONITH
ERROR: unpack_resources: Either configure some or disable STONITH with
ERROR: unpack_resources: NOTE: Clusters with shared data need STONITH to
valid -V may provide more details
目前,我們禁用這個特性,然後在 配置STONISH 章節來配置它。這裏要指出,使用STONITH是非常有必
要的。關閉這個特性就是告訴集羣:假裝故障的節點已經安全的關機了。一些供應商甚至不允許這個特
性被關閉。
我們將 stonith-enabled設置爲 false 來關閉STONITH
# crm configure property stonith-enabled=false
# crm_verify -L
設置完這個選項以後,校驗配置文件就正常了。
添加一個資源
首先要做的是配置一個IP地址,不管集羣服務在哪運行,我們要一個固定的地址來提供服務。在這裏我
選擇192.168.2.111作爲浮動IP,給它取一個好記的名字 VIP 並且告訴集羣 每30秒檢查它一

wKioL1PnCCqggSuiAADYYXblhuc296.jpg用crm_mon查看檢查下IP是不是已經添加上
wKioL1PnCJ6TgfnFAAKfCOVC6MY218.jpg

做節點失效備援:
關掉一個節點的corosync後,添加的那個IP資源不會在剩下的那個節點運行!
法定人數和雙節點集羣:
# crm configure property no-quorum-policy=ignore(當有半數以上的節點在線時,這個集羣就認爲自己擁有法定人數了,是“合法”的)
# crm configure show
node desktop36.example.com
node desktop46.example.com
primitive ClusterIP ocf:heartbeat:IPaddr2 \
params ip="192.168.2.111" cidr_netmask="32" \
op monitor interval="30s"
property $id="cib-bootstrap-options" \
dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false" \
no-quorum-policy="ignore"
然後用crm_mon檢查後發現集羣會在剩下的那個節點上啓動這個IP。然而集羣現在並沒有達到法定人數
現在模擬節點恢復,我們啓動 desktop36 上面的Corosync服務,然後檢查集羣狀態。
# /etc/init.d/corosync start
Starting Corosync Cluster Engine (corosync): [ OK ]
# /etc/init.d/pacemaker start
Starting Pacemaker Cluster Manager: [ OK ]# crm_mon
============
Last updated: Fri Aug 28 15:32:13 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ desktop36.example.com desktop46.example.com ]
ClusterIP
(ocf::heartbeat:IPaddr):
Started desktop36.example.com
現在我們可以看到讓某些人驚奇的事情,IP資源回到原來那個節點(pcmk-1)上去了。
添加httpd服務
在兩臺節點都安裝httpd
vim /etc/httpd/conf/httpd.conf
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Location>(大概在921行)
crm(live)configure# primitive website ocf:heartbeat:apache params configfile=/etc/httpd/conf/httpd.conf op monitor interval=30s
過一會兒就可以看到集羣把apache啓動了
wKioL1PnDx6ye8KLAAFOKT6xkZA415.jpg確保資源在同一個節點上運行:
crm(live)configure# colocation website-with-vip inf: website vip
wKioL1PnD1TDTt6uAAFOKT6xkZA362.jpg指定優先的Location:
crm(live)configure# location master-node website 10: desktop36.example.com
添加fence:(注意添加fence時間一定要同步,並且火牆和selinux都要disabled的)
在宿主機上dd if=/dev/urandom of=fence_xvm.key bs=128 count=1 生成fence_xvm.key這個key文件 然後把它複製到兩個節點上重啓fence(在兩個節點上創建這個/etc/cluster這個目錄) 然後啓動fence_virtd
crm(live)configure# property stonith-enabled=true
crm(live)configure# primitive vmfence stonith:fence_xvm params pcmk_host_map=desktop36.example.com:vm2;desktop46.example.com:vm3 op monitor interval=60s
然後用crm_mon 查看fence是否添加上
wKiom1PnDuuzfKH1AAGpqVW9pDA875.jpg做後測試用ifdown eth0 看這個機子會不會重啓!!!
添加文件存儲系統

192.168.2.184 (drbd)
lvcreate -L 2G -n iscsi lzh 然後啓動iscsi /etc/init.d/iscsi start
iscsiadm -m discovery -t st -p 192.168.2.183 導入 iscsiadm -m node -l 登錄
fdisk /dev/sda
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa42947a5.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1009, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1009, default 1009):
Using default value 1009

Command (m for help): p

Disk /dev/sda: 2147 MB, 2147483648 bytes
67 heads, 62 sectors/track, 1009 cylinders
Units = cylinders of 4154 * 512 = 2126848 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa42947a5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1        1009     2095662   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
然後格式化mkfs.ext4 在另個節點partprobe同步
在crm命令行添加文件系統資源crm(live)configure# primitive webdata ocf:heartbeat:Filesystem params device=/dev/sda1 directory=/var/www/html fstype=ext4 op monitor interval=30s
指定資源的啓動順序:crm(live)configure# order webdata-after-website inf: webdata website
把這幾個資源放在一個組:crm(live)configure# group webgrp vip webdata website
然後用crm_mon查看!!ok!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章