LVS+Keepalived负载均衡方案赵峻峰Blog:@163.comE-mail:zhaojunfeng@msn.com运维解决方案系列之二负载均衡技术常见的三种负载方式缺点:Nginx:nginx是一种基于应用的负载解决方案,相对于内核级的转发而言,性能还是有不少的差距。DNS轮询:对转发的机器无侦测能力,无法实现健康状态检查,后端服务器发生故障时,依然会收到转发的请求基于OS的NLB:严重依赖OS本身的功能,配置复杂效率低,节点数目受到系统本身制约共同的局限性:不能很好地提供Failover运维解决方案系列之二负载均衡技术LVS方案优势:•性能卓越:LVS是内核级别的负载均衡解决方案,具备非常明显的性能优势。•配置灵活:支持8种负载调度算法和3种转发模式•Keepalived实现Failover:相对于其他failover方式,keepalived配置简单:只有一个配置文件负载均衡技术运维解决方案系列之二拓扑结构图:用户负载均衡器用户负载均衡器用户负载均衡器数据库服务器应用服务器负载均衡技术运维解决方案系列之二访问逻辑:用户请求信息返还LVS-DR用户负载均衡技术运维解决方案系列之二应用服务器发生故障:用户负载均衡器应用服务器发生故障的情形负载均衡技术运维解决方案系列之二自动切换:用户负载均衡器应用服务器发生故障的情形负载均衡技术运维解决方案系列之二操作摘录•控制器安装ipvsadmln-sv/usr/src/kernels/2.6.18-92.el5PAE-i686/usr/src/linuxtarzxvfipvsadm-1.24.tar.gztdipvsadm-1.24makemakeinstall负载均衡技术运维解决方案系列之二操作摘录.控制器安装keepalivedtarkeepalived-1.1.15.tar.gzcdkeepalived-1.1.15./configureKeepalivedconfiguration------------------------Keepalivedversion:1.1.15Compiler:gccCompilerflags:-g-O2ExtraLib:-lpopt-lssl-lcryptoUseIPVSFramework:YesIPVSsyncdaemonsupport:YesUseVRRPFramework:YesUseLinkWatch:NoUseDebugflags:NoMakeMakeinstall负载均衡技术Keepalived配置文件#gurationFileforkeepalived#globaldefineglobal_defs{router_idLVS_MAXTHON_1}vrrp_sync_groupVGM{group{VI_M1}}vrrp_sync_groupVGB{group{VI_B1}}vrrp_instanceVI_M1{stateMASTERinterfaceeth0lvs_sync_daemon_intefaceeth0virtual_router_id51priority180advert_int5authentication{auth_typePASSauth_pass1111}virtual_ipaddress{61.135.120.4}}virtual_server61.135.120.480delay_loop6lb_algowlclb_kindDRpersistence_timeout50protocolTCP负载均衡技术运维解决方案系列之二connect_timeout3nb_get_retry3delay_before_retry3connect_port80}}real_server61.135.120.880{weight100TCP_CHECK{connect_timeout3nb_get_retry3delay_before_retry3connect_port80}}real_server61.135.120.1580{weight100TCP_CHECK{connect_timeout3nb_get_retry3delay_before_retry3connect_port80}}}负载均衡技术运维解决方案系列之二转发状态察看(摘录)[root@lvs~]#ipvsadm-lcnIPVSconnectionentriesproexpirestatesourcevirtualdestinationTCP00:56FIN_WAIT10.1.5.140:5964110.1.5.208:8010.1.5.128:80TCP00:40FIN_WAIT10.1.5.136:4567710.1.5.205:8010.1.5.15:80TCP01:16FIN_WAIT10.1.7.32:156010.1.5.207:8010.1.5.53:80TCP00:41FIN_WAIT10.1.9.88:224110.1.5.205:8010.1.5.173:80TCP00:06FIN_WAIT10.1.12.18:444610.1.5.205:8010.1.5.49:80TCP09:48ESTABLISHED10.1.5.141:3338710.1.5.203:808010.1.5.162:8080TCP01:04FIN_WAIT10.1.12.18:447310.1.5.205:8010.1.5.49:80TCP00:39FIN_WAIT10.1.5.35:5040310.1.5.208:8010.1.5.128:80TCP00:34FIN_WAIT10.1.11.93:146510.1.5.205:8010.1.5.15:80TCP01:53FIN_WAIT10.1.6.22:263210.1.5.205:8010.1.5.16:80TCP01:03FIN_WAIT10.1.13.18:252810.1.5.205:8010.1.5.16:80TCP00:26FIN_WAIT10.1.12.18:445610.1.5.205:8010.1.5.49:80TCP10:47ESTABLISHED10.1.5.168:4557510.1.5.205:8010.1.5.16:80TCP01:01FIN_WAIT10.1.7.29:483110.1.5.205:8010.1.5.173:80负载均衡技术运维解决方案系列之二再见2009-2-13负载均衡技术运维解决方案系列之二