Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

2.4. 透過 pcs 指令來建立資源和資源群組

這個使用案例需要您建立四個叢集資源。為了確保這些資源皆執行於相同節點上,它們將配置為資源群組 apachegroup 的一部分。需建立的資源如下,以它們啟用的順序列出。
  1. 一項名為 my_lvmLVM 資源,它使用了您在〈節 2.1, “為一個 LVM 卷冊配置 ext4 檔案系統”〉中所建立的 LVM 卷冊群組。
  2. 一項名為 my_fsFilesystem 資源,它使用了您在〈節 2.1, “為一個 LVM 卷冊配置 ext4 檔案系統”〉中所建立的檔案系統裝置 /dev/my_vg/my_lv
  3. 一項 IPaddr2 資源,它乃 apachegroup 資源群組的浮動 IP 位址。IP 位址必須是一組不與實體節點相聯的位址。若 IPaddr2 資源的 NIC 裝置未指定,浮動 IP 便必須駐存在與叢集節點所使用的靜態指定之 IP 位址相同的網路上,否則將無法正常偵測欲為其分配浮動 IP 位址的 NIC 裝置。
  4. 一項名為 Websiteapache 資源,它使用了 index.html 檔案以及您在〈節 2.2, “網站伺服器配置”〉中定義的 Apache 配置。
下列程序將建立資源群組 apachegroup 以及該群組包含的資源。資源將會以您將其新增至該群組中的順序開始,並且將會以反向的順序停止。請只在叢集的一個節點上執行這項程序。
  1. 下列指令會建立 LVM 資源 my_lvm。這項指令將指定 exclusive=true 參數以確保只有叢集能夠啟用 LVM 邏輯卷冊。因為資源群組 apachegroup 尚未存在,這項指令將會建立資源群組。
    [root@z1 ~]# pcs resource create my_lvm LVM volgrpname=my_vg \
    exclusive=true --group apachegroup
    當您建立資源時,資源會自動啟用。您可使用以下指令來確認資源是否已建立並已啟用。
    # pcs resource show
     Resource Group: apachegroup
         my_lvm	(ocf::heartbeat:LVM):	Started
    您可透過 pcs resource disablepcs resource enable 指令來手動停用和啟用一項資源。
  2. 下列指令會為配置建立剩餘的資源,並將它們加入到既有的資源群組 apachegroup 中。
    [root@z1 ~]# pcs resource create my_fs Filesystem \
    device="/dev/my_vg/my_lv" directory="/var/www" fstype="ext4" --group \
    apachegroup
    
    [root@z1 ~]# pcs resource create VirtualIP IPaddr2 ip=198.51.100.3 \
    cidr_netmask=24 --group apachegroup
    
    [root@z1 ~]# pcs resource create Website apache \
    configfile="/etc/httpd/conf/httpd.conf" \
    statusurl="http://127.0.0.1/server-status" --group apachegroup
  3. 在建立了資源以及包含這些資源的資源群組後,您可檢查叢集的狀態。請注意所有這四項資源皆在相同的節點上執行。
    [root@z1 ~]# pcs status
    Cluster name: my_cluster
    Last updated: Wed Jul 31 16:38:51 2013
    Last change: Wed Jul 31 16:42:14 2013 via crm_attribute on z1.example.com
    Stack: corosync
    Current DC: z2.example.com (2) - partition with quorum
    Version: 1.1.10-5.el7-9abe687
    2 Nodes configured
    6 Resources configured
    
    
    Online: [ z1.example.com z2.example.com ]
    
    Full list of resources:
     myapc	(stonith:fence_apc_snmp):	Started z1.example.com 
     Resource Group: apachegroup
         my_lvm	(ocf::heartbeat:LVM):	Started z1.example.com 
         my_fs	(ocf::heartbeat:Filesystem):	Started z1.example.com 
         VirtualIP	(ocf::heartbeat:IPaddr2):	Started z1.example.com 
         Website	(ocf::heartbeat:apache):	Started z1.example.com
    請注意,若您尚未為您的叢集配置一項隔離裝置(如 節 1.3, “隔離配置” 中所述),就預設值這些資源將不會啟用。
  4. 當叢集啟動後,您可在瀏覽器中輸入您定義為 IPaddr2 資源的 IP 位址,以檢視包含了單一「Hello」字串的範本。
    Hello
    若您發現您配置的資源並未運作,您可執行 pcs resource debug-start 資源 指令來測試資源配置。欲取得有關於 pcs resource debug-start 指令上的相關資訊,請參閱《High Availability Add-On 參照》手冊。