下文給大家?guī)韑vs 虛擬負(fù)載均衡云服務(wù)器總體描述,希望能夠給大家在實(shí)際運(yùn)用中帶來一定的幫助,負(fù)載均衡涉及的東西比較多,理論也不多,網(wǎng)上有很多書籍,今天我們就用創(chuàng)新互聯(lián)在行業(yè)內(nèi)累計(jì)的經(jīng)驗(yàn)來做一個(gè)解答。
成都創(chuàng)新互聯(lián)長(zhǎng)期為成百上千客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為桑日企業(yè)提供專業(yè)的成都網(wǎng)站建設(shè)、成都做網(wǎng)站,桑日網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
一、lvs 虛擬負(fù)載均衡云服務(wù)器總體描述
主要涉及軟件包:ipvsadm 和keepalived(或者h(yuǎn)eartbeat)
1.24.tar.gz(linux安裝盤中有)
主機(jī):linux red-had 6.4
主機(jī)相關(guān)說明:
vip 10.4.127.160 對(duì)外暴露ip端口
master 10.4.121.212 控制負(fù)載均衡
backup 10.4.120.166 負(fù)載均衡備份
rtsp1 10.4.120.165 realserver
rtsp2 10.4.120.163 realserver
注意要求:服務(wù)器時(shí)間要求同步
命令:
修改時(shí)間同步配置文件:vi /etc/ntp.conf 增加server 10.4.121.166 ##10.4.121.166為時(shí)間服務(wù)器
啟動(dòng)時(shí)間同步服務(wù):service ntpd start
ntpd -p 配置 查看主機(jī)對(duì)表
時(shí)間同步問題:錯(cuò)誤1.Server dropped: Strata too high
原因:NTP server還沒有和其自身或者它的server同步上。
處理:NTP Server 修改/etc/ntp.conf
server 127.127.1.0
fudge 127.127.1.0 stratum 8
錯(cuò)誤2.Server dropped: no data
原因:查ntp server的防火墻
處理:service iptables stop
注意:ntpd 只能進(jìn)行時(shí)間微調(diào),如果服務(wù)器相差時(shí)間過多,需要使用ntpdate 10.4.121.166 調(diào)一下,之后啟動(dòng)服務(wù)實(shí)時(shí)微調(diào)
二、maser 上環(huán)境準(zhǔn)備
1,安裝keepalived
#tar -zxvf keepalived-1.1.15.tar.gz
# cd keepalived-1.1.15
./configure --sysconf=/etc --prefix=/usr/local/keepalived
# make && make install
2,下面設(shè)置keepalived以服務(wù)方式啟動(dòng)
設(shè)置成為服務(wù)并開機(jī)啟動(dòng):
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
/etc/rc.d/init.d/keepalived status
chkconfig --add keepalived
chkconfig keepalived on
#cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
#cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
#mkdir /etc/keepalived
#cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
#cp /usr/local/sbin/keepalived /usr/sbin/
#service keepalived start|stop
3,配置keepalived
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
}
notification_email_from
smtp_server smtp.163.com
smtp_connect_timeout 30
router_id LVS_DEVEL
lvs_id lvs01
}
vrrp_instance VI_1 {
state MASTER
interface eth0
lvs_sync_daemon_interface eth0
virtual_router_id 50 ##主從一致
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.4.127.160 ##vip
}
}
virtual_server 10.4.127.160 8042 {
delay_loop 2
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP ####換RTSP 在quicktime下測(cè)試失敗,keepalived不能失敗自動(dòng)剔除切換子例
real_server 10.4.120.165 8042 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 8042
}
}
real_server 10.4.120.163 8042 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 8042
}
}
}
----啟動(dòng) keepalived 后
[root@9data2 keepalived]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.4.121.212:8042 rr persistent 600
-> 10.4.120.165:8042 Route 1 0 5
-> 10.4.120.163:8042 Route 1 0 0
在2臺(tái)rtsp服務(wù)器10.4.120.165/10.4.120.163上添加如下腳本
#vim /etc/init.d/realserver.sh
#!/bin/bash
SNS_VIP=10.4.127.160
. /etc/rc.d/init.d/functions
case "$1" in
start)
ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
/sbin/route add -host $SNS_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 >/dev/null 2>&1
echo "RealServer Start OK"
;;
stop)
ifconfig lo:0 down
route del $SNS_VIP >/dev/null 2>&1
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
賦權(quán):
#chmod 755 /etc/init.d/realserver.sh
#sh /etc/init.d/realserver.sh start
四、Backup注意
此處只做master, backup類似操作 只需稍作修改就行
問題:
Keepalived_vrrp: bogus VRRP packet received on eth0 !!!
Keepalived_vrrp: VRRP_Instance(VI_1) ignoring received
解決:
修改/etc/keepalived/keepalived.conf 中virtual_route_id的值
比如
virtual_router_id 60 主從方都要改,默認(rèn)為51 ,重啟keepalived 即可
1.lvs_id改為lvs02
2.state改為BUCKUP
3.priority改為100,只要比MASTER小就可以。
4、主、從的 virtual_router_id 相同
看了以上關(guān)于lvs 虛擬負(fù)載均衡云服務(wù)器總體描述,如果大家還有什么地方需要了解的可以在創(chuàng)新互聯(lián)行業(yè)資訊里查找自己感興趣的或者找我們的專業(yè)技術(shù)工程師解答的,創(chuàng)新互聯(lián)技術(shù)工程師在行業(yè)內(nèi)擁有十幾年的經(jīng)驗(yàn)了。