8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

corosync + pacemakerの初期セットアップ

Last updated at Posted at 2017-03-26

corosync + pacemakerの初期セットアップ

はじめに

CentOS6.5上で冗長化構成を組もうとした時に、初めはheartbeat + pacemakerでの構築を考えていたが、ネット上で調べたところどうもcorosyncの方が良さそうなので、corosync + pacemakerで検討してみることにした。

  • heartbeatの開発は縮小してきており、メインストリームはcorosyncに変わりつつある
  • corosyncはredhat主導で開発が進められており、同じくredhat主導のpacemakerとの親和性も高そう。
  • ネット上の記事もcorosyncの方が豊富。

実行環境

  • ハイパーバイザー : VirtualBox 5.0.0r101573
  • ホストOS : MacOS Sierra 10.12.3
  • ゲストOS : CentOS 6.5
    • corosync1-cent65 : 192.168.33.10
    • corosync2-cent65 : 192.168.33.11
    • VIP : 192.168.33.12
  • その他 : Vagrant 1.7.4

インストール (corosync1-cent65,corosync2-cent65両方で実施)

まず、モジュールをインストールする。

corosync,pacemaker以外にpcs,cmanのインストールが必要。

  • pcs : クラスタ制御用のコマンドラインインターフェース(crmコマンドみたいなもの。最近はpcsが主流らしい)
  • cman : クラスタマネージャ(これがないとpcsコマンド実行時にエラーとなる)

[root@corosync1-cent65 ~]# yum -y install corosync pacemaker pcs cman
※ 私の環境ではcorosyncは標準で同梱されていたが念のため。。

corosync.conf設定 (corosync1-cent65,corosync2-cent65両方で実施)

corosync.confの設定が必要。
サンプルがあるので今回はコピーして必要最小限の設定変更のみ実施。

[root@corosync1-cent65 ~]# cp /etc/corosync/corosync.conf.example /etc/corosync/corosync.conf
[root@corosync1-cent65 ~]# sed -i -e "/^compatibility: whitetank$/a aisexec {\n\tuser: root\n\tgroup: root\n}\n\nservice {\n\tname: pacemaker\n\tver: 0\n}" /etc/corosync/corosync.conf
[root@corosync1-cent65 ~]# sed -i -e "s/bindnetaddr: 192.168.1.0/bindnetaddr: 192.168.33.0/" /etc/corosync/corosync.conf

上記コマンド実施により、/etc/corosync/corosync.confに以下の設定が追加される。

aisexec {
  user: root
  group: root
}
service {
  name: pacemaker
  ver: 0
}

これによりrootユーザでpacemakerを利用したクラスタ実行がされます。
また、初期値ではクラスタがバインドされるネットワークセグメントが192.168.1.0となっているため、今回ゲストOSが起動される192.168.33.0/24に合わせて設定を変更。

totem  {
    ~略~
    interface {
      bindnetaddr: 192.168.33.0
    }
    ~略~
}

hostsファイル変更 (corosync1-cent65,corosync2-cent65両方で実施)

クラスタリングはドメイン名指定で実施するため、ドメイン名で通信できるように/etc/hostsへの設定追加を実施。
更に同じドメイン名の定義が127.0.0.1にもあるとクラスタの通信に失敗するためコメントアウトする。

[root@corosync1-cent65 ~]# sed -i -e "s/127.0.0.1/#127.0.0.1/" /etc/hosts
[root@corosync1-cent65 ~]# echo 192.168.33.10 corosync1-cent65 >> /etc/hosts
[root@corosync1-cent65 ~]# echo 192.168.33.11 corosync2-cent65 >> /etc/hosts

pcsコマンドインターフェース利用前準備 (corosync1-cent65,corosync2-cent65両方で実施)

cluster setupする時にcluster.confがないとエラーになるので、空ファイルを作成しておく。

[root@corosync1-cent65 ~]# touch /etc/cluster/cluster.conf

cluster authで認証する際に利用するパスワードを設定する。
[root@corosync1-cent65 ~]# passwd hacluster

pcsdを起動する。

[root@corosync1-cent65 ~]# service pcsd start

これでpcsコマンド実行の準備完了。

クラスタ設定(corosync1-cent65でのみ実施)

ここから先は1号機でのみ実施する。
setupコマンド実行時に/etc/cluster/cluster.confに設定が追加される。

[root@corosync1-cent65 ~]# pcs cluster auth corosync1-cent65 corosync2-cent65 -u hacluster
[root@corosync1-cent65 ~]# pcs cluster setup --name testcluster corosync1-cent65 corosync2-cent65 --force
[root@corosync1-cent65 ~]# pcs cluster start --all
[root@corosync1-cent65 ~]# pcs resource create VIP ocf:heartbeat:IPaddr2 ip=192.168.33.12

testclusterという名前でclusterが生成されます。
以下のコマンドで状態を表示します。

[root@corosync1-cent65 ~]# pcs status
Cluster name: testcluster
Last updated: Sun Mar 26 04:13:13 2017		Last change: Sun Mar 26 02:20:21 2017 by root via cibadmin on corosync1-cent65
Stack: cman
Current DC: corosync1-cent65 (version 1.1.14-8.el6_8.2-70404b0) - partition with quorum
2 nodes and 1 resource configured

Online: [ corosync1-cent65 corosync2-cent65 ]

Full list of resources:

 VIP	(ocf::heartbeat:IPaddr2):	Started corosync1-cent65

PCSD Status:
  corosync1-cent65: Online
  corosync2-cent65: Online

corosync1-cent65にVIP192.168.33.12が付与されることも確認できた。

[root@corosync1-cent65 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 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:4f:b8:06 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
    inet6 fe80::a00:27ff:fe4f:b806/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:cf:ef:3d brd ff:ff:ff:ff:ff:ff
    inet 192.168.33.10/24 brd 192.168.33.255 scope global eth1
    inet 192.168.33.12/24 brd 192.168.33.255 scope global secondary eth1
    inet6 fe80::a00:27ff:fecf:ef3d/64 scope link
       valid_lft forever preferred_lft forever

これで基本設定が完了。

8
5
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?