Pacemaker 資料一覧
2015/10/07更新
対応バージョン: Vagrant 1.4.3, Pacemaker 1.0.13, Heartbeat 3.0.5
Vagrantで用意したCentOSのBOXを使って2つの仮想マシン上にPacemaker + Heartbeatによる2ノードクラスタを構築する手順を示す。ホストOSはUbuntu14.04。
関連資料・記事
[Vagrant] Vagrantインストール手順(VirtualBox環境) ... Ubuntu編
[Pacemaker] Pacemaker + Heartbeatによる2ノードクラスタ設定(Apache, Samba)
クラスタ環境は上記で作成した構成を踏襲するが、以下の点が異なっている。
NICのインタフェース名
eth1: サービス提供用(上記資料ではem1)
eth2: インターコネクト(上記資料ではp4p1)
リソース管理するサービスはApacheのみ(上記資料ではApacheとSamba)
rsyslogの設定は変更しない
仮想マシン作成
まず2台の仮想マシンを作成する。
% cd % mkdir -p vagrant/centos65 % cd vagrant/centos65 % vagrant init centos65_64 % ls Vagrantfile
各仮想マシンの設定が異なるのでVagrantfileを以下のように記述する。
# -*- mode: ruby -*- # vi: set ft=ruby : VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.define :s1 do |v| v.vm.box = "centos65_64" v.vm.hostname = "s1" v.vm.network :private_network, ip: "192.168.1.121" v.vm.network :private_network, ip: "192.168.9.121" v.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2122 v.vm.provision :shell, :path => "heartbeat.sh" end config.vm.define :s2 do |v| v.vm.box = "centos65_64" v.vm.hostname = "s2" v.vm.network :private_network, ip: "192.168.1.122" v.vm.network :private_network, ip: "192.168.9.122" v.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2222 v.vm.provision :shell, :path => "heartbeat.sh" v.vm.provision :shell, :path => "pacemaker.sh" end end
初回起動時のプロビジョニングとして各仮想マシンでHeatbeatの設定を行い(heartbeat.sh)、2台がHA構成になったあと2台目の仮想マシンでPacemakerの設定を行う(pacemaker.sh)。
heartbeat.shとpacemaker.shはそれぞれ以下のように記述し、Vagrantfileと同じパスに格納する。説明は後述する。
heartbeat.sh
#!/bin/sh yum update yum -y install wget ### install pacemaker cd /tmp tar xvzf /vagrant/pacemaker-1.0.13-2.1.el6.x86_64.repo.tar.gz cd pacemaker-1.0.13-2.1.el6.x86_64.repo yum -y -c pacemaker.repo install pacemaker-1.0.13-2.el6.x86_64 heartbeat-3.0.5-1.1.el6.x86_64 pm_extras-1.5-1.el6.x86_64 ### install httpd(Apache) yum -y install httpd cp /vagrant/index.html /var/www/html ### add iptables iptables -A INPUT -p udp -m udp --dport 694 -j ACCEPT service iptables save ### add hosts cat /vagrant/hosts_add >> /etc/hosts ### setting heartbeat install /vagrant/ha.cf /etc/ha.d install -m 0600 /vagrant/authkeys /etc/ha.d ### start heartbeat service heartbeat start
### install pacemaker
ホストOS側の共有ディレクトリ(Vagrantfileと同じパス)に格納したPacemakerのバイナリを展開してインストールする。
Pacemakerのバイナリは以下から入手できる。
http://sourceforge.jp/projects/linux-ha/releases/
### install httpd(Apache)
Apacheをインストールする。設定はとりあえずデフォルトのまま。
Apacheの動作をモニタするために内部的にwgetでHTTPアクセスをするのでwgetもインストールしておく。
また上記アクセスにおいてHTMLファイルにアクセスできる必要があるので以下のダミーHTMLを共有ディレクトリ(Vagrantfileと同じパス)に用意しておきApacheのドキュメントルートにコピーする。
(index.html)
<html> </html>
これをやっておかないとApacheのリソースが起動してもすぐ終了してしまう。
関連資料・記事
### add iptables
インターコネクト通信用ポート(694/udp)の接続を許可する。
### add hosts
サーバ2台分のホスト情報を追加する。
このファイルもダミーHTML同様、共有ディレクトリに用意しておく。
(hosts_add)
192.168.1.121 s1 192.168.1.122 s2
### setting heartbeat
Heartbeat用の設定ファイル(/etc/ha.d/ha.cf、/etc/ha.d/authkeys)を用意する。
このファイルも共有ディレクトリに用意しておく。
(ha.cf)
pacemaker on debug 0 udpport 694 keepalive 2 warntime 7 deadtime 10 initdead 10 logfacility local1 ucast eth2 192.168.9.121 ucast eth2 192.168.9.122 ping 192.168.1.1 node s1 node s2 watchdog /dev/watchdog respawn root /usr/lib64/heartbeat/ifcheckd
(authkeys)
auth 1 1 sha1 xxxxx <--- インターコネクト通信用の任意のパスフレーズ
### start heartbeat
heartbeatのサービスを起動する。
pacemaker.sh
#!/bin/sh ### wait for being ready cluster while [ 1 ] do crm node status > /dev/null 2>&1 if [ $? -eq 0 ]; then break fi sleep 1 done sleep 5 ### setting option crm configure property stonith-enabled="false" crm configure property no-quorum-policy="ignore" ### setting resouce crm configure primitive vip_httpd ocf:heartbeat:IPaddr2 params \ ip="192.168.1.101" nic="eth1" cidr_netmask="24" op monitor interval="10" crm configure primitive httpd ocf:heartbeat:apache params \ configfile="/etc/httpd/conf/httpd.conf" statusurl="http://192.168.1.101/" \ op start interval="0" timeout="90" on-fail="restart" \ op monitor interval="10" timeout="60" on-fail="restart" \ op stop interval="0" timeout="300" on-fail="block" ### grouping crm configure group web vip_httpd httpd
### wait for being ready cluster
クラスタが動作可能になってリソース制御ができるようになるまで待つ。
### setting option
各種オプションを設定する。
### setting resouce
リソースとしてVIP(vip_httpd)とApache(httpd)を定義する。
### grouping
上記で定義したリソースをグルーピングして一つのリソースグループとする。
仮想マシン起動
以上の設定が終わったら仮想マシンを起動する。
% vagrant up Bringing machine 's1' up with 'virtualbox' provider... Bringing machine 's2' up with 'virtualbox' provider... [s1] Importing base box 'centos65_64'... [s1] Matching MAC address for NAT networking... [s1] Setting the name of the VM... [s1] Clearing any previously set forwarded ports... [s1] Clearing any previously set network interfaces... [s1] Preparing network interfaces based on configuration... [s1] Forwarding ports... [s1] -- 22 => 2122 (adapter 1) [s1] Booting VM... [s1] Waiting for machine to boot. This may take a few minutes... [s1] Machine booted and ready! [s1] Setting hostname... [s1] Configuring and enabling network interfaces... [s1] Mounting shared folders... [s1] -- /vagrant [s1] Running provisioner: shell... [s1] Running: /tmp/vagrant-shell20141007-20822-ag7wdv Loaded plugins: fastestmirror : (ここからs1のプロビジョニング) : Starting High-Availability services: Done. [s2] Importing base box 'centos65_64'... [s2] Matching MAC address for NAT networking... [s2] Setting the name of the VM... [s2] Clearing any previously set forwarded ports... [s2] Clearing any previously set network interfaces... [s2] Preparing network interfaces based on configuration... [s2] Forwarding ports... [s2] -- 22 => 2222 (adapter 1) [s2] Booting VM... [s2] Waiting for machine to boot. This may take a few minutes... [s2] Machine booted and ready! [s2] Setting hostname... [s2] Configuring and enabling network interfaces... [s2] Mounting shared folders... [s2] -- /vagrant [s2] Running provisioner: shell... [s2] Running: /tmp/vagrant-shell20141007-20822-1pyt36a Loaded plugins: fastestmirror : (ここからs2のプロビジョニング) : Starting High-Availability services: Done. [s2] Running provisioner: shell... [s2] Running: /tmp/vagrant-shell20141007-20822-12eoo2m
初回起動時のみheartbeat.sh及びpacemaker.shが動き(プロビジョニング)、各種ソフトウェアのインストールと設定が行われる。
試しにs1(サーバ1)に接続してcrm_monを実行すると各ノードとリソースが正常に動作しているのが確認できる。この状態でhttp://192.168.1.101/にアクセスするとApacheのテスト画面が表示される。
% vagrant ssh s1 [vagrant@s1 ~]$ sudo crm_mon -A ============ Last updated: Mon Oct 6 17:36:38 2014 Stack: Heartbeat Current DC: s1 (0ae70a20-2a06-4775-98d8-4e6cdddfb170) - partition with quorum Version: 1.0.13-a83fae5 2 Nodes configured, unknown expected votes 1 Resources configured. ============ Online: [ s1 s2 ] Resource Group: web vip_httpd (ocf::heartbeat:IPaddr2): Started s1 httpd (ocf::heartbeat:apache): Started s1 Node Attributes: * Node s1: + s2-eth2 : up * Node s2: + s1-eth2 : up
このプロビジョニングは初回起動時だけ動作すればいいので2回目以降は動かない。
もしスクリプトに変更を加えたい時などは以下のようにいったん仮想マシンを削除して再作成すればよい。
% vagrant destroy Are you sure you want to destroy the 's2' VM? [y/N] y [s2] Forcing shutdown of VM... [s2] Destroying VM and associated drives... [s2] Running cleanup tasks for 'shell' provisioner... Are you sure you want to destroy the 's1' VM? [y/N] y [s1] Forcing shutdown of VM... [s1] Destroying VM and associated drives... [s1] Running cleanup tasks for 'shell' provisioner... % vagrant up :