CentOS: 2009年1月アーカイブ

またまたお金をかけずに冗長化しようシリーズです(笑)。今回はCentOS 5.2でbonding設定を行ったのでメモ。NICはeth0とeth1があるので、これを組み合わせてbond0にします。今回行う設定は以下の通り。

bond0のIPアドレス・・・192.168.0.100/24
bond0にまとめるインターフェイス・・・eth0とeth1
IPv6は設定しない


1. bondingモジュールの読み込み

[root@ishikari ~]# cd /etc/modprobe.d/
[root@ishikari modprobe.d]# vi bonding
alias bond0 bonding
option bond0 miimon=100 mode=1 primary=eth0

今回はNICの監視をMIIにやらせます。

2. bondingインターフェースの定義

[root@ishikari ~]# cd /etc/sysconfig/network-scripts/
[root@ishikari network-scripts]# vi ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
BROADCAST=192.168.0.255
IPADDR=192.168.0.100
IPV6ADDR=
IPV6PREFIX=
NETMASK=255.255.255.0
NETWORK=192.168.0.0
ONBOOT=yes


3. bondインターフェースへethXデバイスを参加させる

既存のeth0とeth1にIPアドレスを設定せず、bond0のslaveとして振舞うように設定する。

[root@ishikari network-scripts]# vi ifcfg-eth0
# Realtek Semiconductor Co., Ltd. RTL-8169 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
MASTER=bond0
SLAVE=yes

[root@ishikari network-scripts]# vi ifcfg-eth1
# Intel Corporation 82540EM Gigabit Ethernet Controller
DEVICE=eth1
BOOTPROTO=static
ONBOOT=yes
MASTER=bond0
SLAVE=yes


あとはネットワークの再起動をするだけ。
# /etc/init.d/network restart

確認してみる。
$ /sbin/ifconfig
bond0     Link encap:Ethernet  HWaddr 00:90:CC:E9:2D:DD
          inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::290:ccff:fee9:2ddd/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:226686 errors:0 dropped:0 overruns:0 frame:0
          TX packets:254940 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:53590591 (51.1 MiB)  TX bytes:65817477 (62.7 MiB)

eth0      Link encap:Ethernet  HWaddr 00:90:CC:E9:2D:DD
          inet6 addr: fe80::290:ccff:fee9:2ddd/64 Scope:Link
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:226686 errors:0 dropped:0 overruns:0 frame:0
          TX packets:254942 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:53590591 (51.1 MiB)  TX bytes:65817801 (62.7 MiB)
          Interrupt:193 Base address:0xa000

eth1      Link encap:Ethernet  HWaddr 00:90:CC:E9:2D:DD
          UP BROADCAST SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
          Base address:0xecc0 Memory:fe100000-fe120000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:8019 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8019 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:943061 (920.9 KiB)  TX bytes:943061 (920.9 KiB)

はいできたー。あとはケーブルを片方ずつひっこ抜いて、通信が途切れないのを確認すればOK。
ね、簡単でしょ?

※ 注意点
非bond環境からbonding環境にするときはそのままモジュールを読み込めばよいが、bonding環境から非bond環境に戻すときは、ネットワークの再起動だけじゃなくてOSごと再起動したほうがよい。
前回までのエントリー(コレコレ)で、heartbeatのインストールとVIPの引継ぎができました。しかしそれだけじゃ冗長化には程遠いってのが人情。次は、apacheのサービスを引き継がせてみましょう。

■ httpdの停止

[重要]
heartbeatの設定をする前に、既存のhttpdを停止します。勿論、httpdの自動起動も停止しておきます。これは、今後httpdの起動停止をheartbeatがつかさどるためです。

[root@ishikari ~]# /etc/init.d/httpd stop
[root@ishikari ~]# chkconfig httpd off
[root@ishikari ~]# chkconfig httpd --list
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
    ↑
すべてのランレベルでoffになっていることを確認する。

※ 注意
yumでhttpdをインストールして、/etc/sysconfig/httpd ファイルを使って apache を worker モードで動かしている場合、heartbeat経由ではこの設定が失われてしまいます(preforkで動作してしまうってこと)。よって、 /usr/sbin/httpd を /usr/sbin/httpd.orig としてバックアップし、 /usr/sbin/httpd.worker へのシンボリックリンクとして /usr/sbin/httpd を設定すること。

例)
# mv /usr/sbin/httpd /usr/sbin/httpd.orig ; ln -s /usr/sbin/httpd.worker /usr/sbin/httpd


■ heartbeat停止

一旦両系でheartbeatを停止します。

[root@ishikari ~]# /etc/init.d/heartbeat stop
Stopping High-Availability services:
                                                           [  OK  ]

■ httpd監視設定を行う

[root@ishikari ~]# cd /var/lib/heartbeat/crm/

※ すべてのファイルをバックアップする
[root@ishikari crm]# tar czf cib.tar.gz *

※ cib.xml.last cib.xml.sig cib.xml.sig.last を削除する
[root@ishikari crm]# rm -f cib.xml.last cib.xml.sig cib.xml.sig.last

cib.xml を編集する
[root@ishikari crm]# vi cib.xml

まず、<nodes>タグの直下にある、<resources>の閉じタグ「<resources/>」を削除します。(そもそも閉じタグだけで、<resources> タグが開始されていないが・・・)

※ ここを
     <nodes>
       <node id="12979f53-e6ec-40f0-a7c2-66dfadf286ba" uname="sorachi.in.example.com" type="normal"/>
       <node id="82d27f7b-4e9a-478e-bcc1-80da0140a4a7" uname="ishikari.in.example.com" type="normal"/>
     </nodes>
     <resources/>

※ こうする
     <nodes>
       <node id="12979f53-e6ec-40f0-a7c2-66dfadf286ba" uname="sorachi.in.example.com" type="normal"/>
       <node id="82d27f7b-4e9a-478e-bcc1-80da0140a4a7" uname="ishikari.in.example.com" type="normal"/>
     </nodes>

次に、<nodes>タグの直下に、以下を追記します。
ココで投入する固有の値は「group_apache(どうやらグループの名前は何でもよいっぽい)」「192.168.0.200(httpをlistenするVIPの値)」「eth0(VIPをeth0インターフェイスのエイリアスにする)」「24(サブネットマスクのビット数)」「/etc/httpd/conf/httpd.conf(httpd.confのフルパス)」です。

     <resources>
       <group id="group_apache">
         <primitive id="ipaddr" class="ocf" type="IPaddr" provider="heartbeat">
         <instance_attributes id="ia_ipaddr">
           <attributes>
             <nvpair id="ia_ipaddr_ip" name="ip" value="192.168.0.200"/>
             <nvpair id="ia_ipaddr_nic" name="nic" value="eth0"/>
             <nvpair id="ia_ipaddr_netmask" name="netmask" value="24"/>
           </attributes>
         </instance_attributes>
       </primitive>
       <primitive id="apache" class="ocf" type="apache" provider="heartbeat">
         <instance_attributes id="ia_apache">
           <attributes>
             <nvpair id="ia_apache_configfile" name="configfile" value="/etc/httpd/conf/httpd.conf"/>
           </attributes>
         </instance_attributes>
         </primitive>
       </group>
     </resources>

以上の設定が終わったら保存します。


■ httpd.confを修正する

[root@ishikari crm]# cd /etc/httpd/conf
[root@ishikari conf]# cp -p httpd.conf httpd.conf.20090104
[root@ishikari conf]# vi httpd.conf

※ ここを
Listen 80

※ こうする
Listen 192.168.0.200:80


※ ここを
#<Location /server-status>
#    SetHandler server-status
#    Order deny,allow
#    Deny from all
#    Allow from .example.com
#</Location>

※ こうする
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 192.168.0
</Location>


■ heartbeatを起動する

[root@ishikari ~]# /etc/init.d/heartbeat start
Starting High-Availability services:
                                                           [  OK  ]

[root@sorachi ~]# /etc/init.d/heartbeat start
Starting High-Availability services:
                                                           [  OK  ]


■ 起動後の確認

しばらく時間をおいて、両系にて監視コマンドを実行します。以下のように表示されていればOK。

= ココに注目! =================================================================================
    ipaddr      (heartbeat::ocf:IPaddr):        Started sorachi.in.example.com
    apache      (heartbeat::ocf:apache):        Started sorachi.in.example.com
================================================================================================


[root@ishikari ~]# crm_mon -i 3
Defaulting to one-shot mode
You need to have curses available at compile time to enable console mode


============
Last updated: Sun Jan  4 04:43:09 2009
Current DC: sorachi.in.example.com (12979f53-e6ec-40f0-a7c2-66dfadf286ba)
2 Nodes configured.
1 Resources configured.
============

Node: sorachi.in.example.com (12979f53-e6ec-40f0-a7c2-66dfadf286ba): online
Node: ishikari.in.example.com (82d27f7b-4e9a-478e-bcc1-80da0140a4a7): online

Resource Group: group_apache
    ipaddr      (heartbeat::ocf:IPaddr):        Started sorachi.in.example.com
    apache      (heartbeat::ocf:apache):        Started sorachi.in.example.com


[root@sorachi ~]# crm_mon -i 3
Defaulting to one-shot mode
You need to have curses available at compile time to enable console mode


============
Last updated: Sun Jan  4 04:43:18 2009
Current DC: sorachi.in.example.com (12979f53-e6ec-40f0-a7c2-66dfadf286ba)
2 Nodes configured.
1 Resources configured.
============

Node: sorachi.in.example.com (12979f53-e6ec-40f0-a7c2-66dfadf286ba): online
Node: ishikari.in.example.com (82d27f7b-4e9a-478e-bcc1-80da0140a4a7): online

Resource Group: group_apache
    ipaddr      (heartbeat::ocf:IPaddr):        Started sorachi.in.example.com
    apache      (heartbeat::ocf:apache):        Started sorachi.in.example.com


■■ 実際の動きを見てみた

テストコンテンツとして、各々のホスト名を書いたindex.htmlをドキュメントルートに配置。sorachiのeth0を抜き差しして片系障害をおこし、フェイルオーバー/フェイルバックされることを確認しました。また、ifconfigコマンドで確認すると、httpdが生きている間は、ちゃんとVIPが設定されています。

【httpdが生きているsorachi】

[oresama@sorachi ~]$ ps auxwww | grep [h]eartbeat
root     22169  0.0  0.5  12072 12072 ?        SLs  07:23   0:00 heartbeat: master control process
nobody   22172  0.0  0.2   5476  5476 ?        SL   07:23   0:00 heartbeat: FIFO reader
nobody   22173  0.0  0.2   5472  5472 ?        SL   07:23   0:00 heartbeat: write: ucast eth1
nobody   22174  0.0  0.2   5472  5472 ?        SL   07:23   0:00 heartbeat: read: ucast eth1
498      22178  0.0  0.0   4900  1756 ?        S    07:23   0:00 /usr/lib/heartbeat/ccm
498      22179  0.2  0.1   6628  2868 ?        S    07:23   0:00 /usr/lib/heartbeat/cib
nobody   22180  0.0  0.0   4596  1616 ?        S    07:23   0:00 /usr/lib/heartbeat/lrmd -r
nobody   22181  0.0  0.2   4628  4628 ?        SL   07:23   0:00 /usr/lib/heartbeat/stonithd
498      22182  0.0  0.0   4784  1716 ?        S    07:23   0:00 /usr/lib/heartbeat/attrd
498      22183  0.0  0.1   5604  2268 ?        S    07:23   0:00 /usr/lib/heartbeat/crmd
root     22184  3.1  0.1   5920  2096 ?        S    07:23   0:02 /usr/lib/heartbeat/mgmtd -v
root     22185  0.0  0.0   4544  1316 ?        S    07:23   0:00 /usr/lib/heartbeat/pingd -m 100 -d 5s -a default_ping_set

[oresama@sorachi ~]$ ps auxwww | grep [h]ttpd
root     22443  0.2  0.3  14736  7332 ?        Ss   07:23   0:00 /usr/sbin/httpd -DSTATUS -f /etc/httpd/conf/httpd.conf
apache   22454  0.0  0.4 2660000 10232 ?       Sl   07:23   0:00 /usr/sbin/httpd -DSTATUS -f /etc/httpd/conf/httpd.conf

[oresama@sorachi ~]$ /sbin/ifconfig
eth0      Link encap:Ethernet  HWaddr 00:90:CC:E9:30:AB
          inet addr:192.168.0.101  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::290:ccff:fee9:30ab/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:47609 errors:0 dropped:0 overruns:0 frame:0
          TX packets:50473 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:11591250 (11.0 MiB)  TX bytes:24177872 (23.0 MiB)
          Interrupt:193 Base address:0xa000

eth0:0    Link encap:Ethernet  HWaddr 00:90:CC:E9:30:AB
          inet addr:192.168.0.200  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:193 Base address:0xa000

eth1      Link encap:Ethernet  HWaddr 00:C0:9F:1A:3C:F2
          inet addr:192.168.1.101  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::2c0:9fff:fe1a:3cf2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8757 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8879 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:2555439 (2.4 MiB)  TX bytes:2625068 (2.5 MiB)
          Base address:0xecc0 Memory:fe100000-fe120000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:18876 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18876 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:4157055 (3.9 MiB)  TX bytes:4157055 (3.9 MiB)


【httpdが死んでいるishikari】


[oresama@ishikari ~]$ ps auxwww | grep [h]eartbeat
root     14050  0.0  0.5  12076 12076 ?        SLs  06:53   0:00 heartbeat: master control process
nobody   14053  0.0  0.2   5480  5480 ?        SL   06:53   0:00 heartbeat: FIFO reader
nobody   14054  0.0  0.2   5476  5476 ?        SL   06:53   0:00 heartbeat: write: ucast eth1
nobody   14055  0.0  0.2   5476  5476 ?        SL   06:53   0:00 heartbeat: read: ucast eth1
498      14058  0.0  0.0   4928  2008 ?        S    06:53   0:00 /usr/lib/heartbeat/ccm
498      14059  0.2  0.1   6628  2936 ?        S    06:53   0:03 /usr/lib/heartbeat/cib
root     14060  0.0  0.0   4896  1880 ?        S    06:53   0:00 /usr/lib/heartbeat/lrmd -r
nobody   14061  0.0  0.2   4624  4624 ?        SL   06:53   0:00 /usr/lib/heartbeat/stonithd
498      14062  0.0  0.0   5188  1820 ?        S    06:53   0:00 /usr/lib/heartbeat/attrd
498      14063  0.0  0.1   5624  2668 ?        S    06:53   0:00 /usr/lib/heartbeat/crmd
root     14064  0.0  0.0   5924  1912 ?        S    06:53   0:00 /usr/lib/heartbeat/mgmtd -v
root     14065  0.0  0.0   4544  1336 ?        S    06:53   0:00 /usr/lib/heartbeat/pingd -m 100 -d 5s -a default_ping_set
498      15217  0.0  0.1   5132  2124 ?        S    06:55   0:00 /usr/lib/heartbeat/tengine
498      15218  0.0  0.1   5760  2380 ?        S    06:55   0:00 /usr/lib/heartbeat/pengine

[oresama@ishikari ~]$ ps auxwww | grep [h]ttpd

[oresama@ishikari ~]$ /sbin/ifconfig
eth0      Link encap:Ethernet  HWaddr 00:90:CC:E9:2D:DD
          inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::290:ccff:fee9:2ddd/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:45991 errors:0 dropped:0 overruns:0 frame:0
          TX packets:51372 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:11094384 (10.5 MiB)  TX bytes:15222245 (14.5 MiB)
          Interrupt:201 Base address:0xc000

eth1      Link encap:Ethernet  HWaddr 00:C0:9F:1A:3C:2D
          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::2c0:9fff:fe1a:3c2d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8820 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8785 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:2631005 (2.5 MiB)  TX bytes:2542771 (2.4 MiB)
          Base address:0xecc0 Memory:fe100000-fe120000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:18799 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18799 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:4120744 (3.9 MiB)  TX bytes:4120744 (3.9 MiB)


これで切替の基本動作はOK。sorachiのネットワークケーブルを抜いてから3秒で検知し、その後3秒でapacheが切り替わり、sorachiのネットワーク復旧は5秒で検知し、その後apacheは5秒で切り替わりました。都合6秒で切り替わり、復旧は都合10秒。

ね、簡単でしょ?


前回のエントリーで、yumを使ったheartbeatインストールができました。今度はheartbeatでVIPを引き継ぐところまでの設定をやってみましょう。


■ 認証ファイル作成

/etc/ha.d/authkeys ファイルを作成します。サンプルは /usr/share/doc/heartbeat-2.1.3/authkeys にあるので、ここからコピーします。


[root@ishikari ~]# cd /etc/ha.d/
[root@ishikari ha.d]# cp -p /usr/share/doc/heartbeat-2.1.3/authkeys ./
[root@ishikari ha.d]# vi authkeys

authkeys ファイルには
sha1 is believed to be the "best", md5 next best.
と書いてあるので、一番安全なsha1での暗号化を採用します。書き方は以下の通り。

auth 1
1 sha1 oresama

上記書き方の例にある、キーワードauth の後に入力するインデックスが何であれ、インデックスは、このファイル内のキーの下に入力しなければなりません。「auth 4」を入力した場合は、下のリストに「4 署名タイプ」行を含めなければならないことに注意。また、「oresama」は別にどんな文字列でもよく、monaでもgikoでも構いません。


■ 認証ファイルのパーミッションを600にする

authkeys ファイルの先頭にも注意書きが書いてあるように、パーミッションは600にすること。

[root@ishikari ha.d]# chmod 600 authkeys


■ ha.cfファイル作成

/etc/ha.d/ha.cf ファイルを作成します。サンプルは /usr/share/doc/heartbeat-2.1.3/ha.cf にあるので、ここからコピーします。

[root@ishikari ha.d]# cp -p /usr/share/doc/heartbeat-2.1.3/ha.cf ./
[root@ishikari ha.d]# vi ha.cf

# Heartbeatでv2スタイルのクラスタマネージャを実行するように設定。
crm on

# Heartbeatがデバッグメッセージを書き込むファイルを指定する。use_logdが有効な場合は無視される。
debugfile /var/log/ha-debug

# Heartbeatのデバッグ以外のメッセージは全て、このファイルに出力される。use_logdが有効な場合は無視される。
logfile /var/log/ha-log

# メッセージのログに使用するsyslogログファシリティを定義する。use_logdが有効な場合は無視される。
logfacility     local0

# キープアライブパケットの間隔を指定する。
keepalive 2

# Heartbeatがクラスタのノードが停止していると判断するまでの時間を指定する。
deadtime 2

# ping応答がない場合ダウンしたと認知する時間
deadping 1

# ハートビートが返ってこない場合警告となる時間
warntime 1

# 起動時間とネットワーク初期化を考慮して、(再起動後などに)全てが最初に起動してから、
# ノードが停止していると判断するまでの待機時間を指定する。
initdead 60

# ノード間の通信にHeartbeatが使用するポートを指定する。デフォルトは694。
udpport 694

# eth0インターフェースで、相手先ホストにパケットを送信する。
# [for ishikari(192.168.0.100)] ucast eth1 192.168.1.101
# [for sorachi(192.168.0.101)] ucast eth1 192.168.1.100
ucast eth0 192.168.0.101

# (デフォルト設定) 自動フェイルバックを有効にする。
auto_failback on

# クラスタ参加のノード名を指定する。ここに入力する値は、
# 各々のノードで「uname -n」を実行した結果と同じでなければならない。
node    ishikari.in.example.com
node    sorachi.in.example.com

# pingの設定を行う。
# From: http://www.ibm.com/developerworks/jp/linux/library/l-linux-ha/index.html
# respawn ディレクティブは、実行してその動作をモニターするプログラムを指定するために使用します。
# 指定したプログラムの終了コードが 100 以外であれば、プログラムは自動的に再起動されます。
# 最初のパラメーターはプログラムを実行するユーザー ID で、2 番目のパラメーターは実行対象のプログラムです。
# -m パラメーターでは pingd 属性を現行のマシンから到達可能な ping ノード数の 100 倍に設定し、
# -d パラメーターでは CIB の pingd 属性を変更するまでの遅延時間を 5 秒に設定しています。
# ping ディレクティブは、Heartbeat に対して PingNode を宣言するためのものです。
# そして最後の crm ディレクティブで、Heartbeat に 1.x 形式のクラスター・マネージャーを実行させるか、
# または 3 ノード以上をサポートする 2.x 形式のクラスター・マネージャーを実行させるかを指定します。
#
# このファイルはすべてのディレクターで同じでなければなりません。そして絶対不可欠なのは、
# hacluster デーモンがこのファイルを読み取れるような許可を適切に設定することです。このようにしないと、
# ログ・ファイルに大量の警告が記録されてデバッグが困難になります。
respawn root    /usr/lib/heartbeat/pingd -m 100 -d 5s -a default_ping_set


ここまで終わったら、sorachi側でもほぼ同じ設定を行います。
ishikariと違うのは
ucast eth0 192.168.0.101 を
ucast eth0 192.168.0.100
と設定するとこだけ。


■ 両系でheartbeatを起動する。

[root@ishikari ~]# /etc/init.d/heartbeat start
Starting High-Availability services:
                                                           [  OK  ]

[root@sorachi ~]# /etc/init.d/heartbeat start
Starting High-Availability services:
                                                           [  OK  ]

■ 自動起動設定をする。

[root@ishikari ~]# chkconfig heartbeat on
[root@sorachi ~]# chkconfig heartbeat on


■ 両系で手動死活監視を行う。

crm_mon コマンドで、ステータスがonlineで帰ってくること。

================================================================================
[root@ishikari ~]# crm_mon -i 3
Defaulting to one-shot mode
You need to have curses available at compile time to enable console mode


============
Last updated: Sun Jan  4 03:56:53 2009
Current DC: sorachi.in.example.com (12979f53-e6ec-40f0-a7c2-66dfadf286ba)
2 Nodes configured.
0 Resources configured.
============

Node: sorachi.in.example.com (12979f53-e6ec-40f0-a7c2-66dfadf286ba): online
Node: ishikari.in.example.com (82d27f7b-4e9a-478e-bcc1-80da0140a4a7): online
================================================================================
[root@sorachi ~]# crm_mon -i 3
Defaulting to one-shot mode
You need to have curses available at compile time to enable console mode


============
Last updated: Sun Jan  4 03:56:57 2009
Current DC: sorachi.in.example.com (12979f53-e6ec-40f0-a7c2-66dfadf286ba)
2 Nodes configured.
0 Resources configured.
============

Node: sorachi.in.example.com (12979f53-e6ec-40f0-a7c2-66dfadf286ba): online
Node: ishikari.in.example.com (82d27f7b-4e9a-478e-bcc1-80da0140a4a7): online
================================================================================

もし、自系でも他系でも
================================================================================
Node: sorachi.in.example.com (12979f53-e6ec-40f0-a7c2-66dfadf286ba): OFFLINE
Node: ishikari.in.example.com (82d27f7b-4e9a-478e-bcc1-80da0140a4a7): OFFLINE
================================================================================
と帰ってくるようなら、DNSかhostsで名前解決がなされていないか、VIPではない、リアルなIPアドレスの設定が間違っているかのどちらかが考えられます。

これで、単純なVIPの引継ぎができました。次のエントリーでは、apacheのサービスを引き継ぐ設定を行います。
webサーバの冗長化をするのに、ロードバランサ買うお金がない (っ´∀`)っ ゃー は、以前リバースプロキシを作ったことはありますが、今度はheartbeatでの冗長化にチャレンジです。

■■ 環境

■ サーバ共通スペック

Dell PowerEdge 600SC
Pentium    4 2.4GHz
Memory 2GB

■ ホスト情報

[ishikari.in.example.com]
eth0 192.168.0.100

[sorachi.in.example.com]
eth0 192.168.0.101


■ ネットワーク

ishikariとsorachiにそれぞれ、仮想IPアドレス(以下VIP)として192.168.0.200を割り当ててこれをhttp受信用に使います。ただし、VIPの設定はheartbeatの設定ファイルで行うため、先んじてエイリアスを切る必要はありません。192.168.0.200 は、ezo.in.example.com でもアクセスできるよう、あらかじめPCのhostsに書いておきます。


■■ 参考

http://www.server-world.info/note?os=ce5&p=heartbeat&f=1
http://www.server-world.info/note?os=ce5&p=heartbeat&f=2
http://www.linux-ha.org/ja/GettingStartedRevisedV2_ja
http://enterprisezine.jp/article/detail/162


■■ 注意点

これらの作業は、ishikari、sorachiともに基本的な設定を同じにします。ただし、それぞれのホストに固有の設定をしなけらばならない箇所については、文中に但し書きをしています。


■ heartbeatインストール

[root@ishikari ~]# yum install heartbeat

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 heartbeat               i386       2.1.3-3.el5.centos  extras            1.7 M
Installing for dependencies:
 PyXML                   i386       0.8.4-4          base              1.1 M
 heartbeat-pils          i386       2.1.3-3.el5.centos  extras            213 k
 heartbeat-stonith       i386       2.1.3-3.el5.centos  extras            311 k

Transaction Summary
=============================================================================
Install      4 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 3.3 M
Is this ok [y/N]: y


しかし、heartbeatは1回ではインストールされず、もう一度yumでインストールしてあげる必要があります。

[root@ishikari ~]# yum install heartbeat

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 heartbeat               i386       2.1.3-3.el5.centos  extras            1.7 M

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 1.7 M
Is this ok [y/N]: y

今度はOK。

Transaction Test Succeeded
Running Transaction
  Installing: heartbeat                    ######################### [1/1]

Installed: heartbeat.i386 0:2.1.3-3.el5.centos
Complete!
※ sorachiでは、先に PyXML heartbeat-stonith heartbeat-pils をインストールしてみたのですが、やはりheartbeatは2度インストールする必要がありました。


さて、インストールが終わったところで、今度は設定作業です。
通常、apacheを何も考えずにインストールすると、preforkで動作します。小規模サイトであればそのままでも構わないのですが、大規模サイトでスレッドによる処理の引渡しが要件に入ってくると、workerで適切なパラメータを投入して動かしたほうがパフォーマンスがよくなります。
※ ただしマシンスペックが低いとあんまり恩恵にあずかれないかも・・・

ちなみに、rpmからインストールしたapacheの動作をpreforkからworkerに変えるのは簡単。
/etc/sysconfig/httpd ファイルの
#HTTPD=/usr/sbin/httpd.worker ← ココのコメントを外し、apacheを再起動するだけ。

しかし問題が1つあって、CentOS付属のPHPはスレッドによる処理の引渡に対応していないので、どノーマルなhttpdとphpをインストールした後にworkerで動作させようとすると、apacheの起動時に以下のようなエラーを吐くのです。。。対処法はココを参考にしました。

$ sudo /etc/init.d/httpd start
Starting httpd: [Fri Jan 02 18:13:43 2009] [crit] Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.  You need to recompile PHP.
Pre-configuration failed
                                                           [FAILED]


■■ PHPのソースRPM入手とインストール

■ ソースRPMの入手

CentOSのミラーサイトには、大抵SRPMのディレクトリがあります。今回は理研さまのサイトからもってきました。
[oresama@sorachi ~]$ wget http://ftp.riken.jp/Linux/centos/5/os/SRPMS/php-5.1.6-20.el5.src.rpm


■ ソースrpmを展開する
[oresama@sorachi ~]$ rpm -ivh php-5.1.6-20.el5.src.rpm


■ SPECファイルを編集する
[oresama@sorachi ~]$ cd rpm/SPECS/
[oresama@sorachi SPECS]$ cp -p php.spec php.spec.orig
[oresama@sorachi SPECS]$ vi php.spec

ここを
%configure \
        --cache-file=../config.cache \
・・・

こうする
%configure \
        --with-tsm-pthreads \
        --enable-maintainer-zts \
        --cache-file=../config.cache \

tsm-pthreadsとmaintainer-ztsを有効にしてやるってことです。


■ 必要なパッケージをインストールする

その他、configureオプションを意図的に削除しない限りは、最低限以下のパッケージが必要になります。

apr-devel apr-util-devel aspell-devel autoconf automake beecrypt-devel bzip2-devel curl-devel cyrus-sasl-devel db4-devel e2fsprogs-devel elfutils-devel elfutils-devel-static elfutils-libelf-devel elfutils-libelf-devel-static expat-devel fontconfig-devel freetype-devel gcc-c++ gd gd-devel gmp-devel httpd-devel imake keyutils-libs-devel krb5-devel libc-client libc-client-devel libgcrypt-devel libgpg-error-devel libidn-devel libjpeg-devel libpng-devel libselinux-devel libsepol-devel libstdc++-devel libtool libX11-devel libXau-devel libXdmcp-devel libxml2-devel libXpm libXpm-devel libxslt libxslt-devel lm_sensors mesa-libGL-devel mysql mysql-devel ncurses-devel net-snmp net-snmp-devel net-snmp-libs openldap-devel openssl-devel pam-devel pcre-devel perl-DBI pkgconfig postgresql postgresql-devel rpm-devel sqlite-devel unixODBC unixODBC-devel xorg-x11-proto-devel zlib-devel

■ rpmbuildコマンドでビルドする

[oresama@sorachi SPECS]$ rpmbuild -bb php.spec


■ パッケージをインストールする

[oresama@sorachi SPECS]$ cd ../RPMS/i386
[oresama@sorachi i386]$ rpm --test -ivh php-5.1.6-20.i386.rpm php-cli-5.1.6-20.i386.rpm php-common-5.1.6-20.i386.rpm
[oresama@sorachi i386]$ sudo rpm -ivh php-5.1.6-20.i386.rpm php-cli-5.1.6-20.i386.rpm php-common-5.1.6-20.i386.rpm


■ apacheを再起動して反映
[oresama@sorachi i386]$ sudo /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]


※ yumでパッケージをアップデートする際に、phpの上書きインストールがされないよう、yum.confでexcludeしましょう。

[oresama@sorachi ~]$ cd /etc/
[oresama@sorachi etc]$ sudo cp -p yum.conf yum.conf.orig
[oresama@sorachi etc]$ sudo vi yum.conf

この行を追加
exclude=php*


あとは、phpのテストページが正常に表示されればOKです。
ね、簡単でしょ?
カスタム検索

カレンダー