Heartbeat實現LVS的故障轉移
LVS是1998年5月由章文嵩博士發起和領導的優秀的叢集解決方案,許多商業的叢集產品,比如RedHat的Piranha,TurboLinux公司的Turbo Cluster等,都是基於LVS的核心程式碼的。在現實的應用中,LVS得到了大量的部署。[@more@]1.3 用Heartbeat實現LVS的高可用性
LVS可以對Apache等服務實現負載均衡,LVS與Ldirectord搭配使用也可以實現Apache等服務的故障轉移,但是LVS自己本身沒有冗餘機制,因此需要藉助第三方工具Heartbeat來實現。
1.3.1 Heartbeat簡介
Heartbeat最核心包括兩個部分:心跳監測部分和資源接管部分。心跳監測可以透過網路鏈路和串列埠進行,而且支援冗餘鏈路,它們之間相互傳送報文來告訴對方自己當前的狀態,如果在指定的時間內未受到對方傳送的報文,那麼就認為對方失效,這時需啟動資源接管模組來接管執行在對方主機上的資源或者服務。
1.3.2 Heartbeat安裝
建立使用者
groupadd haclient
useradd hacluster -g haclient
先安裝libnet
rpm -ivh libnet-1.1.2.1-2.1.i386.rpm
再安裝Heartbeat
tar jxvf Heartbeat-STABLE-2-1-STABLE-2.1.4.tar.bz2
cd Heartbeat-STABLE-2-1-STABLE-2.1.4
./ConfigureMe install --enable-all
1.3.3 配置LVS Drector的冗餘熱備
假設伺服器A,B的公網IP分別是:
A 192.168.100.10
B 192.168.100.4
叢集虛IP: 192.168.100.200
1.3.3.1 設定伺服器A,B的hostname為test10及test4
如不是請修改/etc/sysconfig/network的HOSTNAME部分,並執行
#hostname test10 以立即生效。
在/etc/hosts加入兩行:
192.168.100.10 test10
192.168.100.4 test4
1.3.3.2 修改伺服器A,B的/etc/sysctl.conf檔案,加入如下5行,並執行
#sysctl -p 以立即生效。
net.ipv4.ip_forward = 1
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_announce = 2
1.3.3.3 以root進入伺服器A,執行以下配置:
在/etc/init.d/heartbeat中的#!/bin/sh後插入一行:
ifconfig lo:100 192.168.100.200 netmask 255.255.255.255 up
#chkconfig heartbeat --level 35 on
#cd /etc/ha.d 進入叢集配置檔案目錄
#vi authkeys 建立叢集認證檔案
auth 3
3 md5 HA_2009
#chmod 600 authkeys 必要的操作
#vi ha.cf 建立叢集節點檔案
logfile /var/log/ha.log
#logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 80
mcast eth0 231.231.231.231 694 1 0
##有雙網路卡最好做個兩臺機器最好做交叉線連線,eth0 改eth1
#ucast eth0 192.168.100.4 #(test10直接指向對端ip,test4的化ucast eth0 192.168.100.10)
ping 192.168.100.2
auto_failback on
node test10
node test4
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
叢集中有兩個節點test10及test4,透過多播IP通訊(主要用於超過2個節點)
ping 192.168.100.2 閘道器ping檢測
#vi /etc/ha.d/resource.d/vip.sh 建立我們自己的叢集IP切換shell指令碼
#!/bin/sh
case "$4" in
start)
ifconfig lo:100 down
ifconfig $1:100 $2 netmask $3 up
;;
stop)
ifconfig $1:100 down
ifconfig lo:100 $2 netmask 255.255.255.255 up
;;
esac
/etc/ha.d/resource.d/SendArp 192.168.100.200/eth0 start
最後一行通知其他連線過這臺伺服器的客戶機VIP已經變更,MAC需要更新。
提供了LVS叢集備用節點在迴路地址監聽叢集虛IP以用於應用伺服器。
#chmod +x resource.d/vip.sh
#vi haresources 建立叢集資原始檔
test10 ldirectord::ldirectord.cf LVSSyncDaemonSwap::master vip.sh::eth0::192.168.100.200::255.255.255.0
注:ldirectord是用於管理LVS配置實現Apache的故障轉移,ldirectord.cf檔案的建立,請檢視《使用LVS+Ldirectord實現Web伺服器的負載均衡及故障轉移及其效能測試.doc》
1.3.3.4 在伺服器B上進行第2、3步操作,scp也可。
1.3.4 測試
1、在伺服器A、B上分別執行service heartbeat start 啟動叢集軟體,
及執行service httpd start啟動apache。
2、在伺服器A、B上分別執行:
#echo "WebSite A">/var/www/html/index.html
#echo "WebSite B">/var/www/html/index.html
3、在伺服器A、B上分別執行ifconfig
正常的話, 在伺服器A上出現eth0:100 IP:192.168.100.200
在伺服器B上出現l0:100 IP:192.168.100.200
在伺服器A上執行service heartbeat stop,結果是:
在伺服器A上出現lo0:100 IP:192.168.100.200
在伺服器B上出現eth0:100 IP:192.168.100.200
在伺服器A上執行service heartbeat start將恢復正常情況。
LVS可以對Apache等服務實現負載均衡,LVS與Ldirectord搭配使用也可以實現Apache等服務的故障轉移,但是LVS自己本身沒有冗餘機制,因此需要藉助第三方工具Heartbeat來實現。
1.3.1 Heartbeat簡介
Heartbeat最核心包括兩個部分:心跳監測部分和資源接管部分。心跳監測可以透過網路鏈路和串列埠進行,而且支援冗餘鏈路,它們之間相互傳送報文來告訴對方自己當前的狀態,如果在指定的時間內未受到對方傳送的報文,那麼就認為對方失效,這時需啟動資源接管模組來接管執行在對方主機上的資源或者服務。
1.3.2 Heartbeat安裝
建立使用者
groupadd haclient
useradd hacluster -g haclient
先安裝libnet
rpm -ivh libnet-1.1.2.1-2.1.i386.rpm
再安裝Heartbeat
tar jxvf Heartbeat-STABLE-2-1-STABLE-2.1.4.tar.bz2
cd Heartbeat-STABLE-2-1-STABLE-2.1.4
./ConfigureMe install --enable-all
1.3.3 配置LVS Drector的冗餘熱備
假設伺服器A,B的公網IP分別是:
A 192.168.100.10
B 192.168.100.4
叢集虛IP: 192.168.100.200
1.3.3.1 設定伺服器A,B的hostname為test10及test4
如不是請修改/etc/sysconfig/network的HOSTNAME部分,並執行
#hostname test10 以立即生效。
在/etc/hosts加入兩行:
192.168.100.10 test10
192.168.100.4 test4
1.3.3.2 修改伺服器A,B的/etc/sysctl.conf檔案,加入如下5行,並執行
#sysctl -p 以立即生效。
net.ipv4.ip_forward = 1
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_announce = 2
1.3.3.3 以root進入伺服器A,執行以下配置:
在/etc/init.d/heartbeat中的#!/bin/sh後插入一行:
ifconfig lo:100 192.168.100.200 netmask 255.255.255.255 up
#chkconfig heartbeat --level 35 on
#cd /etc/ha.d 進入叢集配置檔案目錄
#vi authkeys 建立叢集認證檔案
auth 3
3 md5 HA_2009
#chmod 600 authkeys 必要的操作
#vi ha.cf 建立叢集節點檔案
logfile /var/log/ha.log
#logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 80
mcast eth0 231.231.231.231 694 1 0
##有雙網路卡最好做個兩臺機器最好做交叉線連線,eth0 改eth1
#ucast eth0 192.168.100.4 #(test10直接指向對端ip,test4的化ucast eth0 192.168.100.10)
ping 192.168.100.2
auto_failback on
node test10
node test4
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
叢集中有兩個節點test10及test4,透過多播IP通訊(主要用於超過2個節點)
ping 192.168.100.2 閘道器ping檢測
#vi /etc/ha.d/resource.d/vip.sh 建立我們自己的叢集IP切換shell指令碼
#!/bin/sh
case "$4" in
start)
ifconfig lo:100 down
ifconfig $1:100 $2 netmask $3 up
;;
stop)
ifconfig $1:100 down
ifconfig lo:100 $2 netmask 255.255.255.255 up
;;
esac
/etc/ha.d/resource.d/SendArp 192.168.100.200/eth0 start
最後一行通知其他連線過這臺伺服器的客戶機VIP已經變更,MAC需要更新。
提供了LVS叢集備用節點在迴路地址監聽叢集虛IP以用於應用伺服器。
#chmod +x resource.d/vip.sh
#vi haresources 建立叢集資原始檔
test10 ldirectord::ldirectord.cf LVSSyncDaemonSwap::master vip.sh::eth0::192.168.100.200::255.255.255.0
注:ldirectord是用於管理LVS配置實現Apache的故障轉移,ldirectord.cf檔案的建立,請檢視《使用LVS+Ldirectord實現Web伺服器的負載均衡及故障轉移及其效能測試.doc》
1.3.3.4 在伺服器B上進行第2、3步操作,scp也可。
1.3.4 測試
1、在伺服器A、B上分別執行service heartbeat start 啟動叢集軟體,
及執行service httpd start啟動apache。
2、在伺服器A、B上分別執行:
#echo "WebSite A">/var/www/html/index.html
#echo "WebSite B">/var/www/html/index.html
3、在伺服器A、B上分別執行ifconfig
正常的話, 在伺服器A上出現eth0:100 IP:192.168.100.200
在伺服器B上出現l0:100 IP:192.168.100.200
在伺服器A上執行service heartbeat stop,結果是:
在伺服器A上出現lo0:100 IP:192.168.100.200
在伺服器B上出現eth0:100 IP:192.168.100.200
在伺服器A上執行service heartbeat start將恢復正常情況。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/124805/viewspace-1040162/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 基於heartbeat的NFS HA實現(轉)NFS
- 基於heartbeat的NFS HA實現 (轉)NFS
- Amoeba實現MySQL的負載均衡、故障轉移MySql負載
- 4.2.13 主備庫實現自動故障轉移
- 11g DataGuard實現故障轉移(Failover)AI
- docker搭建redis叢集和Sentinel,實現故障轉移DockerRedis
- 基於istio實現單叢集地域故障轉移
- 使用ProxySQL實現MySQL Group Replication的故障轉移、讀寫分離(一)MySql
- dolphinscheduler 實現master當機故障轉移能力原始碼分析AST原始碼
- inux 雙網路卡繫結(bonding)實現負載均衡或故障轉移(轉)UX負載
- LVS+Heartbeat 高可用叢集方案操作記錄
- 搭建Windows故障轉移群集Windows
- Heartbeat Score的計算(轉)
- 理解透明應用程式故障轉移 (TAF) 和快速連線故障轉移 (FCF)
- LVS-NAT模式的實現模式
- [AlwaysOn] AlwaysOn可用性組的故障轉移和故障轉移模式[中英文對照] 3模式
- [AlwaysOn] AlwaysOn可用性組的故障轉移和故障轉移模式[中英文對照] 6模式
- [AlwaysOn] AlwaysOn可用性組的故障轉移和故障轉移模式[中英文對照] 5模式
- [AlwaysOn] AlwaysOn可用性組的故障轉移和故障轉移模式[中英文對照] 4模式
- [AlwaysOn] AlwaysOn可用性組的故障轉移和故障轉移模式[中英文對照] 2模式
- [AlwaysOn] AlwaysOn可用性組的故障轉移和故障轉移模式[中英文對照] 1模式
- Oracle ADG Heartbeat failed to connect to standby故障案例OracleAI
- Mysql MHA部署-05故障轉移MySql
- 伺服器叢集的故障轉移方案伺服器
- 使用etcd選舉sdk實踐master/slave故障轉移AST
- Linux 系統雙網路卡繫結配置實現負載均衡和故障轉移Linux負載
- 5 切換和故障轉移操作
- Oracle Dataguard故障轉移(failover)操作OracleAI
- Sentinel哨兵模式解決故障轉移模式
- redis健康檢查與故障轉移Redis
- ORACLE RAC TAF 配置(透明故障轉移)Oracle
- 實現控制元件的移動、改變大小(DELPHI實現) (轉)控制元件
- 【Redis】Redis Cluster-叢集故障轉移Redis
- 【Mycat】Mycat故障轉移之writetype與switchtype
- keepalive配置mysql自動故障轉移MySql
- 配置 RAC 負載均衡與故障轉移負載
- 資料庫映象和故障轉移群集資料庫
- 理解透明應用程式故障轉移 (TAF) 和快速連線故障轉移 (FCF) (文件 ID 1602113.1)