该测试使用了4个节点,其IP地址分别为

  1. 172.21.0.211
  2. 172.21.0.212
  3. 172.21.0.213
  4. 172.21.0.214

其中节点 1、2、3 为 FreeBSD 12.1-BETA3 系统,节点 4 为 Debian GNU/Linux 10 系统。

设计目的是在任意节点故障时,自动由其它可用节点顶替其 IP 地址。

FreeBSD 系统上相同的配置为:

/boot/loader.conf
carp_load="YES"
vfs.maxbcachebuf=1048576

需要在 Debian GNU/Linux 系统上安装定制过的 ucarp:

TODO: put the source code somewhere

各节点的配置:

172.21.0.211:/etc/rc.conf
clear_tmp_enable="YES"
hostname="ha-file-server-1"
#ifconfig_em0="inet 172.21.0.211 netmask 255.255.240.0"
ifconfig_em0="vhid 1 pass testok 172.21.0.211/20 up"
ifconfig_em0_alias0="vhid 2 advskew 2 pass testok 172.21.0.212/32"
ifconfig_em0_alias1="vhid 3 advskew 3 pass testok 172.21.0.213/32"
ifconfig_em0_alias2="vhid 4 advskew 4 pass testok 172.21.0.214/32"
defaultrouter="172.21.0.1"
sshd_enable="YES"
ntpdate_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"
zfs_enable="YES"
samba_server_enable="YES"
172.21.0.212:/etc/rc.conf
clear_tmp_enable="YES"
hostname="ha-file-server-2"
#ifconfig_em0="inet 172.21.0.212 netmask 255.255.240.0"
ifconfig_em0="vhid 2 pass testok 172.21.0.212/20 up"
ifconfig_em0_alias0="vhid 1 advskew 2 pass testok 172.21.0.211/32"
ifconfig_em0_alias1="vhid 3 advskew 2 pass testok 172.21.0.213/32"
ifconfig_em0_alias2="vhid 4 advskew 3 pass testok 172.21.0.214/32"
defaultrouter="172.21.0.1"
sshd_enable="YES"
ntpdate_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"
zfs_enable="YES"
samba_server_enable="YES"
172.21.0.213:/etc/rc.conf
clear_tmp_enable="YES"
hostname="ha-file-server-3"
#ifconfig_em0="inet 172.21.0.213 netmask 255.255.240.0"
ifconfig_em0="vhid 3 pass testok 172.21.0.213/20 up"
ifconfig_em0_alias0="vhid 1 advskew 3 pass testok 172.21.0.211/32"
ifconfig_em0_alias1="vhid 2 advskew 2 pass testok 172.21.0.212/32"
ifconfig_em0_alias2="vhid 4 advskew 2 pass testok 172.21.0.214/32"
defaultrouter="172.21.0.1"
sshd_enable="YES"
ntpdate_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"
zfs_enable="YES"
samba_server_enable="YES"
172.21.0.214:/etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
 
source /etc/network/interfaces.d/*
 
# The loopback network interface
auto lo
iface lo inet loopback
 
# The primary network interface
auto ens36
iface ens36 inet static
    address 172.21.0.214/20
    gateway 172.21.0.1
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 172.21.0.51
    up sh /etc/network/start-ucarp.sh
172.21.0.214:/etc/network/start-ucarp.sh
#!/bin/sh
INTERFACE=ens36
ucarp --daemonize --interface $INTERFACE -s 172.21.0.214 --vhid 1 --pass testok --advskew 4 --addr 172.21.0.211 --shutdown --upscript /etc/ucarp-vh-up.sh --downscript /etc/ucarp-vh-down.sh --preempt
ucarp --daemonize --interface $INTERFACE -s 172.21.0.214 --vhid 2 --pass testok --advskew 3 --addr 172.21.0.212 --shutdown --upscript /etc/ucarp-vh-up.sh --downscript /etc/ucarp-vh-down.sh --preempt
ucarp --daemonize --interface $INTERFACE -s 172.21.0.214 --vhid 3 --pass testok --advskew 2 --addr 172.21.0.213 --shutdown --upscript /etc/ucarp-vh-up.sh --downscript /etc/ucarp-vh-down.sh --preempt
ucarp --daemonize --interface $INTERFACE -s 172.21.0.214 --vhid 4 --pass testok --advskew 0 --addr 172.21.0.214 --shutdown --upscript /etc/ucarp-vh-up.sh --downscript /etc/ucarp-vh-down.sh --preempt
172.21.0.214:/etc/ucarp-vh-up.sh
#!/bin/sh
ifconfig "$1:$UCARP_VHID" "$2" netmask 255.255.255.255 up
172.21.0.214:/etc/ucarp-vh-down.sh
#!/bin/sh
ifconfig "$1:$UCARP_VHID" down