Linux

在介面上啟動沒有 IP 的 keepalived?

  • June 29, 2018

我想在一個介面上使用keepalived,它會在某個時候獲得一個IP,但最初不會有一個,我可以在配置中以某種方式設置它嗎?如果我現在嘗試啟動它,keepalived 會出錯,因為 keepalived 不知道在發送 VRRP 數據包時要使用哪個源 IP 地址。會議:

!keepalived的配置文件

vrrp_instance VI_1 {
   state MASTER
   interface eth0
   virtual_router_id 51
   priority 150
   advert_int 1
   authentication {
       auth_type PASS
       auth_pass pwd
   }
   virtual_ipaddress {
      192.168.0.13
   }
   notify /etc/state_change.py
}

日誌:

keepalived -f /etc/keepalived.conf --log-console --dont-fork  
Thu Jun 28 11:25:53 2018: Starting Keepalived v1.4.4 (05/08,2018)               
Thu Jun 28 11:25:53 2018: Running on Linux 4.7.8 #9 SMP Wed Jun 27 17:25:18 IST 
2018 (built for Linux 4.7.8)                                                    
Thu Jun 28 11:25:53 2018: Opening file '/etc/keepalived.conf'.                  
Thu Jun 28 11:25:53 2018: Starting Healthcheck child process, pid=18886         
Thu Jun 28 11:25:53 2018: Starting VRRP child process, pid=18887                
Thu Jun 28 11:25:53 2018: Opening file '/etc/keepalived.conf'.                  
Thu Jun 28 11:25:53 2018: Registering Kernel netlink reflector                  
Thu Jun 28 11:25:53 2018: Registering Kernel netlink command channel            
Thu Jun 28 11:25:53 2018: Registering gratuitous ARP shared channel             
Thu Jun 28 11:25:53 2018: Opening file '/etc/keepalived.conf'.                  
Thu Jun 28 11:25:53 2018: WARNING - default user 'keepalived_script' for script 
execution does not exist - please create.                                       
Thu Jun 28 11:25:53 2018: (VI_1): Cannot find an IP address to use for interface
eth0                                                                           
Thu Jun 28 11:25:54 2018: Stopped                                               
Thu Jun 28 11:25:54 2018: Keepalived_vrrp exited with permanent error CONFIG. Te
rminating                                                                       
Thu Jun 28 11:25:54 2018: Stopping                                              
Thu Jun 28 11:25:54 2018: Stopped 

今天發布了新版本的keepalived 2.0.5,它支持尚不存在的介面。FAULT碰巧這也解決了我的問題,因為如果介面沒有 IP,keepalived 將在一個狀態下啟動,這很好。只需添加dynamic_interfaces即可global_defs

為什麼不使用 ifconfig 給它一個臨時地址呢?

引用自:https://serverfault.com/questions/918642