keepalived安装与配置_面试官问LVS+keepalived+nginx怎么实现时该怎么答?
概述
前面大家已經(jīng)對基本概念有個了解了,接下來就是搭建過程了~
需求
1、LVS給兩臺nginx做負載均衡
2、keepalived做lvs高可用,同時做Real-Server健康檢查,如果發(fā)現(xiàn)Real-Server80端口沒開,就認為故障,從集群中剔除
3、在keepalived配置文件內(nèi)就能配置LVS
環(huán)境說明
這里大家要準備4臺服務器,5個IP(其中一個是虛擬IP)來做。
在負載均衡器端配置lvs+keepalived
1、配置linux系統(tǒng)內(nèi)核參數(shù)
LVS主備上面,配置linux系統(tǒng)內(nèi)核參數(shù):開啟內(nèi)核的路由模式
#vim /etc/sysctl.conf net.ipv4.ip.forward = 1立即生效
# sysctl -p2、LVS主備關(guān)閉iptables服務
#service iptables stop
3、LVS主備安裝LVS
可以選擇yum或源碼包的安裝方式,這里我選擇yum安裝
#yum install ipvsadm4、在主備服務器編譯安裝keepalived
(keepalived官網(wǎng):http://www.keepalived.org/)
1)安裝popt的開發(fā)包
#yum install popt-devel -y2)安裝openssl
#yum install openssl-devel -y3)安裝gcc
#yum install gcc -y4)安裝keepalived
#wget http://www.keepalived.org/software/keepalived-1.2.4.tar.gz#tar –zxvf keepalived-1.2.4.tar.gz#./configure –prefix=/usr/local/keepalived#make && make install5、LVS主備將keepalived設置開機啟動服務
#mkdir -p /etc/keepalived/#cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/#cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/#cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/#cp /usr/local/keepalived/sbin/keepalived /usr/sbin/# chkconfig --add keepalived# chkconfig --level 35 keepalived on6、LVS主備配置keepalived.conf
注意LVS網(wǎng)卡為eth1,下面介紹兩個配置文件
6.1、主LVS上面的keepalived的配置文件
! Configuration File for keepalivedglobal_defs { #全局配置部分 notification_email { #email 通知,基本不用此處可注釋掉 acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc #定義發(fā)送郵件的郵箱 smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL # 設置lvs的id,在一個網(wǎng)絡內(nèi)應該是唯一的}vrrp_instance VI_1 { #vrrp實例定義部分 state MASTER #設置lvs的狀態(tài),報錯MASTER和BACKUP兩種,必須大寫 interface eth1 #指定LVS網(wǎng)卡,設置對外服務的接口 virtual_router_id 51 #虛擬路由的標志,一組lvs的虛擬路由標識必須相同,這樣才能切換 priority 100 #定義優(yōu)先級,數(shù)字越大優(yōu)先級越高,在一個vrrp——instance下,master的優(yōu)先級必須大于backup advert_int 1 #設定master與backup負載均衡器之間同步檢查的時間間隔,單位是秒 authentication { #設置驗證類型和密碼 auth_type PASS #主要有PASS和AH兩種 auth_pass 1111 } virtual_ipaddress { #設置虛擬ip地址,可以設置多個,每行一個 xx.xx.xx.E }}virtual_server xx.xx.xx.E 80 { #設置虛擬服務器,需要指定虛擬ip和服務端口 delay_loop 2 #健康檢查時間間隔 lb_algo wrr #負載均衡調(diào)度算法 lb_kind DR #負載均衡轉(zhuǎn)發(fā)規(guī)則 #net_mask 255.255.255.0 persistence_timeout 60 #設置會話保持時間,對動態(tài)網(wǎng)頁非常有用 protocol TCP #指定轉(zhuǎn)發(fā)協(xié)議類型,有TCP和UDP兩種 real_server xx.xx.xx.C 80 { #配置服務器節(jié)點1,需要指定real server的真實IP地址和端口 weight 1 #設置權(quán)重,數(shù)字越大權(quán)重越高 TCP_CHECK { #realserver的狀態(tài)監(jiān)測設置部分單位秒 connect_timeout 3 #超時時間 nb_get_retry 3 #重試次數(shù) delay_before_retry 3 #重試間隔 connect_port 80 #監(jiān)測端口 } } real_server xx.xx.xx.D 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } }}6.2、LVS-backup的配置文件
! Configuration File for keepalivedglobal_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL}vrrp_instance VI_1 { state BACKUP interface eth1 virtual_router_id 51 priority 99 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { xx.xx.xx.E }}virtual_server xx.xx.xx.E 80 { delay_loop 2 lb_algo wrr lb_kind DR #net_mask 255.255.255.0 persistence_timeout 60 protocol TCP real_server xx.xx.xx.C 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server xx.xx.xx.D 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } }}到這里關(guān)于lvs和keepalived部分就已經(jīng)配置好了。
篇幅有限,關(guān)于LVS+KEEPALIVED部分就介紹到這了,后面主要介紹在relay_server端安裝配置nginx部分和測試集群是否生效,能不能自動漂移,感興趣的朋友可以關(guān)注下!
總結(jié)
以上是生活随笔為你收集整理的keepalived安装与配置_面试官问LVS+keepalived+nginx怎么实现时该怎么答?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 邮政放款慢是什么原因
- 下一篇: 主流mes厂商_MES市场的前景