L8.1 lvs+heartbeat-ldirectord实现高可用负载均衡
lvs+heartbeat-ldirectord實(shí)現(xiàn)高可用負(fù)載均衡
拓?fù)?#xff1a;
IPVS規(guī)則與heartbeat
ipvs規(guī)則不再使用ipvsadm配置,而是依靠heartbeat的包工具ldirectord去生成規(guī)則
并且ldirectord有檢測(cè)后端RS健康狀況的機(jī)制(利用權(quán)重,非常正常剔除(w=0),正常后添加)。
刪除之前 heartbeat v2 crm lamp配置的約束和資源
節(jié)點(diǎn)分別停止heartbeat:/etc/init.d/heartbeat stop
規(guī)劃
ipvs-ld節(jié)點(diǎn):?192.168.0.190 ?node1
ipvs-ld點(diǎn):?192.168.0.201 node2
RS:?192.168.0.193 node3 ,192.168.0.202 node4
lvs vip 192.168.0.199
ldirectord依賴(lài)于自己的配置文件生成ipvs規(guī)則,因此,定義集群服務(wù),添加RS都在配置文件中指定,而無(wú)需手動(dòng)執(zhí)行ipvsadm命令;
ldirectord能對(duì)各RS的健康狀態(tài)做檢測(cè),并能實(shí)現(xiàn)按需添加或者刪除各RS。
1,兩個(gè)節(jié)點(diǎn)安裝?heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm?
[root@node2?heartbeat2]#?rpm?-ivh?heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm?
error:?Failed?dependencies:
ipvsadm?is?needed?by?heartbeat-ldirectord-2.1.4-12.el6.x86_64
perl(LWP::Debug)?is?needed?by?heartbeat-ldirectord-2.1.4-12.el6.x86_64
perl(LWP::UserAgent)?is?needed?by?heartbeat-ldirectord-2.1.4-12.el6.x86_64
perl(Mail::Send)?is?needed?by?heartbeat-ldirectord-2.1.4-12.el6.x86_64
[root@node2?heartbeat2]#yum install heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm -y
依賴(lài)包如下:
2,LVS,DR模式配置
配置RS
node3 ,node4主機(jī)分別同樣配置主機(jī):
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
?echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
ifconfig eth0:0 192.168.0.199 broadcast 192.168.0.199 netmask 255.255.255.255
sysctl -p
route add -host 192.168.0.199 dev eth0:0?
/etc/init.d/httpd start?
curl 192.168.0.194?
配置DR主機(jī)ipvs
ifconfig eth0:0 192.168.0.199 broadcast 192.168.0.199 netmask 255.255.255.255
route add -host 192.168.0.199 dev eth0:0
[root@node1?~]#?ipvsadm?-A?-t?192.168.0.199:80?-s?rr
[root@node1?~]#?ipvsadm?-a?-t?192.168.0.199:80?-r?192.168.0.202?-g?-w?1
[root@node1?~]#?ipvsadm?-a?-t?192.168.0.199:80?-r?192.168.0.194?-g?-w?1
訪問(wèn)測(cè)試成功:
3,測(cè)試出成功后,刪除ipvs規(guī)則;
[root@node1?~]#?ipvsadm?-C
[root@node1?~]#?ipvsadm?-L
IP?Virtual?Server?version?1.2.1?(size=4096)
Prot?LocalAddress:Port?Scheduler?Flags
??->?RemoteAddress:Port???????????Forward?Weight?ActiveConn?InActConn
[root@node1?~]#?route?del?-host?192.168.0.199
[root@node1?~]#?ifconfig?eth0:0?down
4,使用ldirectord文件配置規(guī)則
?cd /usr/share/doc/heartbeat-ldirectord-2.1.4/
cp ldirectord.cf /etc/ha.d/?
配置文件說(shuō)明:
#?Global?Directives
checktimeout=3??#超時(shí)時(shí)間間隔
checkinterval=1?#向后端檢查的時(shí)間,即每1秒檢查一次,3秒超時(shí)。
#fallback=127.0.0.1:80?#sorry page
autoreload=yes??#自己不用做reload,文件改變后自動(dòng)裝載。
logfile="/var/log/ldirectord.log"???????#自己的日志
#logfile="local0"
#emailalert="admin@x.y.z"
#emailalertfreq=3600
#emailalertstatus=all
quiescent=yes
...
以ftp為列說(shuō)明:
#virtual=192.168.6.240:21 ? ?#vip
#???????real=192.168.16.3:21?masq ? ?#rs
#???????real=192.168.16.5:21?masq ? ?#rs
#???????fallback=127.0.0.1:21 ? ? ? ? ? ?#sorry page
#???????service=ftp ? ? ? ? ? ? ? ? ? ? ? ? ? ?#表示用ftp協(xié)議檢查
#???????checkport=21 ? ? ? ? ? ? ? ? ? ? ? ?#表示檢查21號(hào)端口,在tcp層
#???????scheduler=wlc ? ? ? ? ? ? ? ? ? ? ? ?#調(diào)度算法
#???????scheduler=rr ? ? ? ? ? ? ? ? ? ? ? ? ? ?#調(diào)度算法
#???????#persistent=600 ? ? ? ? ? ? ? ?#持久連接時(shí)間為600秒。注視表示沒(méi)開(kāi)啟持久連接
#???????#netmask=255.255.255.255
#???????protocol=tcp ? ? ? ? ? ? ? ? ? ? ? ? ? ?#集群服務(wù)協(xié)議類(lèi)型
#???????checktype=negotiate ? ? ? ? ? ? ? ?#協(xié)商類(lèi)型檢查,表示下面的登錄和密碼
#???????login="anonymous" ? ? ? ? ? ? ? ?#用anonymous登錄
#???????passwd="ldirectord@localhost" ? ?#密碼
#???????request="welcome.msg" ? ? ? ? ? ?#請(qǐng)求獲取到welcome.msg文件
#???????receive="test" ? ? ? ? ? ? ? ? ? ? ? ? ? ?#回答test字符串
以http說(shuō)明:
virtual=192.168.6.240:80
????????real=192.168.6.2:80?gate
????????real=192.168.6.3:80?gate
????????real=192.168.6.6:80?gate
????????fallback=127.0.0.1:80?gate
????????service=http
????????request="index.html" ? #請(qǐng)求哪個(gè)頁(yè)面
????????receive="Test?Page" ? ? ? ?#必須返回哪個(gè)字符串,RS才算是正常的
????????virtualhost=some.domain.com.au ? ?#對(duì)虛擬主機(jī)單獨(dú)檢測(cè)
????????scheduler=rr
????????#persistent=600
????????#netmask=255.255.255.255
????????protocol=tcp
????????checktype=negotiate
????????checkport=80
????????request="index.html"
????????receive="Test?Page"
????????virtualhost=www.x.y.z
常用的檢測(cè)類(lèi)型:
checktype = connect|external|negotiate|off|on|ping|checktimeoutN
ip層:connect: syn ,ack就行了
網(wǎng)絡(luò)層:ping
應(yīng)用層:negotiate
配置文件修改:
# Sample for an http virtual service
virtual=192.168.0.199:80
? ? ? ? real=192.168.0.194:80 gate
? ? ? ? real=192.168.0.202:80 gate
? ? ? ? fallback=127.0.0.1:80 gate
? ? ? ? protocol=tcp
? ? ? ? checkport=80
? ? ? ? checktype=negotiate
? ? ? ? service=http
? ? ? ? request=".health.html"
? ? ? ? receive="OK"
? ? ? ? scheduler=rr
? ? ? ? #persistent=600
? ? ? ? #netmask=255.255.255.255
將配置文件復(fù)制到node2節(jié)點(diǎn)
[root@node1?ha.d]#?scp?ldirectord.cf?node2:/etc/ha.d/
兩臺(tái)DR添加sorry page:
vim /var/www/html/index.html
node1 sorry server
兩臺(tái)RS 添加.health.html
vim?/var/www/html/.health.html
測(cè)試網(wǎng)頁(yè)都能訪問(wèn)。
5,配置hb_gui crm
定義組ipvs
? ? 定義集群ip clusterip
? ? 定義 ipvs規(guī)則 ipsrules ?(使用ldirectord定義)
啟動(dòng)組
6,測(cè)試
注意:兩個(gè)HA-DR應(yīng)該開(kāi)機(jī)自動(dòng)啟動(dòng)httpd,sorry page頁(yè)面展示
sorry server頁(yè)面,兩臺(tái)RS,httpd都stop,HA-LVS權(quán)重Weight 為1
通過(guò)設(shè)置權(quán)重為0來(lái)剔除RS。
轉(zhuǎn)載于:https://blog.51cto.com/disheng/1706848
總結(jié)
以上是生活随笔為你收集整理的L8.1 lvs+heartbeat-ldirectord实现高可用负载均衡的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: cutycapt(php截图工具)
- 下一篇: 实现将一个字符串转化成对应的整形数字