• / 7
  • 下载费用:5 金币  

负载均衡--LVS Keepalived(终极文档).doc

关 键 词:
负载 均衡 LVSKEEPALIVED 终极 文档
资源描述:
利用 LVS+Keepalived 实现高性能高可用负载均衡背景:随着你的网站业务量的增长你网站的服务器压力越来越大?需要负载均衡方案!商业的硬件如F5又太贵,你们又是创业型互联公司如何有效节约成本,节省不必要的浪费?同时实现商业硬件一样的高性能高可用的功能?有什么好的负载均衡可伸张可扩展的方案吗?答案是肯定的!有!我们利用LVS+Keepalived基于完整开源软件的架构可以为你提供一个负载均衡及高可用的服务器。一. LVS+Keepalived 介绍1. LVSLVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统。本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一。目前有三种IP负载均衡技术(VS/NAT、VS/TUN 和VS/DR );八种调度算法(rr,wrr,lc,wlc,lblc,lblcr,dh,sh)。2. KeepalviedKeepalived在这里主要用作RealServer的健康状态检查以及 LoadBalance主机和BackUP主机之间failover 的实现二. 网站负载均衡拓朴图客户端202.168.128.202(VIP)通过keepalived 配置LVS(master)eth0:172.24.100.6eth1:202.168.128.101LVS(backup)eth0:172.24.100.7eth1:202.168.128.111172.24.100.70(VGATEWAY)通过keepalived 配置实现WEB1:172.24.100.4 WEB2:172.24.100.5三、配置IPLVS(master)增加一片网卡:eth0:172.24.100.6eth1:202.168.128.101LVS(backup )增加一片网卡:eh0:172.24.100.7eh1:202.168.128.111对外虚拟IP:202.168.128.202对内虚拟IP:172.24.100.70四. 安装LVS 和 Keepalvied软件包#lsmod | rep ip_vs#uname -r显示2.6.18-53.el5PAE#ln -s /usr/src/kernels/2.6.18-53.el5PAE-i686/ /usr/src/linux#tar zxvf ipvsadm-1.24.tar.gz#cd ipvsadm-1.24#make all ;stop)echo “Close LVS Directorserver“/sbin/ifconfig eth0:1 down/sbin/ipvsadm -C;;*)echo “Usage0{start|stop}“exit 1esac六. 利用Keepalvied实现负载均衡和和高可用性1. 主LVS上:172.24.100.6global_defs {router_id LVS_DEVEL}vrrp_sync_group lvs_1 {group {VI_1VI_GATEWAY}}vrrp_instance VI_1 {state MASTERinterface eth1virtual_router_id 51priority 100advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {202.168.128.202 #要指定子网掩码}}vrrp_instance VI_GATEWAY {state MASTERinterface eth0virtual_router_id 52priority 100advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {172.24.100.70}}virtual_server 202.168.128.202 80 {delay_loop 6lb_algo rrlb_kind NATnat_mask 255.255.0.0persistence_timeout 50protocol TCPreal_server 172.24.100.4 80 {weight 1TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3}}real_server 172.24.100.5 80 {weight 1TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3}}}2.从LVS:172.24.100.7global_defs {router_id LVS_DEVEL}vrrp_sync_group lvs_1 {group {VI_1VI_GATEWAY}}vrrp_instance VI_1 {state BACKUPinterface eth1virtual_router_id 51priority 90advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {202.168.128.202}}vrrp_instance VI_GATEWAY {state BACKUPinterface eth0virtual_router_id 52priority 90advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {172.24.100.70}}virtual_server 202.168.128.202 80 {delay_loop 6lb_algo rrlb_kind NATnat_mask 255.255.0.0persistence_timeout 50protocol TCPreal_server 172.24.100.4 80 {weight 1TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3}}real_server 172.24.100.5 80 {weight 1TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3}}}3.开启IP转发net.ipv4.ip_forward=1七、配置WEB端(172.24.100.4和172.24.100.5)1. 配置IP转发功能#vim /etc/sysctl.confnet.ipv4.ip_forward=1net.ipv4.conf.lo.arp_ignore = 1net.ipv4.conf.lo.arp_announce = 2net.ipv4.conf.all.arp_ignore = 1net.ipv4.conf.all.arp_announce = 22. 配置网关#vim /etc/sysconfig/network-scripts/ifcfg-eth0添加GATEWAY=172.24.100.70#service network restart八、启动服务# /usr/local/sbin/lvsdr.sh start (把这条语句写到/etc/rc.local中,开机启动)#/etc/init.d/keepalived start 启动keepalived 服务,keepalived 就能利用keepalived.conf 配置文件,实现负载均衡和高可用.九、测试1. # ip addr showeth0: mtu 1500 qdisc pfifo_fast qlen 1000link/ether 00:0c:29:9d:db:59 brd ff:ff:ff:ff:ff:ffinet 172.24.100.6/24 brd 172.24.0.255 scope global eth0inet 172.24.100.70/32 scope global eth0inet6 fe80::20c:29ff:fe9d:db59/64 scope linkvalid_lft forever preferred_lft forevereth1: mtu 1500 qdisc pfifo_fast qlen 1000link/ether 00:0c:29:9d:db:63 brd ff:ff:ff:ff:ff:ffinet 202.168.128.101/24 brd 202.168.128.255 scope global eth1inet 202.168.128.202/32 scope global eth1inet6 fe80::20c:29ff:fe9d:db63/64 scope linkvalid_lft forever preferred_lft forever………最后把主机宕机,到从机上使用ip addr show 查看,同上则OK。同时还需要用浏览器来测试。2. 查看lvs服务是否正常#watch ipvsadm –lnIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 202.168.128.202:80 wrr persistent 60-> 172.24.100.5:80 Route 3 0 0-> 172.24.100.4:80 Route 3 0 0#tail –f /var/log/message 监听日志,查看状态。3.将一台web 服务器关闭,然后在LVS 上用ipvsadm 命令查看,关闭的服务器应该从lvs集群中剔除了,再将关闭的服务器启动起来,用ipvsadm查看,又回来了。
展开阅读全文
1
  金牌文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
0条评论

还可以输入200字符

暂无评论,赶快抢占沙发吧。

关于本文
本文标题:负载均衡--LVS Keepalived(终极文档).doc
链接地址:http://www.gold-doc.com/p-256927.html
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服客服 - 联系我们
copyright@ 2014-2018 金牌文库网站版权所有
经营许可证编号:浙ICP备15046084号-3
收起
展开