每月彙整: 2010 年 7 月

ifstated

# cd /usr/ports/net/ifstated
# make install clean
# vim /etc/rc.conf
加入以下資料

## ifstated
ifstated_enable=”YES”
ifstated_flags=”-f /usr/local/etc/ifstated.conf”

# vim /usr/local/etc/ifstated.conf
# We want to startup
init-state starting

# net.inet.carp.preempt must be enabled (set to 1)
# for this to work correctly.

carp_up = “carp0.link.up”

state starting {
init {
# Here we boot the box.
if $carp_up
set-state master
if ! $carp_up
set-state not_master
}
}

state not_master {
init {
run “rm /tmp/am_master”
}
if $carp_up
set-state master
}

state master {
init {
run “touch /tmp/am_master”
}
if ! $carp_up
set-state not_master
}

# /usr/local/etc/rc.d/ifstated start

host/provider 都一樣的設定檔
這樣就搞定了…

FreeBSD CARP

1.
角色分為 Provider, Host
Provider 就是設定當Host 失連後可以取得原先在Host 上的ip 的主機
Host 就是我們的Client

2.
先 compile Kernel 加入 ( Provider, Host 都要)
device carp

3.
設定 rc.conf

設定 host
hostname=”hosta.example.org”
ifconfig_fxp0=”inet 192.168.1.3 netmask 255.255.255.0″ ## 原本的網卡設定
cloned_interfaces=”carp0″ ## carp 網卡
ifconfig_carp0=”vhid 1 advskew 10 pass testpass 192.168.1.50/24″ ## vhid 在host/provider 都要一致 pass 的部份 兩台也要一樣

設定 provider
hostname=”provider.example.org”
ifconfig_fxp0=”inet 192.168.1.5 netmask 255.255.255.0″
cloned_interfaces=”carp0″ ## provider 可以不只當做一台host 的 backup
ifconfig_carp0=”vhid 1 advskew 100 pass testpass 192.168.1.50/24″
## advbase
# This optional parameter specifies how often, in seconds, to advertise that we’re a member of the redundancy group.
# The default is 1 second. Acceptable values are from 1 to 255.

## advskew
# This optional parameter specifies how much to skew the advbase when sending CARP advertisements.
# By manipulating advskew, the master CARP host can be chosen.
# The higher the number, the less preferred the host will be when choosing a master. The default is 0.
# Acceptable values are from 0 to 254.

4.
重開機
Host 先重開,再重開Provider
Host 重開機完後應該會取得 192.168.1.50
Host 的 ifconfig 應會如下
carp0: flags=49 metric 0 mtu 1500
inet 192.168.1.50netmask 0xffffff00
carp: MASTER vhid 1 advbase 1 advskew 10

Provider 的 ifconfig 應會如下
carp0: flags=49 metric 0 mtu 1500
inet 192.168.1.50 netmask 0xffffff00
carp: BACKUP vhid 1 advbase 1 advskew 100

5.測試方法
在Master 的那台輸入
ifconfig carp0 down && ifconfig carp0 up
則Backup 應會變成Master
Master 會變Backup

ref.
http://www.freebsd.org/doc/en/books/handbook/carp.html