1. 程式人生 > >02-keepalived實現對nginx服務的高可用(主備)

02-keepalived實現對nginx服務的高可用(主備)

trac code lob back ddr then 密碼 rtu alt

實驗環境:controller3,controller4為後端web服務器,controller1,controller2為nginx負載均衡服務器,用keepalived實現主備模式的高可用

controller1 IP:9.110.187.120  10.1.1.120

controller2 IP:9.110.187.121  10.1.1.121

controller3 IP:10.1.1.122

controller4 IP:10.1.1.123

1.controller3,controller4安裝httpd,提供簡單的測試頁面

技術分享技術分享

2.controller1,controller2安裝nginx,並配置後端服務器組

controller2配置和效果

技術分享

技術分享

controller1配置同controller2

3.在controller1上配置keepalived,實現對nginx的高可用

! Configuration File for keepalived

global_defs {
   notification_email {
        [email protected]    #通知郵箱
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1    #郵箱服務器
   smtp_connect_timeout 
30 #郵箱超時時間 router_id controller1 #本機route ID vrrp_mcast_group4 224.0.32.18 #組播地址 } vrrp_instance keepnginx { #自定義虛擬路由實例 state MASTER #本機虛擬路由狀態為master interface eno16777736 #心跳傳遞地址 virtual_router_id 60 #虛擬路由id priority 100 #權重100 advert_int 1 #1秒檢測 authentication { #檢測方式密碼,
123456 auth_type PASS auth_pass 123456 } virtual_ipaddress { 9.110.187.60/24 dev eno16777736 label eno16777736:1 #虛擬ip,虛擬ip所在網卡(內網) } } track_interface { #追蹤檢測網卡 eno16777736  #外網網卡提供訪問 eno33554960  #內網網卡訪問後端WEB服務器 }

controller2設置為備用

! Configuration File for keepalived

global_defs {
   notification_email {
        [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id controller2
}

vrrp_instance keepnginx {
    state BACKUP
    interface eno16777736
    virtual_router_id 60
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        9.110.187.60/24 dev     eno16777736     label   eno16777736:1
    }
}

track_interface {
        eno16777736
        eno33554960
}

此時虛擬的Ip 9.110.187.60 因為controller1權重100運行在controller1上,停止controller1的keepalived服務後轉移至controller2上,訪問9.110.187.60 可輪詢方式訪問後端vipserver

02-keepalived實現對nginx服務的高可用(主備)