免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
在redhat as 4 下配置lvs RedHat/Fedora 卓越資源

2007-10-20 22:54 

環(huán)境描述:
本文在配置LVS時(shí)使用三臺(tái)linux,一臺(tái)做Directorserver (192.168.0.25) ,兩臺(tái)做realserver(192.168.0.127 192.168.0.12,在配置lvs+heartbeat時(shí)又添加了一臺(tái)(192.168.0.126)做為備份主節(jié)點(diǎn),虛擬VIP: 192.168.0.100

軟件列表:
ipvsadm-1.24.tar.gz
libnet.tar 下載地址:http://www.packetfactory.net/libnet/ 穩(wěn)定版本是:1.1.2.1
e2fsprogs 可以用rpm 安裝光盤(pán)
heartbeat-2.0.2.tar.gz
2.6內(nèi)核已經(jīng)集成IPVS內(nèi)核補(bǔ)訂了,所以不再需要重新編譯內(nèi)核.

配置此集群分以下幾種情況:
(1)、配置基于DR模式Lvs集群
(2)、配置基于隧道模式Lvs集群
(3)、配置基于高可用Lvs+heartbeat
(4)、此種配置方式可以加強(qiáng)LVS的主節(jié)點(diǎn)的高安全性前提下(主節(jié)點(diǎn)簡(jiǎn)稱(chēng)DR,備份主節(jié)點(diǎn)DRbak),考慮充分利用資源可以將DRbak做為realserver

一、配置基于DR模式Lvs集群

1、下載ipvsadm管理程序
http://www.linuxvirtualserver.org/software/
注意對(duì)應(yīng)自己的內(nèi)核版本
ipvsadm-1.24.tar.gz
tar zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
make
make install

注意在make時(shí)可能會(huì)出現(xiàn)很多錯(cuò)誤的信息,請(qǐng)按照如下操作就可以心編譯正常
ln -s /usr/src/kernels/2.6.9-22.EL-i686/ /usr/src/linux
cd ipvsadm-1.24
make
make install

2、配置VIP腳本
[root@ns ~]#more /etc/init.d/lvsDR
#!/bin/sh
#create in 20060812 by ghb
# description: start LVS of Directorserver
VIP=192.168.0.100
RIP1=192.168.0.127
RIP2=192.168.0.128
#RIPn=192.168.0.128~254
GW=192.168.0.1
. /etc/rc.d/init.d/functions
case  $1  in
    start)
    echo "start LVS of DirectorServer"
    # set the Virtual IP Address
    /sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up
    /sbin/route add -host $VIP dev eth0:0
    #Clear IPVS table
    /sbin/ipvsadm -C
    #set LVS
    /sbin/ipvsadm -A -t $VIP:80 -s rr                   #(如果需要session保持添加-p 默認(rèn)保持300秒)
    /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g
    /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
    #/sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -g
    #Run LVS
    /sbin/ipvsadm
    #end
    ;;
    stop)
    echo "close LVS Directorserver"
    /sbin/ipvsadm -C
    ;;
    *)
    echo "Usage: $0" {start|stop}
    exit 1
esac
(-s rr 是使用了輪叫算法,可以自行選擇相應(yīng)的算法,更改rr就可以了,ipvsadm -h查看幫助。-g 是使用lvs工作DR直接路由模式,也可自行修改)
如果有多個(gè)realserver直接添加就可以了,之后啟動(dòng)此腳本就可以了。

3、配置realserver腳本
#!/bin/bash
#description : start realserver
#create in 20060812 by ghb
VIP=192.168.0.100
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p
#end
此腳本使realserver不響應(yīng)arp請(qǐng)求,將此腳本分別在realserver上執(zhí)行就可以了。
測(cè)試:分別啟動(dòng)realserver上的httpd服務(wù)
在realserver1 執(zhí)行 echo "This is realserver1" >  /var/www/html/index.html
在realserver2 執(zhí)行 echo "This is realserver2" >  /var/www/html/index.html
打開(kāi)IE瀏覽器輸入http://192.168.0.100 應(yīng)該可以分別看到:This is realserver1 和 This is realserver1。

二、配置基于隧道模式Lvs集群
1、安裝ipvsadmin方法和上面一樣,在此略過(guò)
2、配置LVS directorserver 腳本
[root@ns ~]# more /etc/init.d/tunlvs
#!/bin/sh
# description: start LVS of Directorserver
VIP=192.168.0.100
RIP1=192.168.0.127
RIP2=192.168.0.128
#RIPn=192.168.0.n
GW=192.168.0.1
. /etc/rc.d/init.d/functions
case $1 in
    start)
    echo "start LVS of DirectorServer"
    # set the Virtual IP Address
    /sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up
    /sbin/route add -host $VIP dev tunl0
    #Clear IPVS table
    /sbin/ipvsadm -C
    #set LVS
    /sbin/ipvsadm -A -t $VIP:80 -s rr
    /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -i
    /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i
    #/sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -i
    #Run LVS
    /sbin/ipvsadm
    #end
    ;;
    stop)
    echo "close LVS Directorserver"
    ifconfig tunl0 down
    /sbin/ipvsadm -C
    ;;
    *)
    echo "Usage: $0" {start|stop}
    exit 1
esac

3、配置realserver
[root@localhost ~]# more /etc/init.d/tunl
#!/bin/sh
# ghb in 20060812
# description: Config realserver tunl port and apply arp patch
VIP=192.168.0.100
. /etc/rc.d/init.d/functions
case $1 in
    start)
    echo "Tunl port starting"
    ifconfig tunl0 $VIP netmask 255.255.255.255 broadcast $VIP up
    /sbin/route add -host $VIP dev tunl0
    echo "1" > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
    echo "2" > /proc/sys/net/ipv4/conf/tunl0/arp_announce
    echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
    echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
    sysctl -p
    ;;
    stop)
    echo "Tunl port closing"
    ifconfig tunl0 down
    echo "1" > /proc/sys/net/ipv4/ip_forward
    echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce
    ;;
    *)
    echo "Usage: $0" {start|stop}
    exit 1
esac
如果有多個(gè)Virutal IP,可以使用tunl0:0,tunl0:1...。
此腳本分別在realserver上執(zhí)行,目的使realserver忽略arp響應(yīng),并設(shè)定vip.
測(cè)式同樣按照上面的方法測(cè)試。

三、配置基于高可用Lvs+heartbeat
1、確定LVS使用DR或/tun模式,請(qǐng)對(duì)照上面的配置。
本例使用tun模式
Director server 端腳本文件
[root@ns ~]# more /etc/init.d/tunlvs
#!/bin/sh
# description: start LVS of Directorserver
VIP=192.168.0.100
RIP1=192.168.0.127
RIP2=192.168.0.128
#RIPn=192.168.0.n
GW=192.168.0.1
. /etc/rc.d/init.d/functions
case $1 in
    start)
    echo "start LVS of DirectorServer"
    # set the Virtual IP Address
    /sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up
    /sbin/route add -host $VIP dev tunl0
    #Clear IPVS table
    /sbin/ipvsadm -C
    #set LVS
    /sbin/ipvsadm -A -t $VIP:80 -s rr
    /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -i
    /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i
    #/sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -i
    #Run LVS
    /sbin/ipvsadm
    #end
    ;;
    stop)
    echo "close LVS Directorserver"
    ifconfig tunl0 down
    /sbin/ipvsadm -C
    ;;
    *)
    echo "Usage: $0" {start|stop}
    exit 1
esac
realserver端同樣使用上面的配置文件就可以。

2、安裝heartbeat
libnet.tar 下載地址:http://www.packetfactory.net/libnet/ 穩(wěn)定版本是:1.1.2.1
e2fsprogs 可以用rpm 安裝光盤(pán)
heartbeat-2.0.2.tar.gz 下載地址: http://www.linux-ha.org/download/
2.1安裝
tar -zxvf libnet.tar.gz
cd libnet
./configure
make
make install
tar zxf heartbeat-1.99.4.tar.gz
cd heartbeat-1.99.4
./ConfigureMe configure --disable-swig --disable-snmp-subagent
make
make install
cp doc/ha.cf doc/haresources doc/authkeys /etc/ha.d/
cp ldirectord/ldirectord.cf /etc/ha.d/
配置:
主配置文件(/etc/ha.d/ha.cf)
#debugfile /var/log/ha-debug
logfile /var/log/ha-log #指名heartbeat的日志存放位置
#crm yes #支持ClusterResourceManager(集群資源管理)功能
#bcast eth1 #指明心跳方式使用以太廣播方式,并且是在eth1接口上進(jìn)行廣播。
logfacility local0
keepalive 2#指明心跳時(shí)間為2秒(即每?jī)擅腌娫趀th1上發(fā)送一次廣播)。
deadtime 30#指定在30秒內(nèi)沒(méi)有心跳信號(hào),則立即切換服務(wù)。
warntime 10 #指明心跳延遲的時(shí)間為十秒。當(dāng)10秒鐘內(nèi)備份機(jī)不能聯(lián)系上主機(jī)(當(dāng)前活動(dòng)的服務(wù)器,即無(wú)心跳信號(hào)),就會(huì)往日志中寫(xiě)入一個(gè)警告日志,但此時(shí)不會(huì)切換服務(wù)。
initdead 120 #With some configurations, the network takes some time to start working after a reboot. This is a separate deadtime to handle that case. It should be at least twice the normal deadtime.
udpport 694#Use port number 694 for bcast or ucast communication. This is the default, and the official IANA registered port number.
baud 19200
serial /dev/ttyS0
mcast eth0 225.0.0.1 694 1 0
# 當(dāng)主節(jié)點(diǎn)恢復(fù)后,是否自動(dòng)切回
auto_failback on
# stonith用來(lái)保證共享存儲(chǔ)環(huán)境中的數(shù)據(jù)完整性
#stonith baytech /etc/ha.d/conf/stonith.baytech
# watchdog能讓系統(tǒng)在出現(xiàn)故障1分鐘后重啟該機(jī)器。這個(gè)功能可以幫助服務(wù)器在確實(shí)停止心跳后能夠重新恢復(fù)心跳。
# 如果使用該特性,則在內(nèi)核中裝入softdog內(nèi)核模塊,用來(lái)生成實(shí)際的設(shè)備文件,輸入insmod softdog加載模塊。
# 輸入grep misc /proc/devices(應(yīng)為10),輸入cat /proc/misc | grep watchdog(應(yīng)為130)。
# 生成設(shè)備文件:mknod /dev/watchdog c 10 130 。
#watchdog /dev/watchdog
node ns.ghb.com #Mandatory. Hostname of machine in cluster as described by uname -n.
node nsbak.ghb.com
# 默認(rèn)heartbeat并不檢測(cè)除本身之外的其他任何服務(wù),也不檢測(cè)網(wǎng)絡(luò)狀況。
# 所以當(dāng)網(wǎng)絡(luò)中斷時(shí),并不會(huì)進(jìn)行Load Balancer和Backup之間的切換。
# 可以通過(guò)ipfail插件,設(shè)置'ping nodes'來(lái)解決這一問(wèn)題。詳細(xì)說(shuō)明參考hearbeat文檔。
#ping 192.168.136.1 172.16.0.1
ping_group group1 192.168.136.1 192.168.136.2
respawn root /usr/lib/heartbeat/ipfail
apiauth ipfail gid=root uid=root
# 其他一些插件可以在/usr/lib/heartbeat下找到
#apiauth ipfail uid=hacluster
#apiauth ccm uid=hacluster
#apiauth cms uid=hacluster
#apiauth ping gid=haclient uid=alanr,root
#apiauth default gid=haclient
資源文件(/etc/ha.d/haresources):
ns.aaa.com IPaddr::192.168.0.127/24/eth0 httpd
#設(shè)置ns.aaa.com為主節(jié)點(diǎn),集群服務(wù)器的ip地址為192.168.0.127 netmask 為255.255.255.240集群的服務(wù)有httpd
認(rèn)證文件(/etc/ha.d/authkeys),選取一種認(rèn)證方式,這個(gè)文件的權(quán)限必須是600
auth 1
1 crc
#2 sha1 sha1_any_password
#3 md5 md5_any_password
使用同樣的方法配置節(jié)點(diǎn)2
備份節(jié)點(diǎn)192.168.0.126 上的heartbeat和apache的配置與節(jié)點(diǎn)1要完全相同,lvs配置也要相同。
2.2
完裝完畢進(jìn)行測(cè)試,關(guān)閉主節(jié)點(diǎn)機(jī)器,另一臺(tái)自動(dòng)接管,主節(jié)點(diǎn)恢復(fù)后自動(dòng)接管回服務(wù)。如果以上測(cè)試沒(méi)有問(wèn)題,那么開(kāi)始和lvs整合。
配置Ldirectord
Ldirectord的作用是監(jiān)測(cè)Real Server,當(dāng)Real Server失效時(shí),把它從Load Balancer列表中刪除,恢復(fù)時(shí)重新添加,在安裝heartbeat時(shí)已經(jīng)安裝了Ldirectord。
配置(/etc/ha.d/ldirectord.cf):
# Global Directives
checktimeout=3
checkinterval=1
fallback=127.0.0.1:80
autoreload=yes
logfile="/var/log/ldirectord.log"
quiescent=yes
# A sample virual with a fallback that will override the gobal setting
virtual=192.168.0.100:80
real=192.168.0.127:80 gate
real=192.168.0.128:80 gate
fallback=127.0.0.1:80 gate
service=http
request="test.html"
receive="Test Page"
virtualhost="www.xxxxxx.net"
scheduler=rr
#persistent=600
#netmask=255.255.255.255
protocol=tcp
在每個(gè)Real Server的中添加監(jiān)控頁(yè):
echo "Test Page" >> /var/www/html/test.html
修改heartbeat的資源文件/etc/ha.d/haresources
ns.ghb.com 192.168.0.100 tunlvs ldirectord httpd
現(xiàn)在可以在主節(jié)點(diǎn)192.168.0.25上啟動(dòng)heartbeat
/etc/init.d/heartbeat start
在備份節(jié)點(diǎn)也啟動(dòng)heartbeat /etc/init.d/heartbeat start
測(cè)試:關(guān)閉主節(jié)點(diǎn),備份節(jié)點(diǎn)將自動(dòng)接管directorserver服務(wù)。(主節(jié)點(diǎn)正常時(shí)用ifconfig 是可以看tunl接可口的,而備份節(jié)點(diǎn)用ifconfig 命令是看不到的,只有在接管主節(jié)點(diǎn)服務(wù)后才是可以見(jiàn)的)
至此第三部分配置完畢。
四、考慮充份使用資源,將備份節(jié)點(diǎn)也做為realserver.
在主備director server 上都要做如下配置
1.director server 需要在腳本文件中將添加realserver,我們預(yù)先設(shè)置所有機(jī)器為realserver。
#!/bin/sh
# description: start LVS of Directorserver
VIP=192.168.0.100
RIP1=192.168.0.127
RIP2=192.168.0.128
RIP3=192.168.0.25
RIP4=192.168.0.126
GW=192.168.0.1
. /etc/rc.d/init.d/functions
case  $1 in
    start)
    echo "start LVS of DirectorServer"
    # set the Virtual IP Address
    /sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up
    /sbin/route add -host $VIP dev tunl0
    #Clear IPVS table
    /sbin/ipvsadm -C
    #set LVS
    /sbin/ipvsadm -A -t $VIP:80 -s rr
    /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -i
    /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i
    /sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -i
    /sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -i
    #Run LVS
    /sbin/ipvsadm
    #end
    ;;
    stop)
    echo "close LVS Directorserver"
    ifconfig tunl0 down
    /sbin/ipvsadm -C
    ;;
    *)
    echo "Usage: $0" {start|stop}
    exit 1
esac
2.修改/etc/ha.d/ldirectord.cf
# Global Directives
checktimeout=3
checkinterval=1
fallback=127.0.0.1:80
autoreload=yes
logfile="/var/log/ldirectord.log"
quiescent=yes
# A sample virual with a fallback that will override the gobal setting
virtual=192.168.0.100:80
real=192.168.0.126:80 gate
real=192.168.0.127:80 gate
real=192.168.0.128:80 gate
real=192.168.0.25:80 gate
fallback=127.0.0.1:80 gate
service="http"
request="test.html"
receive="Test Page"
virtualhost="www.xxxxx.net"
scheduler=rr
#persistent=600
#netmask=255.255.255.255
protocol=tcp
3、將realserver的啟動(dòng)腳本加入到主節(jié)點(diǎn),和備份節(jié)點(diǎn)中,并且這個(gè)腳本的啟動(dòng)級(jí)必須先于heartbeat,關(guān)閉級(jí)必須后于heartbeat
chkconfig tunl on 添加到系統(tǒng)啟動(dòng)
4、創(chuàng)建closetunl啟動(dòng)腳本,為啟動(dòng)director server 做準(zhǔn)備
more /etc/init.d/closetunl
#!/bin/sh
# create in 200608 ghb
# description: close tunl0 and arp_ignore
VIP=192.168.136.100
. /etc/rc.d/init.d/functions
case $1 in
    start)
    echo "start director server and close tunl"
    ifconfig tunl0 down
    echo "1" > /proc/sys/net/ipv4/ip_forward
    echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce
    ;;
    stop)
    echo "start Real Server"
    ifconfig tunl0 $VIP netmask 255.255.255.255 broadcast $VIP up
    /sbin/route add -host $VIP dev tunl0
    echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
    echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
    echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
    echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
    sysctl -p
    ;;
    *)
    echo "Usage: lvs" {start|stop}
    exit 1
esac
chmod 755 /etc/init.d/closetunl
5、修改/etc/ha.d/haresources
ns.wdxc.com closetunl 192.168.0.100 tunlvs ldirectord httpd
6、測(cè)試
http://192.168.0.100 應(yīng)該可以輪到四臺(tái)機(jī)器上

配置完畢
 

       總結(jié),上面就是本人在本配置LVS+heartbeat過(guò)程,本過(guò)程還沒(méi)涉及到共享存儲(chǔ)這塊,我覺(jué)得集群整套方案,共享存儲(chǔ)是相當(dāng)重要的部分,簡(jiǎn)易實(shí)現(xiàn)通過(guò)NFS也可以實(shí)現(xiàn)共享存儲(chǔ),但是在要求更大,更快時(shí),可以要考慮其的存儲(chǔ)方式如SAN等。還有就是后端數(shù)據(jù)庫(kù)之間的負(fù)載,同步問(wèn)題等,本人將在下一步解決關(guān)于共享存儲(chǔ),數(shù)據(jù)庫(kù)負(fù)載方面的問(wèn)題。也希望大家可以給出一些方案或是想法,大家共同討論一下,共同學(xué)習(xí),共同進(jìn)步。

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
LVS負(fù)載均衡
ipvsadm+keepalived 實(shí)現(xiàn)高可用負(fù)載均衡
集群系列四(基于ivs
LVS解決高并發(fā),大數(shù)據(jù)量
LVS(DR) KeepAlived On CentOS6 安裝配置說(shuō)明書(shū)
Linux下的LVS,Apache,resin配置負(fù)載均衡
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服