部署自動虛擬 IP 容錯移轉

您必須先在叢集上安裝 Corosync 與 Pacemaker,才能與私有雲設備整合並測試次要 IP 容錯移轉。

在叢集上安裝

  1. 安裝 Corosync 與 Pacemaker 套件。
    yum install corosync pacemaker pcs
    yum install python36-oci-cli
    根據達到 yum 儲存區域的實驗室需求設定代理主機。
  2. 備份叢集的核心備份組態。
    sudo cp /usr/lib/ocf/resource.d/heartbeat/IPaddr2 /usr/lib/ocf/resource.d/heartbeat/IPaddr2.bck
  3. 執行 firewalld (根據叢集的客戶安全性需求所定義)。
  4. 更新 /etc/hosts 檔案以新增所有叢集節點的節點 IP 和主機名稱資訊,以設定本機 DNS 系統。
    範例:
    <Instance-Node1 Private IP> node1-name
    <Instance-Node2 Private IP> node2-name
  5. 建立使用者並設定密碼。
    sudo passwd hacluster
  6. 啟動及啟用叢集服務。
    sudo systemctl start pcsd
    sudo systemctl enable pacemaker
    sudo systemctl enable corosync
    sudo systemctl enable pcsd
  7. 驗證叢集認證。
    sudo pcs cluster auth <node1-name> <node2-name>
    <node1-name> : Cluster Node1/Hostname
    <node2-name> : Cluster Node1/Hostname
    範例:
    sudo pcs cluster auth a-node1 a-node2
    Username: hacluster
    Password: 
    a-node1: Authorized
    a-node2: Authorized
  8. 叢集設定。
    sudo pcs cluster setup --name <clustername> <node1-name> <node2-name>
    <clustername> : Cluster Name
    <node1-name> : Cluster Node1/Hostname
    <node2-name> : Cluster Node1/Hostname
    範例:
    sudo pcs cluster auth a-node1 a-node2
    Username: hacluster
    Password: 
    a-node1: Authorized
    a-node2: Authorized
    [root@a-node1 opc] # sudo pcs cluster setup HACluster a-node1 a-node2
    Error: A cluster name (--name <name>) is required to setup a cluster
    [root@a-node1 opc] # sudo pcs cluster setup --name HACluster a-node1 a-node2
    Destroying cluster on nodes: a-node1, a-node2...
    a-node1: Stopping Cluster (pacemaker)...
    a-node2: Stopping Cluster (pacemaker)...
    a-node2: Successfully destroyed cluster
    a-node1: Successfully destroyed cluster
    Sending 'pacemaker_remote authkey' to 'a-node1', 'a-node2'
    a-node1: successful distribution of the file 'pacemaker_remote authkey'
    a-node2: successful distribution of the file 'pacemaker_remote authkey'
    Sending cluster config files to the nodes...
    a-node1: Succeeded
    a-node2: Succeeded
    Synchronizing pcsd certificates on nodes a-node1, a-node2...
    a-node1: Success
    a-node2: Success
    Restarting pcsd on the nodes in order to reload the certificates...
    a-node1: Success
    a-node2: Success
  9. 為來自任何叢集節點的所有叢集節點啟動叢集。
    sudo pcs cluster start --name clustername -–all
    範例:
    sudo pcs cluster start --name HACluster --all
    a-node1: Starting Cluster (corosync)...
    a-node2: Starting Cluster (corosync)...
    a-node2: Starting Cluster (pacemaker)...
    a-node1: Starting Cluster (pacemaker)...
  10. 設定發音員特性。
    sudo pcs property set stonith-enabled=false
    sudo pcs property set no-quorum-policy=ignore
  11. 檢查執行中的叢集狀態。
    sudo pcs cluster status
    範例:
    sudo pcs cluster status
    Cluster Status:
    Stack: corosync
    Current DC: a-node2 (version 1.1.23-1.0.1.el7_9.1-9acf116022) - partition with quorum
    Last updated: Fri Aug 19 03:07:25 2022
    Last change: Fri Aug 19 03:06:13 2022 by root via cibadmin on a-node1
    2 nodes configured
    0 resource instances configured
    PCSD Status:
    a-node1: Online
    a-node2: Online
  12. 根據您所有叢集節點上的專用雲端設備設定值設定 OCI 組態。設定組態設定檔對連線至 Private Cloud Appliance 非常重要。
    範例:i.e. /root/.oci/config
    [DEFAULT]
    user=<User-ocid1>
    fingerprint=<fingerprint>
    key_file=<Key-Location>
    tenancy=<Tenancy ocid1>
    region=<PCA FQDN>

定義叢集上的活動訊號設定值,並與 Private Cloud Appliance X9-2 VIP 容錯移轉執行處理整合

  1. 若為 Private Cloud Appliance ,請執行:
    sudo sed -i '633i\export OCI_CLI_CERT_BUNDLE=/root/.oci/ca-chain.cert.pem\' /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    您可以改為使用 assign-private-ip 命令傳送 Private Cloud Appliance 憑證。例如:--cert-bundle <Certification Location for Private Cloud Appliance> 選項。
    以下為 Oracle Linux 7。9 的範例。如果是 Oracle Linux 8 和 Centos 作業系統,請在 IPaddr2 中尋找 add_interface () 函數行號,並在更新 Linux HA IPaddr2 資源項目時相應變更行號。
    sudo sed -i '628i\server="`hostname -s`"\' /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '629i\node1vnic="ocid1.vnic.pca.NODE1-vNIC-OCID"\' 
    /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '630i\node2vnic="ocid1.vnic.pca.NODE2-vNIC-OCID"\' 
    /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '631i\vnicip="10.212.15.13"\' /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '632i\export LC_ALL=C.UTF-8\' /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '633i\export LANG=C.UTF-8\' /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '633i\export OCI_CLI_CERT_BUNDLE=/root/.oci/ca-chain.cert.pem\' 
    /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '634i\touch /tmp/error.log\' /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '635i\##### OCI/IPaddr Integration\' /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '636i\ if [ $server = "node1" ]; then\' 
    /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '637i\ oci network vnic assign-private-ip --unassign-if-already-assigned --vnic-id $node1vnic --ip-address $vnicip >/tmp/error.log 2>&1\' 
    /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '638i\ else \' /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '639i\ oci network vnic assign-private-ip --unassign-if-already-assigned --vnic-id $node2vnic --ip-address $vnicip >/tmp/error.log 2>&1\' 
    /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    sudo sed -i '640i\ fi \' /usr/lib/ocf/resource.d/heartbeat/IPaddr2
    
  2. IPaddr2 中實作程式碼修改。
    • ocid1.vnic.pca.NODE1-vNIC-OCIDocid1.vnic.pca.NODE2-vNIC-OCID 取代為您自己的 OCI VNIC (虛擬網路介面卡) OCID。
    • node1node2 主機名稱項目取代為您自己的叢集節點主機名稱。
    • OCI_CLI_CERT_BUNDLE 中,定義 Private Cloud Appliance 的 CERT 組合位置。
    • 針對您的 VNIC IP,請根據您的組態、子網路、VCN 定義 VNIC IP,並且確定這是唯一的 IP,不會配置給任何其他 VNIC。

設定叢集資源

若要設定叢集資源,請執行:

pcs resource create <Cluster-Resource-Name> ocf:heartbeat:IPaddr2 ip=10.212.15.13 cidr_netmask=24 op monitor interval=20

注意:

  • Pacemaker 指令中的 cidr_netmask=24 相依於子網路大小為 /24。
  • ip=10.212.15.13 是次要專用 IP。

範例:

pcs status
Cluster name: HACluster
Stack: corosync
Current DC: a-node2 (version 1.1.23-1.0.1.el7_9.1-9acf116022) - partition with quorum
Last updated: Fri Aug 19 03:34:51 2022
Last change: Fri Aug 19 03:34:44 2022 by root via cibadmin on a-node1
2 nodes configured
1 resource instance configured
Online: [ a-node1 a-node2 ]
Full list of resources:
HAFailover (ocf::heartbeat:IPaddr2): Started a-node1
Daemon Status:
corosync: active/disabled
pacemaker: active/disabled
pcsd: active/enabled

次要 IP 的測試容錯移轉

測試次要 IP 執行的容錯移轉:

sudo pcs resource move <cluster-name> <node2-name>
<clustername> : Cluster Name
<node2-name> : Cluster Node1/Hostname

例如:

sudo pcs resource move HAFailover a-node2

驗證成功容錯移轉

資源應在 node2 上啟動。若要驗證成功容錯移轉,請執行:

# pcs status