ucarp可以用来做IP failover,和keepalived的用法类似。更简单一些

小郜的主机可以搞一下

主机1

IP: 172.16.9.2

主机2

IP: 172.16.9.3

虚拟IP

IP: 172.16.9.1

步骤如下: 首先在两台实体机上装好ucarp

yum install -y epel-release  
yum install ucarp -y  
主机1
$ cp /etc/ucarp/vip-001.conf.example /etc/ucarp/vip-001.conf
$ cat /etc/ucarp/vip-001.conf
ID=001  
BIND_INTERFACE="eth0"  
SOURCE_ADDRESS="172.16.9.2"  
VIP_ADDRESS="172.16.9.1"  
PASSWORD="mysecret"  
OPTIONS="–shutdown –preempt"  
UPSCRIPT=/usr/libexec/ucarp/vip-up  
DOWNSCRIPT=/usr/libexec/ucarp/vip-down  
$ service ucarp start
主机2
$ cp /etc/ucarp/vip-001.conf.example /etc/ucarp/vip-001.conf
$ cat /etc/ucarp/vip-001.conf
ID=001  
BIND_INTERFACE="eth0"  
SOURCE_ADDRESS="172.16.9.3"  
VIP_ADDRESS="172.16.9.1"  
PASSWORD="mysecret"  
OPTIONS="–shutdown –preempt"  
UPSCRIPT=/usr/libexec/ucarp/vip-up  
DOWNSCRIPT=/usr/libexec/ucarp/vip-down  
$ service ucarp start

现在在主机1上面执行ip a s

就会看到172.16.9.1这个ip在上面了。

centos7服务的做法如下:

$ cat /run/systemd/system/ucarp@.service
[Unit]
Description=UCARP virtual interface %I  
After=network.target  
[Service]
Type=simple  
EnvironmentFile=-/etc/ucarp/vip-common.conf  
EnvironmentFile=-/etc/ucarp/vip-%I.conf  
ExecStart=/usr/sbin/ucarp -i $BIND_INTERFACE -p $PASSWORD -v %I -a $VIP_ADDRESS -s $SOURCE_ADDRESS $OPTIONS -u $UPSCRIPT -d $DOWNSCRIPT  
KillMode=control-group  
[Install]
WantedBy=multiuser.target  
$ systemctl start ucarp@001
comments powered by Disqus