keepalived+lvs 對(duì)nginx做負(fù)載均衡和高可用的操作方法
keepalived+lvs 對(duì)nginx做負(fù)載均衡和高可用
LVS_Director + KeepAlived KeepAlived在該項(xiàng)目中的功能: 1. 管理IPVS的路由表(包括對(duì)RealServer做健康檢查) 2. 實(shí)現(xiàn)調(diào)度器的HA http://www.keepalived.org Keepalived所執(zhí)行的外部腳本命令建議使用絕對(duì)路徑 ================================================================================= 實(shí)施步驟: 1. 主/備調(diào)度器安裝軟件 [root@lvs-keepalived-master ~]# yum -y install ipvsadm keepalived [root@lvs-keepalived-slave ~]# yum -y install ipvsadm keepalived 2. Keepalived lvs-master [root@ha-proxy-master ~]# vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { router_id lvs-keepalived-master #輔助改為lvs-backup } vrrp_instance VI_1 { state MASTER interface ens33 #VIP綁定接口 virtual_router_id 80 #VRID 同一組集群,主備一致 priority 100 #本節(jié)點(diǎn)優(yōu)先級(jí),輔助改為50 advert_int 1 #檢查間隔,默認(rèn)為1s authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.246.110/32 } } virtual_server 192.168.246.110 80 { #LVS配置 delay_loop 6 #健康檢查rs時(shí)間間隔 lb_algo rr #LVS調(diào)度算法 lb_kind DR #LVS集群模式(路由模式) protocol TCP #健康檢查使用的協(xié)議 real_server 192.168.246.162 80 { weight 1 inhibit_on_failure #當(dāng)該節(jié)點(diǎn)失敗時(shí),把權(quán)重設(shè)置為0,而不是從IPVS中刪除 TCP_CHECK { #健康檢查 connect_port 80 #檢查的端口 connect_timeout 3 #連接超時(shí)的時(shí)間 } } real_server 192.168.246.163 80 { weight 1 inhibit_on_failure TCP_CHECK { connect_timeout 3 connect_port 80 } } } [root@lvs-keepalived-slave ~]# vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { router_id lvs-keepalived-slave } vrrp_instance VI_1 { state BACKUP interface ens33 virtual_router_id 80 priority 50 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.246.110/24 } } virtual_server 192.168.246.110 80 { delay_loop 6 lb_algo rr lb_kind DR protocol TCP real_server 192.168.246.162 80 { weight 1 inhibit_on_failure TCP_CHECK { connect_port 80 connect_timeout 3 } } real_server 192.168.246.163 80 { weight 1 inhibit_on_failure TCP_CHECK { connect_timeout 3 connect_port 80 } } } 3. 啟動(dòng)KeepAlived(主備均啟動(dòng)) [root@lvs-keepalived-master ~]# systemctl start keepalived [root@lvs-keepalived-master ~]# systemctl enable keepalived [root@lvs-keepalived-master ~]# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.246.110:80 rr persistent 20 -> 192.168.246.162:80 Route 1 0 0 -> 192.168.246.163:80 Route 0 0 0 4. 所有RS配置(nginx1,nginx2) 配置好網(wǎng)站服務(wù)器,測(cè)試所有RS [root@test-nginx1 ~]# yum install -y nginx [root@test-nginx2 ~]# yum install -y nginx [root@test-nginx1 ~]# ip addr add dev lo 192.168.246.110/32 [root@test-nginx1 ~]# echo "net.ipv4.conf.all.arp_ignore = 1" >> /etc/sysctl.conf [root@test-nginx1 ~]# sysctl -p [root@test-nginx1 ~]# echo "web1..." >> /usr/share/nginx/html/index.html [root@test-nginx1 ~]# systemctl start nginx
注意事項(xiàng):如果之前配置了vip,導(dǎo)致顯示不了vip
需要執(zhí)行systemctl stop keepalived
#先停止在重啟
` systemctl start keepalived `
即可顯示vip
到此這篇關(guān)于keepalived+lvs 對(duì)nginx做負(fù)載均衡和高可用的文章就介紹到這了,更多相關(guān)nginx負(fù)載均衡和高可用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決nginx重新加載配置文件,配置文件沒(méi)生效問(wèn)題
這篇文章主要介紹了解決nginx重新加載配置文件,配置文件沒(méi)生效問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06Nginx IP封禁及自動(dòng)封禁IP的實(shí)現(xiàn)
本文主要介紹了Nginx IP封禁及自動(dòng)封禁IP的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01使用nginx進(jìn)行負(fù)載均衡的搭建全過(guò)程
負(fù)載均衡用于從“upstream”模塊定義的后端服務(wù)器列表中選取一臺(tái)服務(wù)器接受用戶(hù)的請(qǐng)求,下面這篇文章主要給大家介紹了關(guān)于使用nginx進(jìn)行負(fù)載均衡的搭建全過(guò)程,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08Linux下安裝MongoDB的實(shí)現(xiàn)步驟
這篇文章主要介紹了Linux下安裝MongoDB的實(shí)現(xiàn)步驟的相關(guān)資料,希望通過(guò)本文能幫助到大家,讓大家輕松安裝,需要的朋友可以參考下2017-10-10Nginx配置srcache_nginx模塊搭配Redis建立緩存系統(tǒng)
這篇文章主要介紹了Nginx配置srcache_nginx模塊搭配Redis建立緩存系統(tǒng)的方法,文中關(guān)于Nginx模塊和Redis數(shù)據(jù)庫(kù)的安裝就不再說(shuō)明了,這里只關(guān)注配置搭建階段,需要的朋友可以參考下2016-01-01