2018年11月25日日曜日

CentOS 7 + Pacemaker + CorosyncでMariaDBをクラスター化する② (クラスター・リソース構成編)

前回はPacemakerとCorosyncを使用する準備まで実施したので、クラスターとしての設定を行っていく。


★前回の記事はこちら↓

CentOS 7 + Pacemaker + CorosyncでMariaDBをクラスター化する① (準備・インストール編)
https://tech-mmmm.blogspot.com/2018/11/centos-7-pacemaker-corosyncmariadb.html

Pacemaker・Corosyncのクラスターを作成

1. クラスターを作成

スプリットブレイン発生を防止する観点から、クラスター間のハートビートをやり取りするネットワークは2本以上の冗長構成とするのが望ましい。

クラスター作成の際に、ノード名をIPアドレスごとにカンマ区切りで指定することで、複数のIPアドレスでクラスターに登録がされる。

※片方のノードで実施
# pcs cluster setup --start --name cluster2 t1113cent,t1113cent-55 t1114cent,t1114cent-55
------------------------------
Destroying cluster on nodes: t1113cent, t1114cent...
t1113cent: Stopping Cluster (pacemaker)...
t1114cent: Stopping Cluster (pacemaker)...
t1113cent: Successfully destroyed cluster
t1114cent: Successfully destroyed cluster

Sending 'pacemaker_remote authkey' to 't1113cent', 't1114cent'
t1113cent: successful distribution of the file 'pacemaker_remote authkey'
t1114cent: successful distribution of the file 'pacemaker_remote authkey'
Sending cluster config files to the nodes...
t1113cent: Succeeded
t1114cent: Succeeded

Starting cluster on nodes: t1113cent, t1114cent...
t1113cent: Starting Cluster...
t1114cent: Starting Cluster...

Synchronizing pcsd certificates on nodes t1113cent, t1114cent...
t1114cent: Success
t1113cent: Success
Restarting pcsd on the nodes in order to reload the certificates...
t1114cent: Success
t1113cent: Success
------------------------------

設定確認は以下コマンドで実施する。RING ID 0とRING ID 1で2つのIPアドレスが設定されていることがわかる。

# corosync-cfgtool -s
------------------------------
Printing ring status.
Local node ID 1
RING ID 0
        id      = 192.168.11.113
        status  = ring 0 active with no faults
RING ID 1
        id      = 192.168.55.113
        status  = ring 1 active with no faults
------------------------------

2. クラスターのプロパティを設定

クラスターの設定として、STONITHの無効化を行い、no-quorum-policyをignoreに設定する。今回はあくまで検証目的なのでSTONITHは無効化するが、本来はスプリットブレイン時の対策として、STONITHは有効化するべきである。

no-quorum-policyについて、通常クォーラムは多数決の原理でアクティブなノードを決定する仕組みとなるのだが、2台構成のクラスターの場合は多数決による決定ができないため、クォーラム設定は「ignore」に設定するのがセオリーのようだ。この場合スプリットブレインが発生したとしても、各ノードのリソースは特に何も制御されないという設定となるため、STONITHによって片方のノードを強制的に電源を落として対応することになる。

それでは設定をしていこう。まず、現状のプロパティを確認する。

※片方のノードで実施
# pcs property
------------------------------
Cluster Properties:
 cluster-infrastructure: corosync
 cluster-name: cluster2
 dc-version: 1.1.18-11.el7_5.3-2b07d5c5a9
 have-watchdog: false
------------------------------

設定を変更する。

※片方のノードで実施
# pcs property set stonith-enabled=false
# pcs property set no-quorum-policy=ignore
# pcs property
------------------------------
Cluster Properties:
 cluster-infrastructure: corosync
 cluster-name: cluster2
 dc-version: 1.1.18-11.el7_5.3-2b07d5c5a9
 have-watchdog: false
 no-quorum-policy: ignore   ←★クォーラムをignoreに設定
 stonith-enabled: false     ←★STONITHを無効化
------------------------------

リソースエージェントを使ってリソースを構成する

1. リソースを構成

リソースを制御するために、リソースエージェントを利用する。リソースエージェントとは、クラスターソフトで用意されているリソースの起動・監視・停止を制御するためのスクリプトとなる。

今回の構成では以下リソースエージェントを利用する。
  • ocf:heartbeat:IPaddr2 : 仮想IPアドレスを制御
  • ocf:heartbeat:Filesystem  : ファイルシステムのマウントを制御
  • systemd:mariadb : MariaDBを制御
各リソースエージェントの使用方法は、以下コマンドで確認できる。

# pcs resource describe <リソースエージェント>

まずは仮想IPアドレスの設定を行う。付与するipアドレス・サブネットマスク・NICを指定している。また、interval=30sとして監視間隔を30秒に変更している。

※片方のノードで実施
# pcs resource create VirtualIP ocf:heartbeat:IPaddr2 ip=192.168.11.115 cidr_netmask=24 nic=ens192 op monitor interval=30s

次に共有ディスクとして作成したファイルシステム「/dev/sharevg/lv001」のマウントの設定を行う。マウントするデバイス・マウントポイント・ファイルシステムタイプを指定している。

※片方のノードで実施
# pcs resource create ShareDir ocf:heartbeat:Filesystem device=/dev/sharevg/lv001 directory=/share fstype=xfs

最後にMariaDBの設定となる。こちらはシンプルに以下コマンドで設定するだけでよい。

※片方のノードで実施
# pcs resource create MariaDB systemd:mariadb

上記3つのリソースは起動・停止の順番を考慮する必要がある。
  • 起動:「仮想IPアドレス」→「ファイルシステム」→「MariaDB」
  • 停止:「MariaDB」→「ファイルシステム」→「仮想IPアドレス」
この順序を制御するために、リソースの順序を付けてグループ化した「リソースグループ」を作成する。

※片方のノードで実施
# pcs resource group add rg01 VirtualIP ShareDir MariaDB

以上でリソース設定が完了となるので、クラスターの設定を確認してみる。

※片方のノードで実施
# pcs status
------------------------------
Cluster name: cluster2
WARNING: no stonith devices and stonith-enabled is not false
Stack: corosync
Current DC: t1114cent (version 1.1.18-11.el7_5.3-2b07d5c5a9) - partition with quorum
Last updated: Thu Aug 30 23:36:40 2018
Last change: Thu Aug 30 23:36:39 2018 by root via cibadmin on t1113cent

2 nodes configured
3 resources configured

Online: [ t1113cent t1114cent ]

Full list of resources:

 Resource Group: rg01
     VirtualIP  (ocf::heartbeat:IPaddr2):       Stopped
     ShareDir   (ocf::heartbeat:Filesystem):    Stopped
     MariaDB    (systemd:mariadb):      Stopped

Daemon Status:
  corosync: active/disabled
  pacemaker: active/disabled
  pcsd: active/enabled
------------------------------

2. クラスター起動

設定が完了したので、クラスターの起動を行う。各リソースが「Started」となっていれば問題ない。

※片方のノードで実施
# pcs cluster start --all
------------------------------
t1114cent: Starting Cluster...
t1113cent: Starting Cluster...
------------------------------

起動後のステータスを確認。

※片方のノードで実施
# pcs status
------------------------------
Cluster name: cluster2
Stack: corosync
Current DC: t1114cent (version 1.1.18-11.el7_5.3-2b07d5c5a9) - partition with quorum
Last updated: Thu Aug 30 23:40:06 2018
Last change: Thu Aug 30 23:38:42 2018 by root via cibadmin on t1113cent

2 nodes configured
3 resources configured

Online: [ t1113cent t1114cent ]

Full list of resources:

 Resource Group: rg01
     VirtualIP  (ocf::heartbeat:IPaddr2):       Started t1113cent
     ShareDir   (ocf::heartbeat:Filesystem):    Started t1113cent
     MariaDB    (systemd:mariadb):      Started t1113cent

Daemon Status:
  corosync: active/disabled
  pacemaker: active/disabled
  pcsd: active/enabled
------------------------------

クラスターのハートビートが二重化されていることも確認しておこう。今回の場合、192.168.11.113と192.168.55.113の2つのIPアドレスが登録されており、「no faults (エラーなし)」となっていることが確認できる。

※片方のノードで実施
# corosync-cfgtool -s
------------------------------
Printing ring status.
Local node ID 1
RING ID 0
        id      = 192.168.11.113
        status  = ring 0 active with no faults
RING ID 1
        id      = 192.168.55.113
        status  = ring 1 active with no faults
------------------------------

次回予告

これでクラスターの作成が完了した。次回は実際に疑似障害を発生させてクラスターのフェイルオーバーの動きを確認することにする。

★次回はこちら↓

CentOS 7 + Pacemaker + CorosyncでMariaDBをクラスター化する③ (障害試験編)
https://tech-mmmm.blogspot.com/2018/12/centos-7-pacemaker-corosyncmariadb.html

0 件のコメント:

コメントを投稿

人気の投稿