みなさん、こんにちは。コンテンツ・メディア第1事業部インフラ課の藤本佳世です。
今回は、Pacemaker+Corosyncについてお話しします。
今までは、Heartbeatを使っていたのですが、サーバリプレースに伴い、最新バージョンで推奨されているPacemaker+Corosyncを構築しました。まずは、インストールの部分をお話ししたいと思います。
Pacemakerとは
オープンソースソフトウェアとして開発されている、HAクラスタソフトのこと(Heartbeat の後継)。
障害を検知したら他のサーバに自動的にフェイルオーバしてくれます。
Corosyncと組み合わせて利用します。
※HAとは、「High Availability」高可用性のこと。
Corosyncとは
ノードの死活監視を行うオープンソースソフトウェア。
Pacemakerと組み合わせて、クラスタシステムを構成します。
フリューでの利用について
主に、データベースサーバでPacemaker+Corosyncを採用しています。
サーバ(master)に仮想VIPがセカンダリIPとして割り当てられており、サーバ(master)に障害が発生した際、10秒以内(弊社環境)でサーバ(slave)に仮想VIPが付与され、masterとして稼働します。
以前のHeartbeatよりも、Corosyncの方が切替の時間が早いというメリットもあります。
構築した環境
| サーバ名 | OS | Pacemakerバージョン | Corosyncバージョン | IPアドレス | 仮想VIP |
| server1 | CentOS7.4 | 1.1.16.1 | 2.4.2-1 | 192.168.33.28 | 192.168.33.21 |
| server2 | CentOS7.4 | 1.1.16.1 | 2.4.2-1 | 192.168.33.29 |
Pacemaker+Corosyncの構築
LINUX-HA JAPANのドキュメントを参考に進めました。
詳しく手順が書かれているので、この通りに進めるだけです。
yum install -y pacemaker-repo-1.1.16-1.1.el7.x86_64.rpm yum install -y pacemaker-all
インストールの後は、corosync.confを修正します。
cp /etc/corosync/corosync.conf.example /etc/corosync/corosync.conf vim /etc/corosync/corosync.conf
以下のbindnetaddrとquorumの部分を修正しました。
- bindnetaddr:構築するネットワーク環境に合わせて設定
- expected_votes :クラスタを構成するノードの数を設定
# Please read the corosync.conf.5 manual page
totem {
version: 2
# crypto_cipher and crypto_hash: Used for mutual node authentication.
# If you choose to enable this, then do remember to create a shared
# secret with "corosync-keygen".
# enabling crypto_cipher, requires also enabling of crypto_hash.
crypto_cipher: none
crypto_hash: none
# interface: define at least one interface to communicate
# over. If you define more than one interface stanza, you must
# also set rrp_mode.
interface {
# Rings must be consecutively numbered, starting at 0.
ringnumber: 0
# This is normally the *network* address of the
# interface to bind to. This ensures that you can use
# identical instances of this configuration file
# across all your cluster nodes, without having to
# modify this option.
bindnetaddr: 192.168.33.0
# However, if you have multiple physical network
# interfaces configured for the same subnet, then the
# network address alone is not sufficient to identify
# the interface Corosync should bind to. In that case,
# configure the *host* address of the interface
# instead:
# bindnetaddr: 192.168.1.1
# When selecting a multicast address, consider RFC
# 2365 (which, among other things, specifies that
# 239.255.x.x addresses are left to the discretion of
# the network administrator). Do not reuse multicast
# addresses across multiple Corosync clusters sharing
# the same network.
mcastaddr: 239.255.1.1
# Corosync uses the port you specify here for UDP
# messaging, and also the immediately preceding
# port. Thus if you set this to 5405, Corosync sends
# messages over UDP ports 5405 and 5404.
mcastport: 5405
# Time-to-live for cluster communication packets. The
# number of hops (routers) that this ring will allow
# itself to pass. Note that multicast routing must be
# specifically enabled on most network routers.
ttl: 1
}
}
logging {
# Log the source file and line where messages are being
# generated. When in doubt, leave off. Potentially useful for
# debugging.
fileline: off
# Log to standard error. When in doubt, set to no. Useful when
# running in the foreground (when invoking "corosync -f")
to_stderr: no
# Log to a log file. When set to "no", the "logfile" option
# must not be set.
to_logfile: yes
logfile: /var/log/cluster/corosync.log
# Log to the system log daemon. When in doubt, set to yes.
to_syslog: yes
# Log debug messages (very verbose). When in doubt, leave off.
debug: off
# Log messages with time stamps. When in doubt, set to on
# (unless you are only logging to syslog, where double
# timestamps can be annoying).
timestamp: on
logger_subsys {
subsys: QUORUM
debug: off
}
}
quorum {
# Enable and configure quorum subsystem (default: off)
# see also corosync.conf.5 and votequorum.5
provider: corosync_votequorum
expected_votes: 2
two_node: 1
}
続いて、corosync認証鍵ファイルの設定です。
どれか一つのノード上で実行します。
corosync-keygen -l
/etc/corosync配下にauthkey ファイルが生成されます。
作成されたauthkeyファイルをクラスタを構成する全てのノードにコピーします。
scp -p /etc/corosync/authkey root@server2:/etc/corosync/authkey
この後は、pacemakerファイルの設定です。
pacemakerの内部プロセスが故障した場合も、ノード故障として取り扱うようにするため、
以下の設定に変更します。
vim /etc/sysconfig/pacemaker
PCMK_fail_fast=yes
ドキュメントに下記の設定を反映させるために修正が必要と書かれています。
- pacemakerサービス停止時に corosyncサービスも同時に停止させるため
- corosyncプロセス故障時に watchdog 機能を有効にするため
- corosyncの改善により soft_margin オプションは不要となったため
cd /usr/lib/systemd/system systemctl edit corosync.service
[Service] Restart=on-failure RestartSec=70 ExecStartPre= ExecStartPre=/sbin/modprobe softdog
cd /usr/lib/systemd/system systemctl edit pacemaker.service
[Service] ExecStopPost= ExecStopPost=/bin/sh -c 'pidof crmd || killall -TERM corosync'
※ExecStart/Stop は置き換える前に空白にする必要があるので注意してください。
これで完了です。
ドキュメント通り進めるだけなので、簡単に構築できると思います。
いよいよ起動
設定が終わったら、いよいよ起動です。
systemctl start pacemaker
起動確認
crm_mon -D1 Online: [ server1 server2 ]
Onlineになっています!問題なさそうです。
ここまでがインストールの作業です。
次に、仮想VIPやping疎通監視など設定していきますが、詳細は次回説明したいと思います。
crm configureコマンドを使った設定などご紹介する予定なので、お楽しみに。