2015年10月31日土曜日

[CentOS7] Pacemaker のリソースを登録する(Apacheのクラスタ)


以前書いた記事で、CentOS7にPacemaker+Corosyncをインストールしました。

今回は、下記のリソースを使用して、Apacheのクラスタ(Active/Standby) を試してみます。

  • VIPCheck
    一番最初に起動させてVIPに疎通できるかチェックし、疎通できた場合は後続のリソースを起動しないようにします。(スプリットブレインの防止)
  • IPaddr2
    仮想IPアドレス(VIP)を作成します。
  • apache
    apache を起動します。
  • ping
    ネットワークを監視して、デフォルトGWに疎通できるサーバでリソースが起動するようにします。

ping 以外のリソースは同一グループ(WebGroup)に所属させることで、一緒に行動するようにします。VIPCheck/IPaddr2/apacheは常に同じサーバ(Active)で動くようにします。
ping は Active/Standby の両方で動かします。

構成情報は以下のとおり
  • pm01: 10.1.0.71
  • pm02: 10.1.0.72
  • vip: 10.1.0.70
  • デフォルトGW: 10.1.0.254


1.VIPCheck の設定


VIPCheckは、下記URLで配布しているので、ソース(シェルスクリプト)を入手します。
pm01 と pm02 に VIPCheck を配置します。私はコピペしました。
[root@pm01 ~]# cd /usr/lib/ocf/resource.d/
[root@pm01 resource.d]# mkdir myres
[root@pm01 resource.d]# vi myres/VIPCheck
[root@pm01 resource.d]# chmod 755 myres/VIPCheck
[root@pm01 resource.d]# ls -l myres/VIPCheck
-rwxr-xr-x 1 root root 5463 10月 31 20:30 myres/VIPCheck
[root@pm02 ~]# cd /usr/lib/ocf/resource.d/
[root@pm02 resource.d]# mkdir myres
[root@pm02 resource.d]# vi myres/VIPCheck
[root@pm02 resource.d]# chmod 755 myres/VIPCheck
[root@pm02 resource.d]# ls -l myres/VIPCheck
-rwxr-xr-x 1 root root 5463 10月 31 20:30 myres/VIPCheck
以下のようにリソースを登録します。"--group" でリソースを所属させるグループを指定しています。グループに追加した順番で起動するようになります。
[root@pm01 ~]# pcs resource create vipcheck_res ocf:myres:VIPCheck target_ip=10.1.0.70 count=1 wait=10 --group WebGroup
stop と monitor は不要なので削除します。
[root@pm01 ~]# pcs resource op remove vipcheck_res stop
[root@pm01 ~]# pcs resource op remove vipcheck_res monitor
start のパラメータを変更したいので、一旦削除して追加します。
[root@pm01 ~]# pcs resource op remove vipcheck_res start
[root@pm01 ~]# pcs resource op add vipcheck_res start interval=0s timeout=90s on-fail=restart start-delay=4s

2.VIPの設定


pm01とpm02のNICは以下のように eth0 という名前にしています。
[root@pm01 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 4a:73:98:ab:45:82 brd ff:ff:ff:ff:ff:ff
    inet 10.1.0.71/32 brd 10.1.0.71 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::4873:98ff:feab:4582/64 scope link
       valid_lft forever preferred_lft forever
[root@pm02 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether ca:f9:d7:75:bd:8b brd ff:ff:ff:ff:ff:ff
    inet 10.1.0.72/32 brd 10.1.0.72 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::c8f9:d7ff:fe75:bd8b/64 scope link
       valid_lft forever preferred_lft forever
eth0に仮想IPアドレスを設定します。
以下のようにリソースを登録します。
[root@pm01 ~]# pcs resource create vip_res ocf:heartbeat:IPaddr2 nic=eth0 ip=10.1.0.70 cidr_netmask=24 --group WebGroup

3.Apacheの設定


Apacheは、server-status が使用できるように設定します。
pm01、pm02の/etc/httpd/conf.d/status.conf に以下の内容を記述します。
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from localhost
</Location>
Apacheは、Pacemakerで起動/停止するので、OSの自動起動/停止はOFFにします。
[root@pm01 ~]# systemctl list-unit-files -t service | grep httpd
httpd.service                               disabled
[root@pm02 ~]# systemctl list-unit-files -t service | grep httpd
httpd.service                               disabled
以下のようにリソースを登録します。
[root@pm01 ~]# pcs resource create httpd_res apache configfile="/etc/httpd/conf/httpd.conf" statusurl="http://127.0.0.1/server-status" --group WebGroup

4.ping の設定


以下のようにリソースを登録します。 "--clone" を指定することで、クラスタの全ノードで起動するようになります。
[root@pm01 ~]# pcs resource create ping ocf:pacemaker:ping dampen=5s multiplier=1000 host_list=10.1.0.254 --clone
デフォルトGWに疎通可能なサーバで WebGrop のリソースが起動するように設定します。
[root@pm01 ~]# pcs constraint location WebGroup rule score=-INFINITY pingd lt 1 or not_defined pingd

5.自動フェイルバックを無効にする


自動フェイルバックを無効にし、リソース異常時に同一サーバでリソースを再起動する回数を1回にします。
[root@pm01 ~]# pcs resource defaults resource-stickiness=INFINITY migration-threshold=1

6.pm01 が優先して Active になるようにする


pm01/pm02を同時に起動した場合などは、pm01が優先して Activeになるように設定します。
[root@pm01 ~]# pcs constraint location WebGroup prefers pm01=50

7.確認


設定が成功していれば、以下のようにリソースが起動します
[root@pm01 resource.d]# pcs status
Cluster name: cluster_test
Last updated: Sat Oct 31 22:41:27 2015          Last change: Sat Oct 31 22:41:23 2015 by root via cibadmin on pm01
Stack: corosync
Current DC: pm02 (version 1.1.13-a14efad) - partition with quorum
2 nodes and 5 resources configured

Online: [ pm01 pm02 ]

Full list of resources:

 Resource Group: WebGroup
     vipcheck_res       (ocf::myres:VIPCheck):  Started pm01
     vip_res    (ocf::heartbeat:IPaddr2):       Started pm01
     httpd_res  (ocf::heartbeat:apache):        Started pm01
 Clone Set: ping-clone [ping]
     Started: [ pm01 pm02 ]

PCSD Status:
  pm01: Online
  pm02: Online

Daemon Status:
  corosync: active/disabled
  pacemaker: active/disabled
  pcsd: active/enabled
設定内容は以下のようにして確認できます。
[root@pm01 resource.d]# pcs config
Cluster Name: cluster_test
Corosync Nodes:
 pm01 pm02
Pacemaker Nodes:
 pm01 pm02

Resources:
 Group: WebGroup
  Resource: vipcheck_res (class=ocf provider=myres type=VIPCheck)
   Attributes: target_ip=10.1.0.70 count=1 wait=10
   Operations: start timeout=90s on-fail=restart interval=0s start-delay=4s (vipcheck_res-name-start-interval-0s-on-fail-restart-start-delay-4s-timeout-90s)
  Resource: vip_res (class=ocf provider=heartbeat type=IPaddr2)
   Attributes: nic=eth0 ip=10.1.0.70 cidr_netmask=24
   Operations: start interval=0s timeout=20s (vip_res-start-timeout-20s)
               stop interval=0s timeout=20s (vip_res-stop-timeout-20s)
               monitor interval=10s timeout=20s (vip_res-monitor-interval-10s)
  Resource: httpd_res (class=ocf provider=heartbeat type=apache)
   Attributes: configfile=/etc/httpd/conf/httpd.conf statusurl=http://127.0.0.1/server-status
   Operations: start interval=0s timeout=40s (httpd_res-start-timeout-40s)
               stop interval=0s timeout=60s (httpd_res-stop-timeout-60s)
               monitor interval=10 timeout=20s (httpd_res-monitor-interval-10)
 Clone: ping-clone
  Resource: ping (class=ocf provider=pacemaker type=ping)
   Attributes: dampen=5s multiplier=1000 host_list=10.1.0.254
   Operations: start interval=0s timeout=60 (ping-start-timeout-60)
               stop interval=0s timeout=20 (ping-stop-timeout-20)
               monitor interval=10 timeout=60 (ping-monitor-interval-10)

Stonith Devices:
Fencing Levels:

Location Constraints:
  Resource: WebGroup
    Enabled on: pm01 (score:50) (id:location-WebGroup-pm01-50)
    Constraint: location-WebGroup
      Rule: score=-INFINITY boolean-op=or  (id:location-WebGroup-rule)
        Expression: pingd lt 1  (id:location-WebGroup-rule-expr)
        Expression: not_defined pingd  (id:location-WebGroup-rule-expr-1)
Ordering Constraints:
Colocation Constraints:

Cluster Properties:
 cluster-infrastructure: corosync
 cluster-name: cluster_test
 dc-version: 1.1.13-a14efad
 have-watchdog: false
 no-quorum-policy: ignore
 stonith-enabled: false



次回は、F/Oさせてみたり、リソース関連のpcsコマンドを試してみたいと思います。



2015年10月24日土曜日

[VirtualBox5] CentOS6インストール後の設定

VirtualBox5 で CentOS-6.7-x86_64-minimal.iso を使って仮想マシンを作成してみた。

仮想マシン作成後に行った VirtualBox 関連の作業は、以下のとおり

1.ネットワーク設定


仮想マシンのネットワークはブリッジにしました。
仮想マシンのネットワークについては、下記URLのページが参考になります。
CentOSのインストール直後は、ネットワークが使えませんでした。
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 08:00:27:13:10:2d brd ff:ff:ff:ff:ff:ff
/etc/sysconfig/network-scripts/ifcfg-eth0 をみると ONBOOT が "no" になっていたので、yes に修正しました。
DEVICE=eth0
HWADDR=08:00:27:13:10:2D
TYPE=Ethernet
UUID=a3f14be7-d818-4b1b-807b-755f2edd085c
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
ネットワークを再起動したら、DHCPでIPアドレスが割り当てられて、使えるようになりました。
[root@localhost ~]# service network restart
インターフェース eth0 を終了中:                            [  OK  ]
ループバックインターフェースを終了中                       [  OK  ]
ループバックインターフェイスを呼び込み中                   [  OK  ]
インターフェース eth0 を活性化中:
eth0 のIP情報を検出中... 完了。
                                                           [  OK  ]
[root@localhost ~]# ip a
1: lo: <loopback> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <broadcast> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:13:10:2d brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.40/24 brd 192.168.1.255 scope global eth0
    inet6 fe80::a00:27ff:fe13:102d/64 scope link tentative
       valid_lft forever preferred_lft forever
[root@localhost ~]#

2.Guest Addition のインストール


Guest Addition をインストールすると、いろいろと便利な機能を使えるようになります。
詳しくは、下記URLを参照。
まず、VirrtualBoxで Guest Additions の isoイメージを仮想マシンに挿入します。
[デバイス] > [Guest Additions CDイメージの挿入]を選択します。



仮想マシンにログインして、マウントします。 /dev/cdrom がない場合は、 /dev/sr0 でマウントします。
[root@localhost ~]# mount /dev/cdrom /mnt
mount: ブロックデバイス /dev/sr0 は書き込み禁止です、読込み専用でマウントします
インストーラを実行すると、以下のようにエラーになりました。
[root@localhost mnt]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.6 Guest Additions for Linux............
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
The gcc utility was not found. If the following module compilation fails then
this could be the reason and you should try installing it.

The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.
The missing package can be probably installed with
yum install kernel-devel-2.6.32-573.el6.x86_64

Building the main Guest Additions module                   [失敗]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the Guest Additions              [  OK  ]
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.

gcc, kernel-devel, perl が必要みたいなので、インストールします。
[root@localhost mnt]# yum install perl gcc kernel-devel-2.6.32-573.el6.x86_64
再度、インストーラーを実行したら以下のようになりました。
[root@localhost mnt]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.6 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 5.0.6 of VirtualBox Guest Additions...
Stopping VirtualBox Additions                              [  OK  ]
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module                   [  OK  ]
Building the shared folder support module                  [  OK  ]
Building the OpenGL support module                         [失敗]
(Look at /var/log/vboxadd-install.log to find out what went wrong. The module is not built but the others are.)
Doing non-kernel setup of the Guest Additions              [  OK  ]
Starting the VirtualBox Guest Additions                    [  OK  ]
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.


GUI は使用しないので OpenGL の失敗は無視しました。

3.ACPIシャットダウンをつかえるようにする


初期状態では、ACPIシャットダウンがつかえませんでした。
acipd をインストールして、起動し、自動起動がONになっていることを確認します。
[root@localhost ~]# yum install acpid
[root@localhost ~]# service acpid start
[root@localhost ~]# chkconfig --list | grep acpid
acpid           0:off   1:off   2:on    3:on  4:on  5:on        6:off
これで、[仮想マシン] > [ACPIシャットダウン]でシャットダウンできるようになります。



4.共有フォルダを設定する


ホストマシンと仮想マシンの間でファイルを共有できるようにします。
この機能を使用するには GustAddition のインストールが必要です。

まず、ホストマシンの Windows にフォルダを作成します。
今回は、フォルダ名を vmshare としました。

VirtualBox で[仮想マシン] > [設定] で設定画面を開き、下図のように 共有フォルダの設定をします。



これで、仮想マシンを再起動すると、ホストマシンのWindows と仮想マシンの CentOSでファイルを共有できるようになります。
上記設定では、仮想マシンが起動すると、自動的にマウントされます。
マウント場所 /media/sf_<フォルダー名> になります。
[root@localhost ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmshare on /media/sf_vmshare type vboxsf (gid=498,rw)
[root@localhost ~]# ls -l /media
合計 0
drwxrwx---. 1 root vboxsf 0 10月 23 22:17 2015 sf_vmshare

ちなみに、ネットワーク設定がNGで通信できない場合でも、共有フォルダでファイルの共有はできます。

5.仮想マシンをクローンした後のネットワーク設定


VirtualBox では、仮想マシンの複製をつくることができます。



同じ MACアドレスのマシンを複数起動すると通信できなくなるので、1台をクローンして複数のマシンを起動したい場合は、上記のように MACアドレスを初期化します。

クローンしたマシンの初期状態では、ネットワークが使用できません。
以下のように、NIC が eth1 として認識されます。
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 08:00:27:ac:86:bd brd ff:ff:ff:ff:ff:ff
/etc/udev/rules.d/70-persistent-net.rules を見ると、以下のとおり。
クローンしたマシンの新しいMACアドレスが eth1 に割り当てられています。
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:13:10:2d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:ac:86:bd", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

自分のMACアドレスを eth0 に割り当てるように修正します。
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100e (e1000)
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:13:10:2d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:ac:86:bd", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

/etc/sysconfig/network-scripts/ifcfg-eth0 でも新しいMACアドレスを使うように修正します。 以下のように、UUID と HWADDR をコメントアウトします。
DEVICE=eth0
#HWADDR=08:00:27:13:10:2D
TYPE=Ethernet
#UUID=a3f14be7-d818-4b1b-807b-755f2edd085c
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
これで、仮想マシンを再起動するとネットワークがつかえるようになります。
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:ac:86:bd brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.41/24 brd 192.168.1.255 scope global eth0
    inet6 2408:210:d340:c000:a00:27ff:feac:86bd/64 scope global dynamic
       valid_lft 2591814sec preferred_lft 604614sec
    inet6 fe80::a00:27ff:feac:86bd/64 scope link
       valid_lft forever preferred_lft forever







2015年10月18日日曜日

[CentOS7] Pacemaker + corosync のインストール


CentOS7 に Pacemaker(corosync) をインストールして基本動作を確認します。

Pacemaker(corosync)のインストール、設定については、以下のページを参考にしました。
特に、RedHatのマニュアルが参考になりました。

検証環境は以下のとおり。

[環境]
  • サーバ1
    • OS: CentOS7.0
    • IPアドレス: 10.1.0.71
    • ホスト名: mysql01
  • サーバ2
    • OS: CentOS7.0
    • IPアドレス: 10.1.0.72
    • ホスト名: mysql02

1.Pacemakerのインストール


CentOS7.0の標準レポジトリから yum でpacemaker、corosync、pcs をインストールします。
「サーバ1」と「サーバ2」にインストールします。
# yum install pacemaker corosync pcs
pcs はクラスタ管理用のCLIツールです。
pcsを使用したクラスタ操作は、クラスタメンバのサーバであれば、どれか1サーバで実行すれば良いので、ここでは、基本的に「サーバ1」で pcs コマンドを実行するようにしています。

2.OS設定


「サーバ1」と「サーバ2」でSELinuxとファイヤーウォールが無効になっていることを確認します。
# getenforce
Disabled
# systemctl list-unit-files -t service | grep firewalld
firewalld.service                           disabled
# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
クラスタ設定ではホスト名を使用したいので、「サーバ1」と「サーバ2」の /etc/hosts にホスト名を登録します。
10.1.0.71 mysql01
10.1.0.72 mysql02
「サーバ1」と「サーバ2」の双方向で疎通を確認します。
# ping -c1 mysql01(または、mysql02)
pcsでクラスタの設定を行うときに、ssh を使用します。「サーバ1」と「サーバ2」の双方向でsshでログインできることを確認します。
# ssh -l root mysql01(または、mysql02)
pcsでコマンドを実行するときに hacluster ユーザを使用しますが、初期状態ではパスワードが設定されていないので、パスワードを設定します。「サーバ1」と「サーバ2」で実施します。
# passwd hacluster

3.クラスタ設定


pcs でクラスタの設定を行います。ます、pcsd を起動し、自動起動を有効にします。
# systemctl start pcsd
# systemctl enable pcsd
「サーバ1」と「サーバ2」の信頼関係を設定します。hacluster ユーザで認証できるようにします。[Password] は、上記2で設定したパスワードを指定します。「サーバ1」だけで実行します。
# pcs cluster auth mysql01 mysql02
Username: hacluster
Password:
mysql01: Authorized
mysql02: Authorized
クラスタ名を "cluster_mysql" として、mysql01 と mysql02 でクラスタをセットアップします。「サーバ1」だけで実行します。
# pcs cluster setup --name cluster_mysql mysql01 mysql02
Shutting down pacemaker/corosync services...
Redirecting to /bin/systemctl stop  pacemaker.service
Redirecting to /bin/systemctl stop  corosync.service
Killing any remaining services...
Removing all cluster configuration files...
mysql01: Succeeded
mysql02: Succeeded
このコマンドの実行により、「サーバ1」と「サーバ2」に /etc/corosync/corosync.conf が作成されます。内容は以下のとおり。
# cat /etc/corosync/corosync.conf
totem {
version: 2
secauth: off
cluster_name: cluster_mysql
transport: udpu
}

nodelist {
  node {
        ring0_addr: 10.1.0.71
        nodeid: 1
       }
  node {
        ring0_addr: 10.1.0.72
        nodeid: 2
       }
}

quorum {
provider: corosync_votequorum
two_node: 1
}

logging {
to_syslog: yes
}
この設定だとPacemakerのログは /var/log/messages に出力されます。/etc/corosync に設定のサンプルファイルがあるので、logging の設定を変更して、Pacemaker用のログファイルに出力するようにしたほうが見やすいと思います。
直接、このファイルを編集して設定変更できます。設定変更後はクラスタを再起動します。

4.クラスタ起動と状態確認


「サーバ1」と「サーバ2」のクラスタ(pacemaker + corosync)を起動します。
下記コマンドを「サーバ1」で実行します。
# pcs cluster start --all
mysql01: Starting Cluster...
mysql02: Starting Cluster...
クラスタの自動起動/停止は、pacemaker + corocyncを自動起動/停止するように「サーバ1」と「サーバ2」に設定します。
なお、corosync の自動起動に失敗する場合があるようです。こちら のページの最後のほうを参考にしてください。
私の環境では問題なく起動しました。
# systemctl enable pacemaker
# systemctl enable corosync
クラスタのプロセスは以下のとおり。
「サーバ1」と「サーバ2」でpacemakerとcorosyncが起動します。
# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
~ 省略 ~
root     23266     1  0 20:56 ?        00:00:00 /bin/sh /usr/lib/pcsd/pcsd start
root     23270 23266  0 20:56 ?        00:00:00 /bin/bash -c ulimit -S -c 0 >/dev/null 2>&1 ; /usr/bin/ruby -I/usr/lib/pcsd /usr/lib/pcsd/ssl.
root     23271 23270  0 20:56 ?        00:00:01 /usr/bin/ruby -I/usr/lib/pcsd /usr/lib/pcsd/ssl.rb
root     23762     2  0 21:05 ?        00:00:00 [kworker/0:0]
root     23995     2  0 21:07 ?        00:00:00 [kworker/1:0]
root     24950     1  2 21:24 ?        00:00:00 corosync
root     24965     1  0 21:24 ?        00:00:00 /usr/sbin/pacemakerd -f
haclust+ 24966 24965  0 21:24 ?        00:00:00 /usr/libexec/pacemaker/cib
root     24967 24965  0 21:24 ?        00:00:00 /usr/libexec/pacemaker/stonithd
root     24968 24965  0 21:24 ?        00:00:00 /usr/libexec/pacemaker/lrmd
haclust+ 24969 24965  0 21:24 ?        00:00:00 /usr/libexec/pacemaker/attrd
haclust+ 24970 24965  0 21:24 ?        00:00:00 /usr/libexec/pacemaker/pengine
haclust+ 24971 24965  0 21:24 ?        00:00:00 /usr/libexec/pacemaker/crmd
root     25015   626  0 21:25 ?        00:00:00 sleep 60
root     25017  2472  0 21:25 pts/0    00:00:00 ps -ef
クラスタの状態を確認します。「サーバ1」で実行します。
# pcs status cluster
Cluster Status:
 Last updated: Mon May  4 11:19:05 2015
 Last change: Mon May  4 10:50:30 2015
 Stack: corosync
 Current DC: mysql01 (1) - partition with quorum
 Version: 1.1.12-a14efad
 2 Nodes configured
 0 Resources configured
クラスタメンバ(ノード)の状態を確認します。「サーバ1」で実行します。
# pcs status nodes
Pacemaker Nodes:
 Online: mysql01 mysql02
 Standby:
 Offline:
# corosync-cmapctl | grep members
runtime.totem.pg.mrp.srp.members.1.config_version (u64) = 0
runtime.totem.pg.mrp.srp.members.1.ip (str) = r(0) ip(10.1.0.71)
runtime.totem.pg.mrp.srp.members.1.join_count (u32) = 1
runtime.totem.pg.mrp.srp.members.1.status (str) = joined
runtime.totem.pg.mrp.srp.members.2.config_version (u64) = 0
runtime.totem.pg.mrp.srp.members.2.ip (str) = r(0) ip(10.1.0.72)
runtime.totem.pg.mrp.srp.members.2.join_count (u32) = 1
runtime.totem.pg.mrp.srp.members.2.status (str) = joined
# pcs status corosync

Membership information
----------------------
    Nodeid      Votes Name
         1          1 mysql01 (local)
         2          1 mysql02
クラスタ、ノード、リソース、デーモンの状態を確認します。「サーバ1」で実行します。
# pcs status
Cluster name: cluster_mysql
Last updated: Mon May  4 12:29:19 2015
Last change: Mon May  4 11:01:42 2015
Stack: corosync
Current DC: mysql01 (1) - partition with quorum
Version: 1.1.12-a14efad
2 Nodes configured
0 Resources configured


Online: [ mysql01 ]
OFFLINE: [ mysql02 ]

Full list of resources:


PCSD Status:
  mysql01: Online
  mysql02: Online

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

5.クラスタ設定のチェック


クラスタ設定をチェックします。「サーバ1」で実行します。
# 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
STONITHの設定をしていないのでエラーになっています。STONITHは、Pacemakerがスプリットブレインを検知したときに強制的にH/Wを電源OFF/ONする機能だそうです。STONISHについては、以下のページが詳しいです。
STONISH はデフォルトで有効になっていますが、検証用の仮想化環境では使用しないので無効にします。
# pcs property set stonith-enabled=false
エラーにはなっていませんが、クォーラムの設定も変更します。クォーラムについては、以下が詳しいです。
今回は2台構成なので、スプリットブレインが発生しても quorum が特別な動作を行わないように無効にします。
# pcs property set no-quorum-policy=ignore
パラメータを確認します。
# pcs property
Cluster Properties:
 cluster-infrastructure: corosync
 cluster-name: cluster_mysql
 dc-version: 1.1.12-a14efad
 have-watchdog: false
 no-quorum-policy: ignore
 stonith-enabled: false
クラスタの再起動は不要です。変更は即時反映されます。

6.クラスタ操作


pcsコマンドでクラスタを操作してみます。ここでは、「サーバ1」でpcsコマンドを実行します。

クラスタを停止する場合は、以下のようにします。
# pcs cluster stop --all
mysql01: Stopping Cluster (pacemaker)...
mysql02: Stopping Cluster (pacemaker)...
mysql02: Stopping Cluster (corosync)...
mysql01: Stopping Cluster (corosync)...
クラスタを再起動したい場合は、stop してから start します。
# pcs cluster stop --all && pcs cluster start --all
「サーバ2」 をスタンバイにして、状態を確認してみます。
# pcs cluster standby mysql02
# pcs status nodes
Pacemaker Nodes:
 Online: mysql01
 Standby: mysql02
 Offline:
「サーバ2」 をオンラインに戻します。
# pcs cluster unstandby mysql02
# pcs status nodes
Pacemaker Nodes:
 Online: mysql01 mysql02
 Standby:
 Offline:
「サーバ2」 だけ停止します。
# pcs cluster stop mysql02
mysql02: Stopping Cluster (pacemaker)...
mysql02: Stopping Cluster (corosync)...
# pcs status nodes
Pacemaker Nodes:
 Online: mysql01
 Standby:
 Offline: mysql02