🫶
Debian11 で Pacemaker
前提
2台のWebサーバ(debian11-0、debian11-1)でリソースの共有を図っていきます。
共有するリソースは、Webサーバと共有アドレス(10.2.0.244/24)です
まずは nginx をインストールして動作確認します。
# apt install --no-install-recommends nginx
# cp -pi /var/www/html/index.nginx-debian.html /var/www/html/index.nginx-debian.html.orig
# hostname > /var/www/html/index.nginx-debian.html
両ノードで準備
必要なパッケージをインストールします。
# apt install --no-install-recommends pacemaker fence-agents pcs pacemaker-cli-utils
パスワードの設定と初期化を実施します。
# passwd -S hacluster
hacluster L 02/21/2023 0 99999 7 -1
# passwd hacluster
New password:
Retype new password:
passwd: password updated successfully
# passwd -S hacluster
hacluster P 02/21/2023 0 99999 7 -1
# pcs cluster destroy
Shutting down pacemaker/corosync services...
Killing any remaining services...
Removing all cluster configuration files...
/etc/hosts に記載するなど、ホスト名からアドレスへの解決ができるようにしておきます。
マスターノードで実施
ユーザの認証を行います。
# pcs host auth debian11-0 debian11-1
Username: hacluster
Password:
debian11-1: Authorized
debian11-0: Authorized
クラスタのセットアップ
クラスタのセットアップを行います。
# pcs cluster setup web_cluster debian11-0 debian11-1
No addresses specified for host 'debian11-0', using 'debian11-0'
No addresses specified for host 'debian11-1', using 'debian11-1'
Destroying cluster on hosts: 'debian11-0', 'debian11-1'...
debian11-0: Successfully destroyed cluster
debian11-1: Successfully destroyed cluster
Requesting remove 'pcsd settings' from 'debian11-0', 'debian11-1'
debian11-0: successful removal of the file 'pcsd settings'
debian11-1: successful removal of the file 'pcsd settings'
Sending 'corosync authkey', 'pacemaker authkey' to 'debian11-0', 'debian11-1'
debian11-0: successful distribution of the file 'corosync authkey'
debian11-0: successful distribution of the file 'pacemaker authkey'
debian11-1: successful distribution of the file 'corosync authkey'
debian11-1: successful distribution of the file 'pacemaker authkey'
Sending 'corosync.conf' to 'debian11-0', 'debian11-1'
debian11-0: successful distribution of the file 'corosync.conf'
debian11-1: successful distribution of the file 'corosync.conf'
Cluster has been successfully set up.
クラスタを開始します。
# pcs cluster start --all
debian11-1: Starting Cluster...
debian11-0: Starting Cluster...
クラスタの状態を確認します。
# pcs status
Cluster name: web_cluster
WARNINGS:
No stonith devices and stonith-enabled is not false
Cluster Summary:
* Stack: unknown
* Current DC: NONE
* Last updated: Sat Aug 5 17:35:10 2023
* Last change: Sat Aug 5 17:34:53 2023 by hacluster via crmd on debian11-0
* 2 nodes configured
* 0 resource instances configured
Node List:
* Node debian11-0: UNCLEAN (offline)
* Node debian11-1: UNCLEAN (offline)
Full List of Resources:
* No resources
Daemon Status:
corosync: active/disabled
pacemaker: active/disabled
pcsd: active/enabled
# pcs status corosync
Membership information
----------------------
Nodeid Votes Name
1 1 debian11-0 (local)
2 1 debian11-1
リソースの共有設定
設定をするとマスター側でnginxの起動と、共有アドレスの付与が行われます。
このとき、スタンバイ側でnginxが起動していたら停止されます。
# pcs property set stonith-enabled=false
# pcs resource create ClusterIP IPaddr2 ip="10.2.0.244" cidr_netmask="24" nic=ens3
Assumed agent name 'ocf:heartbeat:IPaddr2' (deduced from 'IPaddr2')
# pcs resource create WebServer systemd:nginx
# pcs constraint colocation add WebServer with ClusterIP
# pcs constraint order ClusterIP then start WebServer
Adding ClusterIP WebServer (kind: Mandatory) (Options: first-action=start then-action=start)
リソース確認
# pcs resource
* ClusterIP (ocf::heartbeat:IPaddr2): Started debian11-0
* WebServer (systemd:nginx): Started debian11-0
# pcs resource config ClusterIP
Resource: ClusterIP (class=ocf provider=heartbeat type=IPaddr2)
Attributes: cidr_netmask=24 ip=10.2.0.244 nic=ens3
Operations: monitor interval=10s timeout=20s (ClusterIP-monitor-interval-10s)
start interval=0s timeout=20s (ClusterIP-start-interval-0s)
stop interval=0s timeout=20s (ClusterIP-stop-interval-0s)
# pcs resource config WebServer
Resource: WebServer (class=systemd type=nginx)
Operations: monitor interval=60 timeout=100 (WebServer-monitor-interval-60)
start interval=0s timeout=100 (WebServer-start-interval-0s)
stop interval=0s timeout=100 (WebServer-stop-interval-0s)
クラスタの状態を確認します。
# pcs status
Cluster name: web_cluster
Cluster Summary:
* Stack: corosync
* Current DC: debian11-1 (version 2.0.5-ba59be7122) - partition with quorum
* Last updated: Sat Aug 5 17:51:36 2023
* Last change: Sat Aug 5 17:49:07 2023 by root via cibadmin on debian11-0
* 2 nodes configured
* 2 resource instances configured
Node List:
* Online: [ debian11-0 debian11-1 ]
Full List of Resources:
* ClusterIP (ocf::heartbeat:IPaddr2): Started debian11-0
* WebServer (systemd:nginx): Started debian11-0
Daemon Status:
corosync: active/disabled
pacemaker: active/disabled
pcsd: active/enabled
リソースの移動。
クラスタをスタンバイノードへ移動します。
debian11-0側で、nginx が停止。共有アドレスのはく奪
debian11-1側で、nginx が起動。共有アドレスの付与
が行われます。
リソースの移動は、どちらのノードで実行しても構いません。
# pcs resource move WebServer debian11-1
# pcs status
Cluster name: web_cluster
Cluster Summary:
* Stack: corosync
* Current DC: debian11-1 (version 2.0.5-ba59be7122) - partition with quorum
* Last updated: Sat Aug 5 17:55:33 2023
* Last change: Sat Aug 5 17:55:26 2023 by root via crm_resource on debian11-0
* 2 nodes configured
* 2 resource instances configured
Node List:
* Online: [ debian11-0 debian11-1 ]
Full List of Resources:
* ClusterIP (ocf::heartbeat:IPaddr2): Started debian11-1
* WebServer (systemd:nginx): Started debian11-1
Daemon Status:
corosync: active/disabled
pacemaker: active/disabled
pcsd: active/enabled
リソースを戻してみます。
# pcs resource move WebServer debian11-0
# pcs status
Cluster name: web_cluster
Cluster Summary:
* Stack: corosync
* Current DC: debian11-1 (version 2.0.5-ba59be7122) - partition with quorum
* Last updated: Sat Aug 5 18:02:00 2023
* Last change: Sat Aug 5 18:01:50 2023 by root via crm_resource on debian11-0
* 2 nodes configured
* 2 resource instances configured
Node List:
* Online: [ debian11-0 debian11-1 ]
Full List of Resources:
* ClusterIP (ocf::heartbeat:IPaddr2): Started debian11-0
* WebServer (systemd:nginx): Started debian11-0
Daemon Status:
corosync: active/disabled
pacemaker: active/disabled
pcsd: active/enabled
マスター系の切り離し
マスター側ノードをスタンバイモードにします。
リソースがスタンバイ系へ移動します。
スタンバイモードへの移行は、どちらのノードで実行しても構いません。
# pcs node standby debian11-0
# pcs status
Cluster name: web_cluster
Cluster Summary:
* Stack: corosync
* Current DC: debian11-1 (version 2.0.5-ba59be7122) - partition with quorum
* Last updated: Sat Aug 5 18:51:26 2023
* Last change: Sat Aug 5 18:51:18 2023 by root via cibadmin on debian11-1
* 2 nodes configured
* 2 resource instances configured
Node List:
* Node debian11-0: standby
* Online: [ debian11-1 ]
Full List of Resources:
* ClusterIP (ocf::heartbeat:IPaddr2): Started debian11-1
* WebServer (systemd:nginx): Started debian11-1
Daemon Status:
corosync: active/disabled
pacemaker: active/disabled
pcsd: active/enabled
マスター系をスタンバイモードから戻します。
リソースがマスター系へ戻ります。
# pcs node unstandby debian11-0
# pcs status
Cluster name: web_cluster
Cluster Summary:
* Stack: corosync
* Current DC: debian11-1 (version 2.0.5-ba59be7122) - partition with quorum
* Last updated: Sat Aug 5 18:52:45 2023
* Last change: Sat Aug 5 18:52:36 2023 by root via cibadmin on debian11-1
* 2 nodes configured
* 2 resource instances configured
Node List:
* Online: [ debian11-0 debian11-1 ]
Full List of Resources:
* ClusterIP (ocf::heartbeat:IPaddr2): Started debian11-0
* WebServer (systemd:nginx): Started debian11-0
Daemon Status:
corosync: active/disabled
pacemaker: active/disabled
pcsd: active/enabled
スタンバイ系の切り離し
# pcs node standby debian11-1
# pcs status
Cluster name: web_cluster
Cluster Summary:
* Stack: corosync
* Current DC: debian11-0 (version 2.0.5-ba59be7122) - partition with quorum
* Last updated: Sat Aug 5 20:39:22 2023
* Last change: Sat Aug 5 20:39:17 2023 by root via cibadmin on debian11-0
* 2 nodes configured
* 2 resource instances configured
Node List:
* Node debian11-1: standby
* Online: [ debian11-0 ]
Full List of Resources:
* ClusterIP (ocf::heartbeat:IPaddr2): Started debian11-0
* WebServer (systemd:nginx): Started debian11-0
Daemon Status:
corosync: active/disabled
pacemaker: active/disabled
pcsd: active/enabled
スタンバイモードに移行したスタンバイ系で、クラスタを停止します。
# pcs cluster stop debian11-1
debian11-1: Stopping Cluster (pacemaker)...
debian11-1: Stopping Cluster (corosync)...
# pcs status
Cluster name: web_cluster
Cluster Summary:
* Stack: corosync
* Current DC: debian11-0 (version 2.0.5-ba59be7122) - partition with quorum
* Last updated: Sat Aug 5 20:41:26 2023
* Last change: Sat Aug 5 20:39:17 2023 by root via cibadmin on debian11-0
* 2 nodes configured
* 2 resource instances configured
Node List:
* Node debian11-1: OFFLINE (standby)
* Online: [ debian11-0 ]
Full List of Resources:
* ClusterIP (ocf::heartbeat:IPaddr2): Started debian11-0
* WebServer (systemd:nginx): Started debian11-0
Daemon Status:
corosync: active/disabled
pacemaker: active/disabled
pcsd: active/enabled
スタンバイ系のOS再起動してみます。
# pcs status
Error: error running crm_mon, is pacemaker running?
Could not connect to the CIB: Transport endpoint is not connected
crm_mon: Error: cluster is not available on this node
# shutdown -r now
再起動後、pacemaker サービスを起動します。
# systemctl start pacemaker
# pcs status
Cluster name: web_cluster
Cluster Summary:
* Stack: corosync
* Current DC: debian11-0 (version 2.0.5-ba59be7122) - partition with quorum
* Last updated: Sat Aug 5 20:45:11 2023
* Last change: Sat Aug 5 20:39:17 2023 by root via cibadmin on debian11-0
* 2 nodes configured
* 2 resource instances configured
Node List:
* Node debian11-1: standby
* Online: [ debian11-0 ]
Full List of Resources:
* ClusterIP (ocf::heartbeat:IPaddr2): Started debian11-0
* WebServer (systemd:nginx): Started debian11-0
Daemon Status:
corosync: active/disabled
pacemaker: active/disabled
pcsd: active/enabled
スタンバイ系をクラスタへ再度組み入れます。
# pcs node unstandby debian11-1
# pcs status
Cluster name: web_cluster
Cluster Summary:
* Stack: corosync
* Current DC: debian11-0 (version 2.0.5-ba59be7122) - partition with quorum
* Last updated: Sat Aug 5 20:46:50 2023
* Last change: Sat Aug 5 20:46:46 2023 by root via cibadmin on debian11-0
* 2 nodes configured
* 2 resource instances configured
Node List:
* Online: [ debian11-0 debian11-1 ]
Full List of Resources:
* ClusterIP (ocf::heartbeat:IPaddr2): Started debian11-0
* WebServer (systemd:nginx): Started debian11-0
Daemon Status:
corosync: active/disabled
pacemaker: active/disabled
pcsd: active/enabled
Discussion