利用keepalived實現集羣調度器的高可用

在這裏插入圖片描述

使用keepalived爲集羣調度器提供高可用功能,防止調度器單點故障,爲用戶提供web服務

環境搭建

  1. 調度器1的真實ip爲192.168.1.21
  2. 調度器2的真實ip爲192.168.1.22
  3. 服務器vip爲192.168.1.20
  4. 使用加權輪詢調度算法

1 安裝軟件包

yum -y install keepalived

2 修改配置文件

vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {        #設置報警收件人郵箱
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from   
        [email protected]   #設置發件人
   smtp_server 127.0.0.1        #定義郵件服務器
   smtp_connect_timeout 30
   router_id tt-ha-0001        #設置路由id號(設置爲主機名即可)
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
   vrrp_iptables           #設置vrrp路由表
}

vrrp_instance VI_1 {
    state MASTER          #設置主服務器爲MASTER(從服務器爲BACKUP)
    interface eth0       #定義網絡接口
    virtual_router_id 51     #主從vrid號必須一致
    priority 100         #服務器優先級(從服務器要比主服務器小)
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111    #主從服務器密碼必須一致
    }
    virtual_ipaddress {
        192.168.1.20      #配置虛擬vip
    }
}
  real_server 192.168.1.21 80 {        #設置後端web服務器真實ip
    weight 1                    #權重爲1       
    TCP_CHECK     {                #對後臺real_server做健康檢查              
    connect_timeout 3
    nb_get_retry 3
    delay_before_retry 3
    }
  }
  real_server 192.168.1.22 80 {        
    weight 1                           
    TCP_CHECK {                       
    connect_timeout 3
    nb_get_retry 3
    delay_before_retry 3
    }
  }

3 啓動服務並設置開機自啓

systemctl start keepalived
systemctl enable keepalived

4 驗證服務

ip a s
可以查看到vip
手工down掉調度器1,調度器2會自動接管vip

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章