lvs虚拟负载均衡云服务器总体描述
下文给大家带来lvs 虚拟负载均衡云服务器总体描述,希望能够给大家在实际运用中带来一定的帮助,负载均衡涉及的东西比较多,理论也不多,网上有很多书籍,今天我们就用创新互联在行业内累计的经验来做一个解答。
成都创新互联长期为成百上千客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为桑日企业提供专业的成都网站建设、成都做网站,桑日网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。
一、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 虚拟负载均衡云服务器总体描述,如果大家还有什么地方需要了解的可以在创新互联行业资讯里查找自己感兴趣的或者找我们的专业技术工程师解答的,创新互联技术工程师在行业内拥有十几年的经验了。
当前名称:lvs虚拟负载均衡云服务器总体描述
当前网址:http://hbruida.cn/article/jhsjds.html