ここでは作ったクラスターの仮想IP(リソース名:VIP)を「192.168.0.102/24」としている.
外から見てクラスターが提供するサービスの宛先IPって感じ
っで設定する.
[root@ha01 ~]# pcs resource create VIP ocf:heartbeat:IPaddr ip=192.168.0.102 cidr_netmask=24 op monitor interval=10s
(確認)
[root@ha01 ~]# pcs resource show
VIP (ocf::heartbeat:IPaddr): Started ha01-1-heartbeat
[root@ha01 ~]#
「ocf:heartbeat:IPaddr」はリソースの枠組みの一つで、「/lib/ocf/resource.d/」に予め用意されている
コマンド「pcs resource agents ocf:heartbeat」「pcs resource agents ocf:pacemaker」でどのような枠組みがあるかが見れます
実際にipアドレスも付与された. 本体のIPアドレス[192.168.0.100]以外にクラスターの仮想IP[192.168.0.102]が付与されている
[root@ha01 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
(略
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:d5:dc:17 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.100/24 brd 192.168.0.255 scope global noprefixroute dynamic ens32
valid_lft 38759sec preferred_lft 38759sec
inet 192.168.0.102/24 brd 192.168.0.255 scope global secondary ens32 <---- 追加された仮想IP
valid_lft forever preferred_lft forever
(略
3: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:d5:dc:21 brd ff:ff:ff:ff:ff:ff
inet 10.10.0.1/24 brd 10.10.0.255 scope global noprefixroute ens192
(略
[root@ha01 ~]#
次にこのリソース「VIP」をha02側に渡してみる
[root@ha01 ~]# ip addr |grep 192.168.0.102
inet 192.168.0.102/24 brd 192.168.0.255 scope global secondary ens32
[root@ha01 ~]# pcs resource move VIP ha02-1-heartbeat
(確認)
[root@ha01 ~]# ip addr |grep 192.168.0.102 | wc -l
0
[root@ha01 ~]#
ha02側でip addrコマンドを実行して 192.168.0.102 が移ったことを確認します
そしてまた元に戻す
[root@ha01 ~]# pcs resource move VIP ha01-1-heartbeat
次に一応手動で片方のマシンをクラスター構成として止めてみる. フェイルオーバーを起こさせてipが移るかのテストになる
[root@ha01 ~]# pcs cluster status
Cluster Status:
Stack: corosync
Current DC: ha01-1-heartbeat (version 1.1.21-4.el7-f14e36fd43) - partition with quorum
Last updated: Mon Jun 1 05:08:02 2020
Last change: Mon Jun 1 04:51:20 2020 by root via cibadmin on ha01-1-heartbeat
2 nodes configured
1 resource configured
PCSD Status:
ha02-1-heartbeat: Online
ha01-1-heartbeat: Online
[root@ha01 ~]# pcs cluster stop ha01-1-heartbeat <--- これで ha01側を停止
ha01-1-heartbeat: Stopping Cluster (pacemaker)...
ha01-1-heartbeat: Stopping Cluster (corosync)...
[root@ha01 ~]# pcs cluster status
Error: cluster is not currently running on this node
[root@ha01 ~]# ip addr |grep 192.168.0.102 | wc -l
0
[root@ha01 ~]#
そしてha02側では
[root@ha02 ~]# ip addr |grep 192.168.0.102
inet 192.168.0.102/24 brd 192.168.0.255 scope global secondary ens32
[root@ha02 ~]#
とipが継承された
戻すにはha01のクラスターを起動させる. すると自動的にVIPが戻るみたい
[root@ha01 ~]# pcs cluster start ha01-1-heartbeat
ha01-1-heartbeat: Starting Cluster (corosync)...
ha01-1-heartbeat: Starting Cluster (pacemaker)...
[root@ha01 ~]# ip addr |grep 192.168.0.102 | wc -l
1
[root@ha01 ~]#