CARP 使用笔记

1、安装

freebsd 7.3下用kldload if_carp 加载不了,报找不到模块的错,升级到9.2后就可以了。

然后按照freebsd官方手册的ifconfig carp0 create创建设备,然后改/etc/rc.conf中的carp0配置,重启网卡生效。

2、钩子脚本

看 /etc/devd.conf里面是否有下面这两个目录,在freebsd下,默认是有的:
# grep directory /etc/devd.conf
# Each “directory” directive adds a directory to the list of
directory “/etc/devd”;

directory “/usr/local/etc/devd”;

编辑notify.conf配置文件,注意必须要.conf后缀,否则devd进程无法读取该配置文件:

vi /usr/local/etc/devd/notify.conf

notify 30{
  match "system" "IFNET";
  match "subsystem" "carp0";
  match "type" "LINK_UP";
  action "/root/scripts/notify.sh up";

}; 

notify 30{
  match "system" "IFNET";
  match "subsystem" "carp0";
  match "type" "LINK_DOWN";
  action "/root/scripts/notify.sh down";

}; 

30表示这个notify的优先级,让devd进程接收到后优先处理

重启devd进程:/etc/rc.d/devd restart 

3、高阶使用

  由于怕一对carp设备因为网络的抖动造成ip敏感切换,可以启用两对carp设备,一对是绑定对外ip,一对是内网ip,仅用于心跳:

hostA(master) hostB(backup)
carp0:pub_ip carp0:pub_ip
carp1:10.0.0.1 carp1:10.0.0.2

  实际环境中,需要先对A的物理网卡添加别名10.0.0.3/24,对B的物理网卡添加别名10.0.0.4/24,然后再创建carp1设备及添加ip,这样carp1才会找到路由广播vrrp,不然两个carp1设备都认为自己是master。

  之后,绑定carp1的钩子脚本,ip切换时,脚本ping一下pub_ip是否有响应,仅当没响应的时候才切换pub_ip。

  实际使用中发现,如果改了A的路由,让vrrp发不出去,B在变为master后,再恢复A的路由,此时A会变为backup。

原文地址:https://www.cnblogs.com/children/p/3432989.html