1. 程式人生 > >ubuntu安裝keepalived

ubuntu安裝keepalived

virtual grep IV 文件 data- ast rep out ifconfig

1. 註意

  • 不需要修改默認源
  • 全程需要以root身份執行
  • 目前只能在虛擬機或實體機安裝,docker中暫時還有問題

2. 安裝

apt-cache search keepalived
keepalived - Failover and monitoring daemon for LVS clusters

apt-get install keepalived

安裝完成,會生成/etc/keepalived/目錄,該目錄是keepalived的配置文件目錄。

3. 配置

  • ifconfig 查看網卡名稱和ip

  • vim /etc/keepalived/keepalived.conf

vrrp_instance VI_1 {
   state MASTER
   interface ens33 #ifconfig確定
   virtual_router_id 
51 #路由器標識,MASTER和BACKUP必須是一致的 priority 100 #定義優先級,數字越大,優先級越高,在同一個vrrp_instance下,MASTER的優先級必須大於BACKUP的優先級。這樣MASTER故障恢復後,就可以將VIP資源再次搶回來 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.11.25 # 虛擬ip } }

需要配置的項為:state,interface

,priority,virtual_ipaddress

4. 啟動與停止

/etc/init.d/keepalived status # 查看狀態
/etc/init.d/keepalived stop  # 停止
/etc/init.d/keepalived start # 啟動

5. 測試

首先ps -ef|grep keep查看進程是否存在;
其次ip addr查看ip信息是否創建成功,ping虛擬ip是否相通。

ubuntu安裝keepalived