CARP 使用笔记

一、安装网络

 

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

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

 

二、钩子脚本进程

 

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

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

 

编辑notify.conf配置文件,注意必需要.conf后缀,不然devd进程没法读取该配置文件:io

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";

}; table

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

}; 

 

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

 

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

 

三、高阶使用

 

  因为怕一对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。

相关文章
相关标签/搜索