CentOS5.5下Heartbeat+LVS(VS/DR)+Ldirectord分步驟實驗

Heartbeat+LVS(VS/DR)+Ldirectord+ipvsadm

——Cyent

共分爲3個實驗:(請從實驗一開始做起,因爲有些配置是共有的,在實驗一配置過後,在實驗二、三就不再贅述)

實驗一:Heartbeat雙機熱備

實驗二:LVS(VS/DR)負載均衡

實驗三:Heartbeat+LVS(VS/DR)+Ldirectord

 

做實驗前務必理清幾個概念:

1.       集羣的分類

2.       高可用性(HA)集羣和負載均衡集羣的區別與聯繫

3.       Heartbeat的幾個術語、理論(與HA集羣理論比較)

4.       Heartbeat3個常用插件

5.       LVS3種技術、8種算法

6.       LVSHeartbeat的關係

7.       ipvsadmheartbeatheartbeat-ldirectord的區別與作用

請參照:http://book.51cto.com/art/200912/168029.htm

 

環境:

總拓撲爲:

所有設備的操作系統均爲:CentOS 5.5

6臺機器:

Client

              主機名:client

              eth0192.168.10.100/24        子網1

Router

              主機名:router

              eth0192.168.10.1/24            子網1

              eth1192.168.60.1/24            子網2

Director 1(主節點)

              主機名:node1

              eth0192.168.60.132/24        子網2    DIP

              eth110.1.1.1/24                    子網3    Private IP

Director 2(備用節點)

              主機名:node2

              eth0192.168.60.133/24        子網2    DIP
              eth1
10.1.1.2/24                    子網3    Private IP

Real Server1

              主機名:real1

              eth0192.168.60.151/24        子網2    RIP

              lo0:0192.168.60.200/32 VIP

Real Server2

              主機名:real2

              eth0192.168.60.152/24        子網2    RIP

              lo0:0192.168.60.200/32 VIP

VIPVirtual IP):192.168.60.200/32

 

注:

1. Director是在LVS裏這麼稱呼的,但在Heartbeat裏叫做Node,故以下實驗中稱呼的不一樣

2. 本文檔的實驗均不設置域,只是單單的主機名,即執行uname -n輸出的就是以上各個機器的主機名

3. 以上的網絡設置現在就要配置好,並且保證網絡完全連通(除了2Private IP外),用ping來測試

 

 

實驗一:Heartbeat雙機熱備

環境:用到了ClientRouterNode 1Node 2,其他機器關閉

1. 在主節點node1和備用node2上分別安裝heartbeatlibnethttpd

[root@node1 ~]# yum -y install heartbeat libnet httpd

 

2. 獲得heartbeat的相關默認配置文件

[root@node1 ~]# cd /usr/share/doc/heartbeat-2.1.3/

[root@node1 heartbeat-2.1.3]# cp ha.cf authkeys haresources /etc/ha.d

 

3. heartbeat的相關配置(根據所示,有的註釋要去掉,有的不能去,其他的默認就好)

1) /etc/ha.d/ha.cf

logfile /var/log/ha-log

#crm yes      #去掉註釋後,纔會開啓HeartbeatLRMCRM模塊(現在別開啓),否則只有CCM

logfacility     local0

keepalive 2

deadtime 10

warntime 5

initdead 120

udpport 694

bcast eth1

#mcast eth0 ....

#ucast eth0 ....

auto_failback on

#watchdog /dev/watchdog          #如果去掉註釋,則要modprobe softdog,並保證系統啓動後會自動加載softdog模塊

node    node1

node    node2

ping 192.168.60.1

ping_group group1 192.168.60.151 192.168.60.152

respawn hacluster /usr/lib/heartbeat/ipfail

 

2) /etc/ha.d/haresources的配置(只有一行)

node1 IPaddr::192.168.60.200/32/eth0:0 httpd

 

3) /etc/ha.d/authkeys的配置(只有2行),按以下設置完之後chmod 600 authkeys

auth 1

1 crc

 

4) 要保證node1node2上的這3個配置文件一樣,因此可以在node1上配置完後scpnode2

 

5) node1node2/etc/hosts內容均爲:

127.0.0.1              localhost.localdomain localhost

::1           localhost6.localdomain6 localhost6

192.168.60.132           node1

192.168.60.133           node2

 

6) node1node2上執行chkconfig heartbeat on

node1node2上開啓heartbeat,執行service heartbeat start,觀察:

Starting High-Availability services:

2011/03/05_12:10:19 INFO:  Resource is stopped

                                                           [  OK  ]

如果出現這種情形,代表已經成功,不要被Resource is stopped給嚇到了

 

4. 測試:(基本的網絡配置、網絡連通測試以及node1node2上的httpd設置就不贅述了)

1) node1上執行ifconfig查看是否有eth0:0,再netstat -lntpu | grep httpd查看80端口是否監聽所有網卡;而此時在node2上,應該不存在eth0:0,並且httpd進程未開啓。

 

2) Client上執行for i in `seq 1 1000`; do curl http://192.168.60.200/; sleep 1; done來測試能否正常訪問VIPhttp服務。

 

3) node1的任一網卡連接斷掉,然後查看Clientcurl輸出的變化(建議node1node2的網頁內容設置不同,以便區分),是否30秒後curl輸出的變爲node2的網頁

 

實驗二:LVSVS/DR)負載均衡

環境:用到了ClientRouterDirector 1Real 1Real 2,其他機器關閉

1.       關閉Director 1heartbeat,即執行service heartbeat stop

 

2. Director 1上執行yum -y install ipvsadmDirector 2也可以現在就裝ipvsadm

 

3. Real 1Real 2上的/etc/sysctl.conf文件裏分別增加4行:

net.ipv4.conf.lo.arp_ignore = 1

net.ipv4.conf.lo.arp_announce = 2

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.all.arp_announce = 2

然後執行sysctl -p,使得立即生效。

 

4. Real 1Real 2上分別安裝httpd,並創建一個簡單主頁(便於區分)

 

5. Director 1上執行:

[root@node1 ~]# ipvsadm -A -t 192.168.60.200:80 -s wrr

[root@node1 ~]# ipvsadm -a -t 192.168.60.200:80 -r 192.168.60.151:80 -g -w 1

[root@node1 ~]# ipvsadm -a -t 192.168.60.200:80 -r 192.168.60.152:80 -g -w 2

然後執行ipvsadm -L查看是否已經增加成功

 

6. 測試:

Client上仍然執行for i in `seq 1 1000`; do curl http://192.168.60.200/; sleep 1; done 查看是否能成功訪問Real 1Real 2的網頁,正常情況下,應該是先訪問Real 2的網頁2次,然後再訪問Real 1的網頁1次,再訪問Real 2的網頁2次,如此循環下去。

 

實驗三:Heartbeat+LVSVS/DR+Ldirectord

環境:用到了所有機器

1.       node1node2上分別執行yum -y install heartbeat-ldirectord

 

2. 獲得heartbeat-ldirectord的相關默認配置文件,node2也一樣配置

[root@node1 ~]# cd /usr/share/doc/heartbeat-ldirectord-2.1.3/

[root@node1 heartbeat-ldirectord-2.1.3]# cp ldirectord.cf /etc/ha.d

 

3. node1node2/etc/ha.d/haresources內容修改爲:

node1 IPaddr::192.168.60.200/32/eth0:0 httpd ldirectord

 

4. node1node2上的/etc/hosts內容均改爲:

127.0.0.1               localhost.localdomain localhost

::1             localhost6.localdomain6 localhost6

192.168.60.132          node1

192.168.60.133          node2

192.168.60.151          real1

192.168.60.152          real2

 

5. node1node2上的/etc/ha.d/ldirectord.cf內容均修改爲:

checktimeout=5

checkinterval=2

#fallback=127.0.0.1:80

autoreload=yes

logfile="/var/log/ldirectord.log"

quiescent=no

virtual=192.168.60.200:80       #(以下行頭均要Tab一下)

        real=192.168.60.151:80 gate 1

        real=192.168.60.152:80 gate 2

        #fallback=127.0.0.1:80 gate

        service=http

        request=".healthcheck.html"

        receive="successful"

        #virtualhost=some.domain.com.au

        scheduler=wrr

        #persistent=20

        #netmask=255.255.255.255

        protocol=tcp

        checktype=negotiate

        checkport=80

        #request="index.html"

        #receive="Test Page"

        #virtualhost=www.x.y.z

 

6. Real 1Real 2/var/www/html裏建立.healthcheck.html文件(注意health前有個點),文件內容就一行successful

 

7. node1node2上重啓heartbeatservice heartbeat restart

 

8. 測試:

1)      node1上執行ipvsadm -L查看是否有2個路由條目

2)      node1netstat -lntpu | grep httpd是否所有網卡監聽,node2應該無此進程

3)      node1ifconfig,是否存在eth0:0,而node2上應該不存在

4)      Clientfor i in `seq 1 1000`; do curl http://192.168.60.200/; sleep 1; done 查看是否如實驗二一樣

5)      node1eth0拔掉,在Client上是否會呈現停止了一會,繼而訪問了node2,然後又開始訪問Real 1Real 2.此時node1上的eth0:0httpd進程、ipvsadm -L應該都沒有了,而node2上都有。

 

注:如果將ipvsadm命令寫入/etc/sysconfig/ipvsadm裏,並在/etc/ha.d/haresources裏寫上ipvsadm,會導致heartbeat剛啓動的短暫時間內,ipvsadm會將/etc/sysconfig/ipvsadm裏的內容全部加載,因此我選擇讓ldirectord自己檢測加載。

 

Powered by Cyent

2011-03-05

E-mail[email protected]

歡迎找茬!

歡迎轉載!

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章