Red Hat Training
A Red Hat training course is available for Red Hat Enterprise Linux
3.5. 配置叢集資源
本部分提供了為此使用案例配置叢集資源的程序。
注意
建議當您透過
pcs resource create
建立叢集資源後,馬上執行 pcs status
指令以驗證資源是否有在運作。請注意,若您尚未為您的叢集配置隔離裝置(如〈節 1.3, “隔離配置”〉中所述),就預設值資源將不會啟用。
若您發現您配置的資源沒有在運作,您可執行
pcs resource debug-start 資源
指令來測試資源配置。這將會啟用叢集控制之外的服務。在這時已配置的資源會再次運作,請執行 pcs cluster cleanup resource
以使叢集偵測到更新。欲取得有關於 pcs resource debug-start
指令上的相關資訊,請參閱《High Availability Add-On 參照》指南。
下列程序將會配置系統資源。為了確保這些資源全部皆會在相同節點上執行,它們將被配置為
nfsgroup
資源群組的一部分。資源將會以您將其新增至該群組中的順序開始,並且將會以反向的順序停止。請只在叢集的一個節點上執行這項程序。
- 下列指令會建立名為
my_lvm
的 LVM 資源。這項指令將指定exclusive=true
參數以確保只有叢集能夠啟用 LVM 邏輯卷冊。因為資源群組nfsgroup
尚未存在,這項指令將會建立資源群組。[root@z1 ~]#
pcs resource create my_lvm LVM volgrpname=my_vg
\exclusive=true --group nfsgroup
檢查叢集的狀態以驗證資源是否有在執行。root@z1 ~]#
pcs status
Cluster name: my_cluster Last updated: Thu Jan 8 11:13:17 2015 Last change: Thu Jan 8 11:13:08 2015 Stack: corosync Current DC: z2.example.com (2) - partition with quorum Version: 1.1.12-a14efad 2 Nodes configured 3 Resources configured Online: [ z1.example.com z2.example.com ] Full list of resources: myapc (stonith:fence_apc_snmp): Started z1.example.com Resource Group: nfsgroup my_lvm (ocf::heartbeat:LVM): Started z1.example.com PCSD Status: z1.example.com: Online z2.example.com: Online Daemon Status: corosync: active/enabled pacemaker: active/enabled pcsd: active/enabled - 為叢集配置一項
Filesystem
資源。注意
您可透過options=options
參數為Filesystem
資源指定掛載選項作為資源配置的一部分。欲取得完整配置選項請執行pcs resource describe Filesystem
指令。下列指令將配置一個名為nfsshare
的 ext4Filesystem
資源,作為nfsgroup
資源群組的一部分。此檔案系統使用了您在〈節 3.2, “為一個 LVM 卷冊配置 ext4 檔案系統”〉中建立的 LVM 卷冊群組和 ext4 檔案系統,並且將會被掛載至您在〈節 3.3, “NFS Share 設定”〉中所建立的/nfsshare
目錄上。[root@z1 ~]#
pcs resource create nfsshare Filesystem
\device=/dev/my_vg/my_lv directory=/nfsshare
\fstype=ext4 --group nfsgroup
驗證my_lvm
和nfsshare
資源是否有在執行。[root@z1 ~]#
pcs status
... Full list of resources: myapc (stonith:fence_apc_snmp): Started z1.example.com Resource Group: nfsgroup my_lvm (ocf::heartbeat:LVM): Started z1.example.com nfsshare (ocf::heartbeat:Filesystem): Started z1.example.com ... - 建立名為
nfs-daemon
的nfsserver
資源,作為nfsgroup
資源群組的一部分。[root@z1 ~]#
pcs resource create nfs-daemon nfsserver
\nfs_shared_infodir=/nfsshare/nfsinfo nfs_no_notify=true
\--group nfsgroup
[root@z1 ~]#pcs status
... - 新增
exportfs
資源以匯出/nfsshare/exports
目錄。這些資源為nfsgroup
資源群組的一部分。這會為 NFSv4 客戶端建立一個虛擬目錄。NFSv3 客戶端亦可存取這些匯出目錄。[root@z1 ~]#
pcs resource create nfs-root exportfs
\clientspec=192.168.122.0/255.255.255.0
\options=rw,sync,no_root_squash
\directory=/nfsshare/exports
\fsid=0 --group nfsgroup
[root@z1 ~]# #pcs resource create nfs-export1 exportfs
\clientspec=192.168.122.0/255.255.255.0
\options=rw,sync,no_root_squash directory=/nfsshare/exports/export1
\fsid=1 --group nfsgroup
[root@z1 ~]# #pcs resource create nfs-export2 exportfs
\clientspec=192.168.122.0/255.255.255.0
\options=rw,sync,no_root_squash directory=/nfsshare/exports/export2
\fsid=2 --group nfsgroup
- 加入 nfs 客戶端將會使用來存取 nfs share 的 IP 位址資源。您指定的浮動 IP 位址需要進行一項反向 DNS 查詢,否則它必須指定於叢集中所有節點上的
/etc/hosts
中。此資源為資源群組nfsgroup
的一部分。在此範例建置中,我們將使用 192.168.122.200 作為浮動 IP 位址。[root@z1 ~]#
pcs resource create nfs_ip IPaddr2
\ip=192.168.122.200 cidr_netmask=24 --group nfsgroup
- 當整個 NFS 建置初始化後,加入
nfsnotify
資源以傳送 NFSv3 重新啟動通知。注意
若要正確處理 NFS 通知,浮動 IP 位址必須有一組與其相聯的主機名稱,並且它在 nfs 伺服器與 nfs 客戶端上皆必須一致。[root@z1 ~]#
pcs resource create nfs-notify nfsnotify
\source_host=192.168.122.200
在建立了資源和資源限制後,您便可檢查叢集的狀態。請注意,所有資源皆在相同節點上運作。
[root@z1 ~]# pcs status
...
Full list of resources:
myapc (stonith:fence_apc_snmp): Started z1.example.com
Resource Group: nfsgroup
my_lvm (ocf::heartbeat:LVM): Started z1.example.com
nfsshare (ocf::heartbeat:Filesystem): Started z1.example.com
nfs-daemon (ocf::heartbeat:nfsserver): Started z1.example.com
nfs-root (ocf::heartbeat:exportfs): Started z1.example.com
nfs-export1 (ocf::heartbeat:exportfs): Started z1.example.com
nfs-export2 (ocf::heartbeat:exportfs): Started z1.example.com
nfs_ip (ocf::heartbeat:IPaddr2): Started z1.example.com
nfs-notify (ocf::heartbeat:nfsnotify): Started z1.example.com
...