久しぶりのCDPネタです。
今回は「High Availability NATパターン」(Incubator & 未完成)です。
上記をCentOS6上でCorosyncとPacemaker、そしてPython版コマンドラインツールで
構築してみました。
※上記のVPC/EC2/セキュリティグループなどの設定は適切に行われているものとします。
AWS(EC2)と"iptables"の設定
下記参照。
VPCのNATインスタンスを作ってみる(環境準備編)次のようになっていれば、OKです。
VPCのNATインスタンスを作ってみる(iptables編)
# iptables --list -t nat Chain PREROUTING (policy ACCEPT) target prot opt source destination Chain POSTROUTING (policy ACCEPT) target prot opt source destination MASQUERADE all -- anywhere anywhere Chain OUTPUT (policy ACCEPT) target prot opt source destination
"corosync"と"pacemaker"の導入と設定
下記参照
Corosync & Pacemaker on EC2次のようになっていれば、OKです。
# crm_mon ============ Last updated: Mon Jan 28 18:21:56 2013 Last change: Mon Jan 28 18:20:39 2013 via crmd on ip-10-10-8-122 Stack: openais Current DC: ip-10-10-8-122 - partition with quorum Version: 1.1.7-6.el6-148fccfd5985c5590cc601123c6c16e966b85d14 2 Nodes configured, 2 expected votes 0 Resources configured. ============ Online: [ ip-10-10-9-111 ip-10-10-8-122 ]
"iptables"のモニタリングとフェイルオーバーの設定
下記参照。
"Corosync & Pacemaker"で"iptables"のフェイルオーバー次のようになっていれば、OKです。
# crm_mon ============ Last updated: Mon Jan 28 18:24:36 2013 Last change: Mon Jan 28 18:24:34 2013 via cibadmin on ip-10-10-8-122 Stack: openais Current DC: ip-10-10-8-122 - partition with quorum Version: 1.1.7-6.el6-148fccfd5985c5590cc601123c6c16e966b85d14 2 Nodes configured, 2 expected votes 1 Resources configured. ============ Online: [ ip-10-10-9-111 ip-10-10-8-122 ] iptables (lsb:iptables): Started ip-10-10-9-111
フェイルオーバー時の"Route Table"の変更設定
ここからが、本番です。下記のような初期起動スクリプトを用意します。
# cat /etc/init.d/associate-nat
#!/bin/sh
#
# chkconfig: 2345 99 10
# description: Associate EIP
# Source Function Library
. /etc/init.d/functions
# System Variable
prog=${0##*/}
lock=/var/lock/subsys/$prog
# User Variavle
ROUTE_TABLE_ID=rtb-xxxxxxxx
DESTINATION_CIDR=0.0.0.0/0
# Source Config
if [ -f /etc/sysconfig/$prog ] ; then
. /etc/sysconfig/$prog
fi
#
case "$1" in
start)
touch $lock
AZ=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`
REGION=`echo $AZ | cut -c 1-$((${#AZ} - 1))`
INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
aws --region $REGION ec2 replace-route \
--destination-cidr-block $DESTINATION_CIDR \
--route-table-id $ROUTE_TABLE_ID \
--instance-id $INSTANCE_ID \
| logger -s -i -t $prog
exit ${PIPESTATUS[0]}
;;
stop)
rm -f $lock
exit 0
;;
status)
if [ -f $lock ] ; then
exit 0
else
exit 3
fi
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
esac
それに実行権限を与えます。
# chmod 755 /etc/init.d/associate-nat
さらに"Route Table ID"も設定します。
# cat /etc/sysconfig/associate-nat ROUTE_TABLE_ID=rtb-yyyyyyyy
そして実行すると"Route Table"で指定しているNATインスタンスが自分自身の
インスタンスIDに変更されます。
# service associate-nat start
associate-nat[9971]: {
associate-nat[9971]: "return": "true",
associate-nat[9971]: "requestId": "e9220a00-e8c0-4c20-b42a-f3e5af3d9dc7"
associate-nat[9971]: }
これをPacemakerに設定します。
# crm configure primitive associate-nat lsb:associate-nat # crm configure group ha-nat iptables associate-nat
次のようになっていれば、OKです。
# crm_mon
============
Last updated: Mon Jan 28 20:26:37 2013
Last change: Mon Jan 28 20:26:17 2013 via cibadmin on ip-10-10-9-111
Stack: openais
Current DC: ip-10-10-8-122 - partition with quorum
Version: 1.1.7-6.el6-148fccfd5985c5590cc601123c6c16e966b85d14
2 Nodes configured, 2 expected votes
2 Resources configured.
============
Online: [ ip-10-10-9-111 ip-10-10-8-122 ]
Resource Group: ha-nat
iptables (lsb:iptables): Started ip-10-10-9-111
associate-nat (lsb:associate-nat): Started ip-10-10-9-111
一方のEC2の"iptables"を停止すると、
# service iptables stop
次のようにフェイルオーバーされ、
# crm_mon
============
Last updated: Mon Jan 28 20:54:28 2013
Last change: Mon Jan 28 20:26:17 2013 via cibadmin on ip-10-10-9-111
Stack: openais
Current DC: ip-10-10-8-122 - partition with quorum
Version: 1.1.7-6.el6-148fccfd5985c5590cc601123c6c16e966b85d14
2 Nodes configured, 2 expected votes
2 Resources configured.
============
Online: [ ip-10-10-9-111 ip-10-10-8-122 ]
Resource Group: ha-nat
iptables (lsb:iptables): Started ip-10-10-8-122
associate-nat (lsb:associate-nat): Started ip-10-10-8-122
Failed actions:
iptables_monitor_5000 (node=ip-10-10-9-111, call=5, rc=7, status=complete): not running
"Route Table"も"associate-nat"が実行された(スタンバイ)EC2のインスタンスIDに
変更されます。
フェイルバックするためには、一旦、障害を起こしたEC2の"Failed Action"をクリアします。
# crm resource cleanup ha-nat ip-10-10-9-111 Cleaning up iptables on ip-10-10-9-111 Cleaning up associate-nat on ip-10-10-9-111 Waiting for 3 replies from the CRMd... OK
次のように"Failed Action"が消えていれば、OKです。
# crm_mon
============
Last updated: Mon Jan 28 21:04:02 2013
Last change: Mon Jan 28 21:04:02 2013 via crmd on ip-10-10-9-111
Stack: openais
Current DC: ip-10-10-8-122 - partition with quorum
Version: 1.1.7-6.el6-148fccfd5985c5590cc601123c6c16e966b85d14
2 Nodes configured, 2 expected votes
2 Resources configured.
============
Online: [ ip-10-10-9-111 ip-10-10-8-122 ]
Resource Group: ha-nat
iptables (lsb:iptables): Started ip-10-10-8-122
associate-nat (lsb:associate-nat): Started ip-10-10-8-122
これを自動で作成できるようにしたい...
--------
http://www.suz-lab.com



0 コメント:
コメントを投稿