#author("2020-06-16T21:22:33+00:00","default:sysosa","sysosa")
#author("2020-06-17T10:10:33+00:00","default:sysosa","sysosa")
High Availability(高可用性)
クラスターを組んで片方のノードが都合により停止になっても他のノードが引き継ぎサービスを提供し続ける機構
&size(10){クラスターって言葉は扱いが難しい... HPCにも使うから};

昔windowsServerにて[[windowsServer/wsfc]]を組んでみた. こんな感じなもの.


参照先[[https://linux-ha.osdn.jp/wp/>+https://linux-ha.osdn.jp/wp/]]


リソース追加[[HighAvailability/resource]]
(HAクラスターのサービスにNFSを追加 [[HighAvailability/resource/NFS]] )


***構成 [#d3718428]
CentOS7で &color(magenta){pacemaker-1.1}; と &color(magenta){corosync-2}; で行います.



VMware esxiで作ってます.
|BGCOLOR(YELLOW):マシン名|BGCOLOR(YELLOW):IPアドレス|BGCOLOR(YELLOW):OS|BGCOLOR(YELLOW):system disk|BGCOLOR(YELLOW):shared disk&br;(fencing device)|BGCOLOR(YELLOW):仮想IP|
|ha01&br;(ha01-1-heartbeat)|192.168.0.100&br;(10.10.10.1)|CentOS7.7|8GB|100GB&br;(1GB)|192.168.0.102|
|ha02&br;(ha02-1-heartbeat)|192.168.0.101&br;(10.10.10.2)|~|8GB|~|~|

&size(10){スプリットブレイン対策のため死活確認の&color(orangered){インターコネクト};ネットワークを複数用意すべきかも};
&color(red){*};&size(10){余談: ホスト名へのアンダーバー(_)はRFC952で不許可であるが、OSによっては許容されている};

&color(red){*};&size(10){[[スプリットブレイン>#x66aae76]]対策によっては&color(orangered){インターコネクト};ネットワークは不要かも..};

***Shared disk [#h98bde18]
参照[[VMware/shared]]

***下拵え [#nab11fa2]
grouplist から「High Availability」をインストールします.
「High Availability」をインストールすると pacemaker とその関連のものらが同時にインストールされます.

#code(nonumber){{
[root@ha01 ~]# yum grouplist hidden | less           <--- grouplist を全て見る
 :
Available Environment Groups:
 :
Available Groups:
 :
   High Availability
 :
Done
[root@ha01 ~]#

[root@ha01 ~]# yum groupinfo  "High Availability"    <--- grouplist「High Availability」の中身を確認
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp

Group: High Availability
 Group-Id: ha
 Description: Infrastructure for highly available services and/or shared storage.
 Mandatory Packages:
    pacemaker
 Default Packages:
   +fence-agents-aliyun
   +fence-agents-all
   +fence-agents-aws
   +fence-agents-azure-arm
   +fence-agents-gce
   +omping
   +pacemaker-doc
   +pcs
 Optional Packages:
   awscli
   booth-arbitrator
   booth-site
   resource-agents-aliyun
   sbd
[root@ha01 ~]# yum groupinstall "High Availability"
}}
次に /etc/hosts を整備する
#code(nonumber){{
[root@ha01 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain

192.168.0.100 ha01 ha01.sybyl.local
192.168.0.101 ha02 ha02.sybyl.local

#---- heartbeat ----#
10.10.0.1 ha01-1-heartbeat
10.10.0.2 ha02-1-heartbeat

[root@ha01 ~]#
}}
そして既定で用意されているhigh-availability向けのfirewall設定を読み込ませる.  &size(10){「/usr/lib/firewalld/services/」に定義可能なサービスがある};
#code(nonumber){{
[root@ha01 ~]# firewall-cmd --add-service=high-availability --permanent
[root@ha01 ~]# firewall-cmd --reload
}}
上記は全ノードに施します.

***pcs(Pacemaker Configuration System)でクラスターを構築 [#a2b67b6b]
rpmのDescriptionには
#code(nonumber){{
Description : pcs is a corosync and pacemaker configuration tool.  It permits
            : users to easily view, modify and create pacemaker based clusters.
}}
とある.
初めに「yum groupinfo  "High Availability"」の実行で作られたユーザ「&color(orangered){hacluster};」にパスワードを付与する
#code(nonumber){{
[root@ha01 ~]# id hacluster
uid=189(hacluster) gid=189(haclient) groups=189(haclient)

[root@ha01 ~]# echo hacluster123 | passwd --stdin hacluster   <-- ユーザ[hacluster]のパスワードを「hacluster123」とした
}}
その後に &color(magenta){pcsd.service}; を有効にして稼働させる.
#code(nonumber){{
[root@ha01 ~]# systemctl enable pcsd.service
[root@ha01 ~]# systemctl start pcsd.service
}}
この操作をもう片方の ha02 にも施す

設定が終わったら片方でクラスターのノード間の認証を行う
#code(nonumber){{
[root@ha01 ~]# pcs cluster auth ha01-1-heartbeat   ha02-1-heartbeat -u hacluster -p hacluster123  --force
ha01-1-heartbeat: Authorized
ha02-1-heartbeat: Authorized
[root@ha01 ~]#
}}
この時「/var/lib/pcsd/{tokens,pcs_users.conf}」が作られる.

クラスターを作成する
クラスターを作成する. &size(10){クラスター監視用アドレスを指定する};
#code(nonumber){{
[root@ha01 ~]# pcs cluster setup --name ha ha01-1-heartbeat   ha02-1-heartbeat

Destroying cluster on nodes: ha01-1-heartbeat, ha02-1-heartbeat...
ha01-1-heartbeat: Stopping Cluster (pacemaker)...
ha02-1-heartbeat: Stopping Cluster (pacemaker)...
ha01-1-heartbeat: Successfully destroyed cluster
ha02-1-heartbeat: Successfully destroyed cluster
*サービスLANのIPもクラスター監視用アドレスとして使用するなら
「pcs cluster setup --name ha   ha01,ha01-1-heartbeat   ha02,ha02-1-heartbeat」 と同一ノードのIP(名前)をカンマ(,)で繋げる

Sending 'pacemaker_remote authkey' to 'ha01-1-heartbeat', 'ha02-1-heartbeat'
ha01-1-heartbeat: successful distribution of the file 'pacemaker_remote authkey'
ha02-1-heartbeat: successful distribution of the file 'pacemaker_remote authkey'
Sending cluster config files to the nodes...
ha01-1-heartbeat: Succeeded
ha02-1-heartbeat: Succeeded

Synchronizing pcsd certificates on nodes ha01-1-heartbeat, ha02-1-heartbeat...
ha01-1-heartbeat: Success
ha02-1-heartbeat: Success
Restarting pcsd on the nodes in order to reload the certificates...
ha01-1-heartbeat: Success
ha02-1-heartbeat: Success

[root@ha01 ~]#

[root@ha01 ~]# pcs cluster status
Error: cluster is not currently running on this node

[root@ha01 ~]# pcs cluster start --all
ha01-1-heartbeat: Starting Cluster (corosync)...
ha02-1-heartbeat: Starting Cluster (corosync)...
ha01-1-heartbeat: Starting Cluster (pacemaker)...
ha02-1-heartbeat: Starting Cluster (pacemaker)...

[root@ha01 ~]# pcs cluster status
Cluster Status:
 Stack: unknown
 Current DC: NONE
 Last updated: Sat May 30 11:39:29 2020
 Last change: Sat May 30 11:39:19 2020 by hacluster via crmd on ha01-1-heartbeat
 2 nodes configured
 0 resources configured

PCSD Status:
  ha01-1-heartbeat: Online
  ha02-1-heartbeat: Online

[root@ha01 ~]#
}}
この段階では何もHighAvailabilityなリソース、サービスは登録してません.
単にクラスターの枠組みを作っただけです.

***各種確認 [#c045bcda]
作成したクラスターの様子を確認

双方でcorosync(Corosync Cluster Engine)のノード間通信を確認.
#code(nonumber){{
[root@ha01 ~]# pcs status corosync                  [root@ha02 ~]# pcs status corosync
                                                    
Membership information                              Membership information
----------------------                              ----------------------
    Nodeid      Votes Name                              Nodeid      Votes Name
         1          1 ha01-1-heartbeat (local)               1          1 ha01-1-heartbeat
         2          1 ha02-1-heartbeat                       2          1 ha02-1-heartbeat (local)
[root@ha01 ~]#                                      [root@ha02 ~]#
}}

corosyncのコマンド「corosync-cfgtool」では下記のように確認できる
#code(nonumber){{
[root@ha01 ~]# corosync-cfgtool -s                  [root@ha02 ~]# corosync-cfgtool -s
Printing ring status.                               Printing ring status.
Local node ID 1                                     Local node ID 2
RING ID 0                                           RING ID 0
        id      = 10.10.0.1                                 id      = 10.10.0.2
        status  = ring 0 active with no faults              status  = ring 0 active with no faults
[root@ha01 ~]#                                      [root@ha02 ~]#
}}

そして作られたクラスターでは参加したノードに「/etc/corosync/corosync.conf」が作成されます.
#code(nonumber){{
[root@ha02 corosync]# cat corosync.conf
totem {
    version: 2
    cluster_name: ha
    secauth: off
    transport: udpu
}

nodelist {
    node {
        ring0_addr: ha01-1-heartbeat
        nodeid: 1
    }

    node {
        ring0_addr: ha02-1-heartbeat
        nodeid: 2
    }
}

quorum {
    provider: corosync_votequorum
    two_node: 1
}

logging {
    to_logfile: yes
    logfile: /var/log/cluster/corosync.log
    to_syslog: yes
}
}}
pacemakerのコマンド「crm_verify」でも状態を確認すると下記エラーが報告されている.

***スプリットブレイン [#x66aae76]
ノード間で死活確認がうまく動かずに双方とも「Active」になって仕事しちゃう現象.

その対策の1つとしてSTONITH(Shoot-The-Other-Node-In-The-Head:他ノードを即時強制終了)がある.
ipmiなポート経由で相手を眠らせるとか、
esxi の上で動くのでesxiのコマンド経由で相手を眠らせる方法がある.
「yum search fence-agents」で得られるのがその対策リストらしい.



既定で「STONITHを施す」となっているため下記のようなエラーが発生してしまう.

#code(nonumber){{
[root@ha01 ~]# crm_verify -L -V
   error: unpack_resources:     Resource start-up disabled since no STONITH resources have been defined
   error: unpack_resources:     Either configure some or disable STONITH with the stonith-enabled option
   error: unpack_resources:     NOTE: Clusters with shared data need STONITH to ensure data integrity
Errors found during check: config not valid
[root@ha01 ~]#
}}


だが、今はこの要求されるSTONITHは無視/無効する.



#code(nonumber){{
[root@ha01 ~]# pcs property list --all | grep stonith
 stonith-action: reboot
 stonith-enabled: true
 stonith-max-attempts: 10
 stonith-timeout: 60s
 stonith-watchdog-timeout: (null)

[root@ha01 ~]# pcs property set stonith-enabled=false

(確認)
[root@ha01 ~]# pcs property list --all | grep stonith
 stonith-action: reboot
 stonith-enabled: false
 stonith-max-attempts: 10
 stonith-timeout: 60s
 stonith-watchdog-timeout: (null)

[root@ha01 ~]# crm_verify -L -V    <-- エラー項目が表示されない
[root@ha01 ~]#
}}
&color(red){*};&size(10){この部分の変更がどこに書かれているのかが分からない...};

このSTONITH以外にも「Quorum」を使った方法もあるが、こちらは2ノードクラスターでは使えない.
Quorum: 定足数.  3ノードクラスターで2ノードから「こいつは寝てる」となれば他へリソースが移される感じかな.
#code(nonumber){{
[root@ha01 ~]# pcs property list --all | grep quorum
 no-quorum-policy: stop

[root@ha01 ~]# pcs property set no-quorum-policy=ignore

[root@ha01 ~]# pcs property list --all | grep quorum
 no-quorum-policy: ignore

[root@ha01 ~]#
}}
***再起動 [#hb93fa63]
両ノードを再起動してみた
#code(nonumber){{
[root@ha01 ~]# systemctl list-unit-files | grep pcsd
pcsd.service                                  enabled

[root@ha01 ~]# ps -ef |grep pcsd | grep -v grep
root      1115     1  0 22:11 ?        00:00:01 /usr/bin/ruby /usr/lib/pcsd/pcsd

[root@ha01 ~]#
}}
とpcsdは再起動後も動いているのだが、

#code(nonumber){{
[root@ha01 ~]# pcs cluster status
Error: cluster is not currently running on this node
[root@ha01 ~]#
}}
と動ていない.
っで
#code(nonumber){{
[root@ha01 ~]# pcs cluster start --all
ha01-1-heartbeat: Starting Cluster (corosync)...
ha02-1-heartbeat: Starting Cluster (corosync)...
ha01-1-heartbeat: Starting Cluster (pacemaker)...
ha02-1-heartbeat: Starting Cluster (pacemaker)...
[root@ha01 ~]#
}}
っで動かす.


***参考先 [#lf1afa0c]
[[https://clusterlabs.org/pacemaker/doc/en-US/Pacemaker/1.1/html/Clusters_from_Scratch/index.html]]
[[http://kan3aa.hatenablog.com/category/CentOS]]
[[https://gist.github.com/kogoto/92eef35b28ae632a11f7]]
1

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS