1. 程式人生 > 實用技巧 >ipvs+ldirectord實現高可用ipvs

ipvs+ldirectord實現高可用ipvs

一、heartbeat準備

1、接上文HA叢集準備工作

2、 安裝heartbeat-ldirectord元件包

[[email protected]heartbeat]#yumlocalinstallheartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm

3、ldirectord元件簡介

ldirectord依賴於自己的配置檔案來生成ipvs的規則,因此,定義LVS叢集、新增RS都是在ldirectord的配置檔案中指定,而無需手動執行ipvsadm命令。ldirectord對LVS叢集的director高可用,並對LVS進群的RS提供健康狀態監測,若某節點出現故障,則會把它從集群系統中剔除,並在其回覆正常後,將它重新加入集群系統。ldirectord還可以呼叫ipvsadm命令建立LVS路由表資訊,只需要在/etc/ha.d/ldirectord.cf配置檔案中指明即可。


4、基本資訊

wKioL1gxFMuzyeDEAAAo9TfmwgU377.png


二、配置

RS:

1、準備RS指令碼
#!/bin/bash

vip=192.168.0.17
interface="lo:0"

case$1in
start)
echo1>/proc/sys/net/ipv4/conf/all/arp_ignore
echo1>/proc/sys/net/ipv4/conf/eth0/arp_ignore
echo2>/proc/sys/net/ipv4/conf/all/arp_announce
echo2>/proc/sys/net/ipv4/conf/eth0/arp_announce
ifconfig$interface$vipbroadcast$vipnetmask255.255.255.255up
routeadd-host$vipdev$interface
;;
stop)
echo0>/proc/sys/net/ipv4/conf/all/arp_ignore
echo0>/proc/sys/net/ipv4/conf/eth0/arp_ignore
echo0>/proc/sys/net/ipv4/conf/all/arp_announce
echo0>/proc/sys/net/ipv4/conf/eth0/arp_announce
ifconfig$interfacedown
;;
status)
ififconfiglo:0|grep$vip&>/dev/null;then
echo"ipvsisrunning."
else
echo"ipvsisstopped."
fi
;;
*)
echo"pleaseinput:`basename$0`{start|stop|status}"
exit1
esac

[
[email protected]
~]#chmod+xrs.sh 2、準備httpd [[email protected]~]#yuminstallhttpd [[email protected]~]#echo"ThisisRS">/var/www/html/index.html [[email protected]~]#servicehttpdstart [[email protected]~]#curl192.168.0.20 ThisisRS [[email protected]~]#./rs.shstart

主備Director測試

[[email protected]~]#ifconfigeth0:0192.168.0.17broadcast192.168.0.17netmask255.255.255.255up
[[email protected]~]#routeadd-host192.168.0.17deveth0:0
[[email protected]~]#ipvsadm-A-t192.168.0.17:80-srr
[[email protected]~]#ipvsadm-a-t192.168.0.17:80-r192.168.0.20-g

wKioL1gwc1mwyqRMAAAMjdMdBRY617.png

[[email protected]~]#ipvsadm-C
[[email protected]~]#routedel-host192.168.0.17
[[email protected]~]#ifconfigeth0:0down


主Director:node1配置

1、cp樣例配置檔案
[[email protected]~]#cd/usr/share/doc/heartbeat-ldirectord-2.1.4/
[[email protected]heartbeat-ldirectord-2.1.4]#cpldirectord.cf/etc/ha.d
[[email protected]heartbeat-ldirectord-2.1.4]#cd/etc/ha.d

2、配置檔案
##全域性配置
#GlobalDirectives
##健康狀態檢測超時時間間隔
checktimeout=3
##每一秒檢查一次
checkinterval=1
#fallback=127.0.0.1:80
##自動裝載配置檔案
autoreload=yes
##日誌檔案
logfile="/var/log/ldirectord.log"
##日誌檔案級別
#logfile="local0"
##郵件通知警告資訊
#emailalert="[email protected]"
##郵件通知間隔1小時
#emailalertfreq=3600
##郵件通知所有的狀態資訊
#emailalertstatus=all
##是否工作於靜默模式
quiescent=yes

##虛擬服務配置
#Sampleforanhttpvirtualservice
##VIP
virtual=192.168.0.17:80
##RSgate為dr型別
real=192.168.0.20:80gate
#real=192.168.6.3:80gate
#real=192.168.6.6:80gate
##backserver
fallback=127.0.0.1:80gate
##健康狀態檢查基於http協議
service=http
##請求的頁面
request=".health.html"
##檢查request=“”頁面中的字串是否一致
receive=""
##對多個虛擬主機進行檢查
virtualhost=some.domain.com.au
##排程型別為rr
scheduler=rr
##持久連線時長
#persistent=600
##掩碼
#netmask=255.255.255.255
##基於tcp的檢查,叢集服務型別
protocol=tcp
##檢查型別為互動式檢查
##checktype:connect是傳輸層檢查,ping是網路層檢查,negotlate是應用層檢查
##當checktype=negotlate時,ldirectord將基於指定的協議與各RS建立連線,完成應用層檢查
checktype=negotia
##檢查埠為80
checkport=80
##請求的頁面
request="index.html"
##請求的字串檢查
#receive="TestPage"
##對虛擬主機檢查
#virtualhost=


3、準備web服務,node1作為backserver提供sorryserver服務
[[email protected]ha.d]#vim/var/www/html/index.html
Thisissorryserver(node1)
[[email protected]ha.d]#servicehttpdstart
Startinghttpd:httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using192.168.0.15forServerName
[OK]
[[email protected]ha.d]#curl192.168.0.15
Thisissorryserver(node1)

4、將配置檔案cp給node2
[[email protected]ha.d]#scpldirectord.cfnode2:/etc/ha.d/


備Director:node2配置

[[email protected]~]#vim/var/www/html/index.html
Thisissorryserver(node2)
[[email protected]~]#servicehttpdstart
Startinghttpd:httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using192.168.0.16forServerName
[OK]
[[email protected]~]#curl192.168.0.16
Thisissorryserver(node2)

RS準備測試頁

[[email protected]~]#echo"ok">/var/www/html/.health.html

啟動服務

[[email protected]~]#serviceheartbeatstart;sshnode2'serviceheartbeatstart'


gui介面配置資源

1、定義資源組ipvs,定義叢集ip資源(vip)

wKioL1gxELCyetcIAADczpHFfEE299.png


2、定義ipvs規則,lsb格式不提供引數,ocf格式的資源代理須提供配置檔案

wKiom1gxEa7ieEOfAADaUNvR_Bk213.png


3、啟動資源

wKioL1gxEhXSmsReAAEwx1BWtYI866.png


4、驗證node2節點

[[email protected]~]#ipvsadm-L-n
IPVirtualServerversion1.2.1(size=4096)
ProtLocalAddress:PortSchedulerFlags
->RemoteAddress:PortForwardWeightActiveConnInActConn
TCP192.168.0.17:80rr
->192.168.0.20:80Route100

[[email protected]~]#ipaddshoweth0
2:eth0:<BROADCAST,MULTICAST,UP,LOWER_UP>mtu1500qdiscpfifo_faststateUPqlen1000
link/ether00:0c:29:15:ea:32brdff:ff:ff:ff:ff:ff
inet192.168.0.16/24brd192.168.0.255scopeglobaleth0
inet192.168.0.17/24brd192.168.0.255scopeglobalsecondaryeth0
inet6fe80::20c:29ff:fe15:ea32/64scopelink
valid_lftforeverpreferred_lftforever


5、驗證負載均衡叢集效果

wKiom1gxEu3wgWnYAAA-CgSsgsg478.png


6、檢測RS下線,director錯誤頁面

[[email protected]~]#mv/var/www/html/.health.html/var/www/html/a.html
[[email protected]~]#ipvsadm-L-n
IPVirtualServerversion1.2.1(size=4096)
ProtLocalAddress:PortSchedulerFlags
->RemoteAddress:PortForwardWeightActiveConnInActConn
TCP192.168.0.17:80rr
->127.0.0.1:80Local100
->192.168.0.20:80Route000

wKioL1gxE92TVSjvAABApx6xdqs999.png


同理檢查node1。



轉載於:https://blog.51cto.com/jiayimeng/1874717