您好,登錄后才能下訂單哦!
下文給大家帶來lvs 虛擬負載均衡云服務器總體描述,希望能夠給大家在實際運用中帶來一定的幫助,負載均衡涉及的東西比較多,理論也不多,網上有很多書籍,今天我們就用億速云在行業內累計的經驗來做一個解答。
一、lvs 虛擬負載均衡云服務器總體描述
主要涉及軟件包:ipvsadm 和keepalived(或者heartbeat)
1.24.tar.gz(linux安裝盤中有)
主機:linux red-had 6.4
主機相關說明:
vip 10.4.127.160 對外暴露ip端口
master 10.4.121.212 控制負載均衡
backup 10.4.120.166 負載均衡備份
rtsp1 10.4.120.165 realserver
rtsp2 10.4.120.163 realserver
注意要求:服務器時間要求同步
命令:
修改時間同步配置文件:vi /etc/ntp.conf 增加server 10.4.121.166 ##10.4.121.166為時間服務器
啟動時間同步服務:service ntpd start
ntpd -p 配置 查看主機對表
時間同步問題:錯誤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
錯誤2.Server dropped: no data
原因:查ntp server的防火墻
處理:service iptables stop
注意:ntpd 只能進行時間微調,如果服務器相差時間過多,需要使用ntpdate 10.4.121.166 調一下,之后啟動服務實時微調
二、maser 上環境準備
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,下面設置keepalived以服務方式啟動
設置成為服務并開機啟動:
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下測試失敗,keepalived不能失敗自動剔除切換子例
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
}
}
}
----啟動 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臺rtsp服務器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
賦權:
#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 主從方都要改,默認為51 ,重啟keepalived 即可
1.lvs_id改為lvs02
2.state改為BUCKUP
3.priority改為100,只要比MASTER小就可以。
4、主、從的 virtual_router_id 相同
看了以上關于lvs 虛擬負載均衡云服務器總體描述,如果大家還有什么地方需要了解的可以在億速云行業資訊里查找自己感興趣的或者找我們的專業技術工程師解答的,億速云技術工程師在行業內擁有十幾年的經驗了。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。