7
6

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.

CentOS7でucarpを使いHA環境構築 (corosync2+pacemakerより簡単)

Last updated at Posted at 2014-07-09

参考

参考その2

ソースからインストールする場合

ビルド

インストール
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

参考: Full Text Bug Listing

7
6
0

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
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?