参考
- 公式サイト
- README
- UCARP on arch linux | Ramblings of a mad geek
- [NetBSD]CARPによるサーバ冗長化 - La vie des marmotte
- carpについてはCommon Address Redundancy Protocol - Wikipedia
参考その2
- 第3の冗長化プロトコル、CARPを試す : 負け組アーキテクトの憂鬱
- Linux-HA Japan Pacemakerリポジトリパッケージ (RHEL7) (1.1.13-1.1)
ソースからインストールする場合
ビルド
インストール
yum install -y libpcap-devel gcc
cd /opt
wget http://download.pureftpd.org/pub/ucarp/ucarp-1.5.2.tar.gz
tar xzf ucarp-1.5.2.tar.gz
cd ucarp-1.5.2
./configure && make && make install
mkdir /etc/ucarp/
スクリプト作成
/etc/ucarp/ucarp.sh
#!/bin/bash
UCARP=/usr/local/sbin/ucarp
UP=/etc/ucarp/up.sh
DOWN=/etc/ucarp/down.sh
DEV=enp0s3
# このサーバの実IP
SIP=192.168.100.11
#Virtual host ID number, every ucarp instance should have its own.
VHID=5
# 仮想IP
VIP=192.168.100.10
#The ucarp password shared only with the matching ucarp instance on another host
PASSWD="ucarp_pass1"
#any other flags you want to pass (refer to the man page for desired operation)
FLAGS="--shutdown --preempt --advskew=1"
#exec ucarp
exec ${UCARP} -i ${DEV} -s ${SIP} -v ${VHID} -p ${PASSWD} -a ${VIP} -u ${UP} -d ${DOWN} ${FLAGS}
/etc/ucarp/up.sh
#!/bin/bash
#the device and IP are passed by the ucarp daemon as $1 and $2 respectively
DEV="${1}"
IP="${2}"
/sbin/ip address add ${IP}/24 dev ${DEV}
/sbin/ip neigh flush dev ${DEV}
#start any service you need listening on your virtual IP
/bin/systemctl restart mysqld
/etc/ucarp/down.sh
#!/bin/bash
DEV="${1}"
IP="${2}"
/sbin/ip addr del ${IP}/24 dev ${DEV}
#optionally stop services here
/usr/lib/systemd/system/ucarp.service
Description=UCARP daemon
After=network.target
[Service]
ExecStart=/etc/ucarp/ucarp.sh
ExecStop=/bin/kill -TERM $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
権限修正
chown root:root /etc/ucarp/*.sh
chmod 0700 /etc/ucarp/*.sh
サービス登録
サービス登録
systemctl enable ucarp
systemctl start ucarp
パッケージからインストールする場合
yum install -y ucarp
# rpm -qal ucarp
/etc/ucarp
/etc/ucarp/vip-001.conf.example
/etc/ucarp/vip-common.conf
/usr/lib/systemd/system/ucarp@.service
/usr/libexec/ucarp
/usr/libexec/ucarp/ucarp
/usr/libexec/ucarp/vip-down
/usr/libexec/ucarp/vip-up
/usr/sbin/ucarp
/usr/share/doc/ucarp-1.5.2
/usr/share/doc/ucarp-1.5.2/AUTHORS
/usr/share/doc/ucarp-1.5.2/COPYING
/usr/share/doc/ucarp-1.5.2/ChangeLog
/usr/share/doc/ucarp-1.5.2/NEWS
/usr/share/doc/ucarp-1.5.2/README
/usr/share/locale/en@boldquot/LC_MESSAGES/ucarp.mo
/usr/share/locale/en@quot/LC_MESSAGES/ucarp.mo
設定
/etc/ucarp/vip-up
#!/bin/sh
exec 2>/dev/null
/sbin/ip address add "$2"/24 dev "$1"
echo "up" `date "+%c"` \
| mail -s `hostname`" vip001 up" root@localhost
/etc/ucarp/vip-down
#!/bin/sh
exec 2>/dev/null
/sbin/ip address del "$2"/24 dev "$1"
echo "down" `date "+%c"` \
| mail -s `hostname`" vip001 down" root@localhost
/etc/ucarp/vip-common.conf
PASSWORD="hogehoge"
BIND_INTERFACE="eth1"
SOURCE_ADDRESS="192.168.100.11"
OPTIONS="--shutdown --preempt"
/etc/ucarp/vip-001.conf
UPSCRIPT=/etc/ucarp/vip-up
DOWNSCRIPT=/etc/ucarp/vip-down
VIP_ADDRESS="192.168.100.10"
サービス登録
サービス登録
systemctl enable ucarp@vip-001
systemctl start ucarp@vip-001