首页 > 代码库 > LVS+keepalived 下部署RTSP负载均衡
LVS+keepalived 下部署RTSP负载均衡
一、lvs 虚拟负载均衡服务器总体描述
主要涉及软件包:ipvsadm 和keepalived(或者heartbeat)
参考下载地址:http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-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+keepalived 下部署RTSP负载均衡