在 Azure 中的 Red Hat Enterprise Linux 上設定 Pacemaker

本文說明如何在 Red Hat Enterprise Server (RHEL) 上設定基本 Pacemaker 叢集。 這些指示涵蓋 RHEL 7、RHEL 8 和 RHEL 9。

必要條件

請先閱讀下列 SAP 附註和檔案:

叢集安裝

Diagram that shows an overview of Pacemaker on RHEL.

注意

Red Hat 不支援軟體模擬監視程式。 Red Hat 不支援雲端平臺上的 SBD。 如需詳細資訊,請參閱 RHEL 高可用性叢集的支持原則 - sbd 和 fence_sbd

Azure 上 Pacemaker RHEL 叢集唯一支援的隔離機制是 Azure 柵欄代理程式。

下列專案前面會加上:

  • [A]: 適用於所有節點
  • [1]: 僅適用於節點 1
  • [2]: 僅適用於節點 2

命令或 RHEL 7 與 RHEL 8/RHEL 9 之間的設定差異會標示在檔中。

  1. [A] 註冊。 此步驟是選擇性的。 如果您使用已啟用 RHEL SAP HA 的映像,則不需要此步驟。

    例如,如果您要在 RHEL 7 上部署,請註冊 VM,並將其連結至包含 RHEL 7 存放庫的集區。

    sudo subscription-manager register
    # List the available pools
    sudo subscription-manager list --available --matches '*SAP*'
    sudo subscription-manager attach --pool=<pool id>
    

    當您將集區附加至 Azure Marketplace 隨用隨付 RHEL 映射時,您的 RHEL 使用量實際上會加倍計費。 您需支付隨用隨付映射的一次費用,一次用於您附加的集區中的 RHEL 權利。 為了減輕這種情況,Azure 現在提供自備訂用帳戶 RHEL 映射。 如需詳細資訊,請參閱 Red Hat Enterprise Linux 自備訂用帳戶 Azure 映像

  2. [A] 啟用 SAP 存放庫的 RHEL。 此步驟是選擇性的。 如果您使用已啟用 RHEL SAP HA 的映像,則不需要此步驟。

    若要在 RHEL 7 上安裝必要的套件,請啟用下列存放庫:

    sudo subscription-manager repos --disable "*"
    sudo subscription-manager repos --enable=rhel-7-server-rpms
    sudo subscription-manager repos --enable=rhel-ha-for-rhel-7-server-rpms
    sudo subscription-manager repos --enable=rhel-sap-for-rhel-7-server-rpms
    sudo subscription-manager repos --enable=rhel-ha-for-rhel-7-server-eus-rpms
    
  3. [A] 安裝 RHEL HA 附加元件。

     sudo yum install -y pcs pacemaker fence-agents-azure-arm nmap-ncat
    

    重要

    如果資源停止失敗,或叢集節點無法再彼此通訊,我們建議下列版本的 Azure 隔離代理程式(或更新版本)讓客戶受益於更快速的故障轉移時間:

    RHEL 7.7 或更高版本使用最新可用的範圍代理程式套件版本。

    RHEL 7.6:fence-agents-4.2.1-11.el7_6.8

    RHEL 7.5:fence-agents-4.0.11-86.el7_5.8

    RHEL 7.4:fence-agents-4.0.11-66.el7_4.12

    如需詳細資訊,請參閱 以 RHEL 高可用性叢集成員身分執行的 Azure VM 需要很長的時間進行隔離,或在 VM 關機前隔離失敗/逾時。

    重要

    針對想要針對 Azure 資源使用受控識別的客戶,而不是柵欄代理程式的服務主體名稱,建議使用下列版本的 Azure 隔離代理程式(或更新版本):

    RHEL 8.4:fence-agents-4.2.1-54.el8。

    RHEL 8.2:fence-agents-4.2.1-41.el8_2.4

    RHEL 8.1:fence-agents-4.2.1-30.el8_1.4

    RHEL 7.9:fence-agents-4.2.1-41.el7_9.4。

    重要

    在 RHEL 9 上,我們建議使用下列套件版本(或更新版本),以避免 Azure 柵欄代理程式發生問題:

    fence-agents-4.10.0-20.el9_0.7

    fence-agents-common-4.10.0-20.el9_0.6

    ha-cloud-support-4.10.0-20.el9_0.6.x86_64.rpm

    檢查 Azure 柵欄代理程式的版本。 如有必要,請將它更新為最低必要版本或更新版本。

    # Check the version of the Azure Fence Agent
     sudo yum info fence-agents-azure-arm
    

    重要

    如果您需要更新 Azure 隔離代理程式,而且如果您使用自定義角色,請務必更新自定義角色以包含動作 powerOff。 如需詳細資訊,請參閱 建立隔離代理程式的自定義角色。

  4. 如果您要在 RHEL 9 上部署,也請安裝用於雲端部署的資源代理程式。

    sudo yum install -y resource-agents-cloud
    
  5. [A] 設定主機名解析。

    您可以使用 DNS 伺服器或修改 /etc/hosts 所有節點上的檔案。 此範例示範如何使用 /etc/hosts 檔案。 在下列命令中取代IP位址和主機名。

    重要

    如果您在叢集組態中使用主機名,請務必有可靠的主機名解析。 如果名稱無法使用,叢集通訊就會失敗,這可能會導致叢集故障轉移延遲。

    使用 /etc/hosts 的優點是叢集與 DNS 無關,這可能是單一失敗點。

    sudo vi /etc/hosts
    

    將下列幾行插入 。/etc/hosts 變更IP位址和主機名以符合您的環境。

    # IP address of the first cluster node
    10.0.0.6 prod-cl1-0
    # IP address of the second cluster node
    10.0.0.7 prod-cl1-1
    
  6. [A]hacluster 密碼變更為相同的密碼。

    sudo passwd hacluster
    
  7. [A] 新增 Pacemaker 的防火牆規則。

    將下列防火牆規則新增至叢集節點之間的所有叢集通訊。

    sudo firewall-cmd --add-service=high-availability --permanent
    sudo firewall-cmd --add-service=high-availability
    
  8. [A] 啟用基本叢集服務。

    執行下列命令以啟用 Pacemaker 服務並加以啟動。

    sudo systemctl start pcsd.service
    sudo systemctl enable pcsd.service
    
  9. [1] 建立 Pacemaker 叢集。

    執行下列命令來驗證節點並建立叢集。 將令牌設定為 30000,以允許記憶體保留維護。 如需詳細資訊,請參閱 適用於Linux的文章。

    如果您要在 RHEL 7.x建置叢集,請使用下列命令:

    sudo pcs cluster auth prod-cl1-0 prod-cl1-1 -u hacluster
    sudo pcs cluster setup --name nw1-azr prod-cl1-0 prod-cl1-1 --token 30000
    sudo pcs cluster start --all
    

    如果您要在 RHEL 8.x/RHEL 9.x建置叢集,請使用下列命令:

    sudo pcs host auth prod-cl1-0 prod-cl1-1 -u hacluster
    sudo pcs cluster setup nw1-azr prod-cl1-0 prod-cl1-1 totem token=30000
    sudo pcs cluster start --all
    

    執行下列命令來確認叢集狀態:

    # Run the following command until the status of both nodes is online
    sudo pcs status
    
    # Cluster name: nw1-azr
    # WARNING: no stonith devices and stonith-enabled is not false
    # Stack: corosync
    # Current DC: prod-cl1-1 (version 1.1.18-11.el7_5.3-2b07d5c5a9) - partition with quorum
    # Last updated: Fri Aug 17 09:18:24 2018
    # Last change: Fri Aug 17 09:17:46 2018 by hacluster via crmd on prod-cl1-1
    #
    # 2 nodes configured
    # 0 resources configured
    #
    # Online: [ prod-cl1-0 prod-cl1-1 ]
    #
    # No resources
    #
    # Daemon Status:
    #   corosync: active/disabled
    #   pacemaker: active/disabled
    #   pcsd: active/enabled
    
  10. [A] 設定預期的投票。

    # Check the quorum votes 
    pcs quorum status
    
    # If the quorum votes are not set to 2, execute the next command
    sudo pcs quorum expected-votes 2
    

    提示

    如果您要建置多節點叢集,也就是具有兩個以上節點的叢集,請勿將投票設為 2。

  11. [1] 允許並行圍欄動作。

    sudo pcs property set concurrent-fencing=true
    

建立隔離裝置

隔離裝置會使用 Azure 資源的受控識別或服務主體來授權 Azure。

若要建立受控識別 (MSI), 請為叢集中的每個 VM 建立系統指派的 受控識別。 如果系統指派的受控識別已經存在,則會使用它。 目前請勿搭配 Pacemaker 使用使用者指派的受控識別。 RHEL 7.9 和 RHEL 8.x/RHEL 9.x 支援柵欄裝置, 以受控識別為基礎。

[1] 建立柵欄代理程式的自定義角色

受控識別和服務主體預設沒有存取 Azure 資源的許可權。 您必須提供受控識別或服務主體許可權,以啟動和停止叢集的所有 VM。。 如果您尚未建立自定義角色,您可以使用 PowerShell 或 Azure CLI 加以建立

針對輸入檔使用下列內容。 您必須將內容調整為訂用帳戶,也就是將 和 yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy 取代xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx為您訂用帳戶的標識碼。 如果您只有一個訂用帳戶,請移除 中的 AssignableScopes第二個專案。

{
      "Name": "Linux Fence Agent Role",
      "description": "Allows to power-off and start virtual machines",
      "assignableScopes": [
              "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
              "/subscriptions/yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"
      ],
      "actions": [
              "Microsoft.Compute/*/read",
              "Microsoft.Compute/virtualMachines/powerOff/action",
              "Microsoft.Compute/virtualMachines/start/action"
      ],
      "notActions": [],
      "dataActions": [],
      "notDataActions": []
}

[A] 指派自定義角色

使用受控識別或服務主體。

將上一節中建立的自定義角色 Linux Fence Agent Role 指派給叢集 VM 的每個受控識別。 每個 VM 系統指派的受控識別都需要為每個叢集 VM 資源指派的角色。 如需詳細資訊,請參閱使用 Azure 入口網站 將受控識別存取權指派給資源。 確認每個 VM 的受控識別角色指派都包含所有叢集 VM。

重要

請注意,使用受控識別 指派和移除授權可能會延遲 到生效為止。

[1] 建立隔離裝置

編輯 VM 的權限之後,您可以設定叢集中的隔離裝置。

sudo pcs property set stonith-timeout=900

注意

只有在 RHEL 主機名稱和 Azure VM 名稱不相同時,命令中才需要選項pcmk_host_map 以 hostname:vm-name 格式指定對應。 請參閱命令中的粗體區段。 如需詳細資訊,請參閱 我應該使用何種格式來指定節點對應至pcmk_host_map中的隔離裝置?

針對 RHEL 7.x,請使用下列命令來設定柵欄裝置:

sudo pcs stonith create rsc_st_azure fence_azure_arm msi=true resourceGroup="resource group" \ 
subscriptionId="subscription id" pcmk_host_map="prod-cl1-0:prod-cl1-0-vm-name;prod-cl1-1:prod-cl1-1-vm-name" \
power_timeout=240 pcmk_reboot_timeout=900 pcmk_monitor_timeout=120 pcmk_monitor_retries=4 pcmk_action_limit=3 pcmk_delay_max=15 \
op monitor interval=3600

針對 RHEL 8.x/9.x,請使用下列命令來設定柵欄裝置:

# Run following command if you are setting up fence agent on (two-node cluster and pacemaker version greater than 2.0.4-6.el8) OR (HANA scale out)
sudo pcs stonith create rsc_st_azure fence_azure_arm msi=true resourceGroup="resource group" \
subscriptionId="subscription id" pcmk_host_map="prod-cl1-0:prod-cl1-0-vm-name;prod-cl1-1:prod-cl1-1-vm-name" \
power_timeout=240 pcmk_reboot_timeout=900 pcmk_monitor_timeout=120 pcmk_monitor_retries=4 pcmk_action_limit=3 \
op monitor interval=3600

# Run following command if you are setting up fence agent on (two-node cluster and pacemaker version less than 2.0.4-6.el8)
sudo pcs stonith create rsc_st_azure fence_azure_arm msi=true resourceGroup="resource group" \
subscriptionId="subscription id" pcmk_host_map="prod-cl1-0:prod-cl1-0-vm-name;prod-cl1-1:prod-cl1-1-vm-name" \
power_timeout=240 pcmk_reboot_timeout=900 pcmk_monitor_timeout=120 pcmk_monitor_retries=4 pcmk_action_limit=3 pcmk_delay_max=15 \
op monitor interval=3600

如果您使用以服務主體設定為基礎的隔離裝置,請閱讀 使用 Azure 隔離 從 SPN 變更為 Pacemaker 叢集的 MSI,並瞭解如何轉換成受控識別設定。

提示

  • 若要避免雙節點 Pacemaker 叢集中的圍欄競爭,您可以設定 priority-fencing-delay 叢集屬性。 當發生分割腦案例時,這個屬性會在隔離具有較高總資源優先順序的節點時引入額外的延遲。 如需詳細資訊,請參閱 Pacemaker 是否可以使用最少執行的資源來隔離叢集節點?
  • 屬性 priority-fencing-delay 適用於 Pacemaker 2.0.4-6.el8 版或更新版本,且適用於雙節點叢集。 如果您設定 priority-fencing-delay 叢集屬性,則不需要設定 pcmk_delay_max 屬性。 但是,如果 Pacemaker 版本小於 2.0.4-6.el8,您需要設定 pcmk_delay_max 屬性。
  • 如需如何設定 priority-fencing-delay 叢集屬性的指示,請參閱個別的 SAP ASCS/ERS 和 SAP HANA 相應增加 HA 檔。

監視和隔離作業會還原串行化。 因此,如果執行時間較長的監視作業和同時隔離事件,叢集故障轉移就不會有延遲,因為監視作業已經執行。

[1] 啟用隔離裝置的使用

sudo pcs property set stonith-enabled=true

提示

Azure 柵欄代理程式需要對公用端點的輸出連線。 如需詳細資訊以及可能的解決方案,請參閱 使用標準 ILB 的 VM 公用端點連線。

設定 Azure 排程事件的 Pacemaker

Azure 提供 排程的事件。 排程的事件會透過元數據服務傳送,並允許應用程式準備這類事件的時間。

Pacemaker 資源代理程式 azure-events-az 會監視已排程的 Azure 事件。 如果偵測到事件,且資源代理程式會判斷另一個叢集節點可供使用,則會設定叢集健康情況屬性。

為節點設定叢集健康情況屬性時,位置條件約束會觸發,且名稱不是以 開頭 health- 的所有資源都會從具有排程事件的節點移轉。 在受影響的叢集節點沒有執行中的叢集資源之後,就會認可排程的事件,並可執行其動作,例如重新啟動。

  1. [A] 請確定代理程式的套件 azure-events-az 已安裝且為最新狀態。

    RHEL 8.x: sudo dnf info resource-agents
    RHEL 9.x: sudo dnf info resource-agents-cloud
    

    最低版本需求:

    • RHEL 8.4: resource-agents-4.1.1-90.13
    • RHEL 8.6: resource-agents-4.9.0-16.9
    • RHEL 8.8: resource-agents-4.9.0-40.1
    • RHEL 9.0: resource-agents-cloud-4.10.0-9.6
    • RHEL 9.2 和更新版: resource-agents-cloud-4.10.0-34.1
  2. [1] 在 Pacemaker 中設定資源。

    #Place the cluster in maintenance mode
    sudo pcs property set maintenance-mode=true
    
    
  3. [1] 設定 Pacemaker 叢集健康情況節點策略和條件約束。

    sudo pcs property set node-health-strategy=custom
    sudo pcs constraint location 'regexp%!health-.*' \
    rule score-attribute='#health-azure' \
    defined '#uname'
    

    重要

    除了後續步驟中所述的資源以外,請勿在叢集中 health- 定義任何其他資源。

  4. [1] 設定叢集屬性的初始值。 針對每個叢集節點和向外延展環境執行,包括多數製造商 VM。

    sudo crm_attribute --node prod-cl1-0 --name '#health-azure' --update 0
    sudo crm_attribute --node prod-cl1-1 --name '#health-azure' --update 0
    
  5. [1] 在 Pacemaker 中設定資源。 請確定資源開頭為 health-azure

    sudo pcs resource create health-azure-events \
    ocf:heartbeat:azure-events-az op monitor interval=10s
    sudo pcs resource clone health-azure-events allow-unhealthy-nodes=true
    
  6. 讓 Pacemaker 叢集脫離維護模式。

    sudo pcs property set maintenance-mode=false
    
  7. 清除啟用期間的任何錯誤,並確認 health-azure-events 資源已在所有叢集節點上成功啟動。

    sudo pcs resource cleanup
    

    排程事件 的第一次查詢執行最多可能需要兩分鐘的時間。 使用排程事件的 Pacemaker 測試,可以使用叢集 VM 的重新啟動或重新部署動作。 如需詳細資訊,請參閱 排程的事件

選擇性隔離組態

提示

只有在您想要設定特殊隔離裝置 fence_kdump時,本節才適用。

如果您需要收集 VM 內的診斷資訊,根據柵欄代理程式 fence_kdump來設定另一個隔離裝置可能很有用。 代理 fence_kdump 程式可以偵測到節點已進入 kdump 損毀復原,並允許損毀復原服務在叫用其他隔離方法之前完成。 請注意, fence_kdump 當您使用 Azure VM 時,不是傳統柵欄機制的替代專案,例如 Azure 柵欄代理程式。

重要

請注意,當 設定為第一層隔離裝置時 fence_kdump ,它會在隔離作業中引入延遲,以及應用程式資源故障轉移的延遲。

如果成功偵測到損毀傾印,隔離會延遲到損毀復原服務完成為止。 如果失敗的節點無法連線或未回應,則隔離會依所決定的時間、設定的反覆項目數目和 fence_kdump 逾時而延遲。 如需詳細資訊,請參閱在 Red Hat Pacemaker 叢集中設定fence_kdump 如何??

建議的 fence_kdump 逾時可能需要調整為特定環境。

建議您 fence_kdump 只在需要時設定隔離,以收集 VM 內的診斷,並一律與傳統柵欄方法結合,例如 Azure 柵欄代理程式。

下列 Red Hat KB 文章包含設定 fence_kdump 隔離的重要資訊:

除了 Azure 柵欄代理程式設定之外,請執行下列選擇性步驟來新增 fence_kdump 為第一層隔離組態。

  1. [A] 確認為 kdump 作用中並已設定。

    systemctl is-active kdump
    # Expected result
    # active
    
  2. [A] 安裝 fence_kdump 柵欄代理程式。

    yum install fence-agents-kdump
    
  3. [1] 在叢集中建立 fence_kdump 隔離裝置。

    pcs stonith create rsc_st_kdump fence_kdump pcmk_reboot_action="off" pcmk_host_list="prod-cl1-0 prod-cl1-1" timeout=30
    
  4. [1] 設定隔離層級, fence_kdump 讓隔離機制優先參與。

    pcs stonith create rsc_st_kdump fence_kdump pcmk_reboot_action="off" pcmk_host_list="prod-cl1-0 prod-cl1-1"
    pcs stonith level add 1 prod-cl1-0 rsc_st_kdump
    pcs stonith level add 1 prod-cl1-1 rsc_st_kdump
    pcs stonith level add 2 prod-cl1-0 rsc_st_azure
    pcs stonith level add 2 prod-cl1-1 rsc_st_azure
    
    # Check the fencing level configuration 
    pcs stonith level
    # Example output
    # Target: prod-cl1-0
    # Level 1 - rsc_st_kdump
    # Level 2 - rsc_st_azure
    # Target: prod-cl1-1
    # Level 1 - rsc_st_kdump
    # Level 2 - rsc_st_azure
    
  5. [A] 允許透過防火牆的必要埠 fence_kdump

    firewall-cmd --add-port=7410/udp
    firewall-cmd --add-port=7410/udp --permanent
    
  6. [A] 確定 initramfs 影像檔案包含 fence_kdumphosts 檔案。 如需詳細資訊,請參閱在 Red Hat Pacemaker 叢集中 如何? 設定fence_kdump?

    lsinitrd /boot/initramfs-$(uname -r)kdump.img | egrep "fence|hosts"
    # Example output 
    # -rw-r--r--   1 root     root          208 Jun  7 21:42 etc/hosts
    # -rwxr-xr-x   1 root     root        15560 Jun 17 14:59 usr/libexec/fence_kdump_send
    
  7. [A] 執行 中的/etc/kdump.conf設定fence_kdump_nodes,以避免fence_kdump某些kexec-tools版本的逾時失敗。 如需詳細資訊,請參閱 未使用 kexec-tools 2.0.15 版或更新 版本指定fence_kdump_nodes逾時fence_kdump逾時,fence_kdump RHEL 6 或 7 高可用性叢集中的 RHEL 6 或 7 高可用性叢集中的 kexec-tools 版本早於 2.0.14 時失敗。 此處會顯示兩個節點叢集的範例組態。 在 中 /etc/kdump.conf進行變更之後,必須重新產生 kdump 映像。 若要重新產生,請重新啟動 kdump 服務。

    vi /etc/kdump.conf
    # On node prod-cl1-0 make sure the following line is added
    fence_kdump_nodes  prod-cl1-1
    # On node prod-cl1-1 make sure the following line is added
    fence_kdump_nodes  prod-cl1-0
    
    # Restart the service on each node
    systemctl restart kdump
    
  8. 藉由當機節點來測試組態。 如需詳細資訊,請參閱在 Red Hat Pacemaker 叢集中 如何? 設定fence_kdump?

    重要

    如果叢集已在生產力使用中,請據以規劃測試,因為當機節點會對應用程式造成影響。

    echo c > /proc/sysrq-trigger
    

下一步