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。

相關文章
相關標籤/搜索