ubuntu server 10.4 下LVS-DR+heartbeat +Ldirectord实现web服务高可性负载均衡实验

本文涉及的产品
应用型负载均衡 ALB,每月750个小时 15LCU
网络型负载均衡 NLB,每月750个小时 15LCU
传统型负载均衡 CLB,每月750个小时 15LCU
简介:
前言:
在  ubuntu server 10.4 的LVS-DR+heartbeat 实验中实现了负载均衡器的高可用性,可是存在一个问题就是如果其中一台www服务器故障后,根据lvs的rr算法,当客户端有请求时还会访问到这台故障服务器。这时应用Ldirectord就可以解决这个问题。
那什么是Ldirectord, ldirectord is a daemon to monitor and administer real servers in a  LVS cluster of load balanced virtual servers.  ldirectord typically used as a resource for  Linux-HA , but can also be run from the command line.  ldirectord has a configuration file which specifies the virtual services and their associated real servers. When  ldirectord is initialised it creates the virtual services for the clutster.  ldirectord monitors the health of the real servers by periodically requesting a known URL and checking that the response contains an expected response. If a real server fails then the server is removed and will be reactivated once it comes back on line. If all the real servers are down then a fall-back server is inserted into the pool, which will made quiescent one of the real web servers comes back on line. Typically, the fall-back server is localhost. If an HTTP virtual service is being provided then it is useful to run an Apache HTTP server that returns a page indicating that the service is temporarily inaccessible. (引用自“ http://www.vergenet.net/linux/ldirectord/”),直观能看到那台服务器故障,用#sudo ipvsadm 看到的weight值为零(0)的那台就是。
实验环境:
1,配置主负载均衡器ubserver1:
    (1)安装Ldirectord软件包
    #sudo apt-get install ldirectord
#sudo cp /usr/share/doc/ldirectord/examples/ldirectord.cf  /etc/ha.d
    (2)ha.cf及authkeys配置文件内容不变与 ubuntu server 10.4 的LVS-DR+heartbeat 实验中相同
(3)haresources文件做以下改动
ubserver1 192.168.3.100 lvs.sh 改为
ubserver1 192.168.3.100 lvs.sh ldirectord
   (4)ldirectord.cf文件配置:
#sudo vim /etc/ha.d/ldirectord.cf
lvs-ldirectord5
checktype=negotiate时要求启用
request=”test.html” #在www服务器ubserver2,ubserver3的/var/www下建立test.html/页内容为“work”,这是因为: ldirectord monitors the health of the real servers by  periodically requesting a known  URL and  checking that the response contains an expected response
receive=”work”
checktype=connect时这两个配置可以注释掉因为 Connect only attemts to make a TCP/IP connection,我做实验时,把这两个注释掉,发现当一台www服务器down掉后,是发现不了的,不知道这是为什么。
*:ldirectord.cf的配置可以参考: http://linux.die.net/man/8/ldirectord
checktype = connect|external|negotiate|off|on|ping|checktimeoutN
Type of check to perform. Negotiate sends a request and matches a receive string. Connect only attemts to make a TCP/IP connection, thus the request and receive strings may be omitted. If checktype is a number then negotiate and connect is combined so that after each N connect attempts one negotiate attempt is performed. This is useful to check often if a service answers and in much longer intervalls a negotiating check is done. Ping means that ICMP ping will be used to test the availability of real servers. Ping is also used as the connect check for UDP services. Off means no checking will take place and no real or fallback servers will be activated. On means no checking will take place and real servers will always be activated. Default is negotiate.
2,配置从主负载均衡器ubserver5:
与主负载均衡器ubserver1的所做的修改相同。ldirectord.cf配置文件内容相同。
3,模拟故障:
关掉ubserver2的www服务后与启有后,用#sudo ipvsadm –L –n 查看结果
lvs-ldirecotrd4
4,用了Ldirectord后,当一台www服务器down掉后,在客户端不会出现错误页;如不用,则会。
总结:用lvs+heartbeat+ldirectord感觉要配置的东西的很多,ha.cf,haresources,authkeys,ldirectord.cf四个配置文件,还要在www服务器上建立让ldirectord发现它是否正常的网页,还要写LVS的脚本(实验用的lvs.sh就是)这样的配置过程给以后的维护带来困难。网上关于这方面的配置案例很多,都大同小异,一定要亲自实验下,不然不知道到底行不行。过程中会碰到很多问题,解决了就是学习。


本文转自xcjgutong 51CTO博客,原文链接:http://blog.51cto.com/xuchengji/333153

相关实践学习
SLB负载均衡实践
本场景通过使用阿里云负载均衡 SLB 以及对负载均衡 SLB 后端服务器 ECS 的权重进行修改,快速解决服务器响应速度慢的问题
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
相关文章
|
4月前
|
网络协议 Windows
Windows Server 2019 Web服务器搭建
Windows Server 2019 Web服务器搭建
126 0
|
6月前
|
开发者 前端开发 Apache
Apache Wicket Ajax揭秘:轻松几步,让你的Web应用告别“呆板”,焕发新生!
【8月更文挑战第31天】随着互联网技术的发展,Web应用的交互性成为评价网站成功的关键指标。Apache Wicket作为一款卓越的Java Web框架,不仅具备强大的组件化开发能力,还内置了对Ajax技术的支持,使开发者能轻松提升Web应用的交互体验。通过简单的代码示例展示了如何在不刷新页面的情况下异步更新页面元素,极大提升了用户体验。Wicket提供了多种Ajax组件和行为,如AjaxFallbackLink、AjaxButton等,满足不同场景需求,并支持自定义Ajax行为,帮助开发者实现复杂交互效果。合理运用Wicket的Ajax功能,可显著增强网站竞争力。
71 0
|
6月前
|
C# 开发者
全面提升开发效率:详解如何使用Blazor Server与SignalR打造实时Web应用,从零开始构建聊天室示例并掌握实时通信核心技术
【8月更文挑战第31天】提高生产力不仅关乎效率提升,更在于用更少时间完成更多任务。本文将通过具体代码示例,介绍如何结合 Blazor Server 和 SignalR 构建实时 Web 应用。从创建 Blazor 项目到添加 SignalR 支持,再到实现客户端与服务器间的实时通信,每个步骤都详细讲解。通过这一组合,C# 开发者能获得前后端一致的编程体验,轻松打造高效、响应迅速的实时应用。实时通信功能已在社交、协作等多个领域发挥重要作用,本文将助你掌握这一强大技术组合。
179 0
|
8月前
|
tengine 安全 应用服务中间件
修改Nginx/Tengine版本名称伪装任意WEB SERVER
修改Nginx/Tengine版本名称伪装任意WEB SERVER
125 1
|
9月前
|
机器学习/深度学习 SQL 人工智能
Web LLM 实验:间接注入
Web LLM 实验:间接注入
|
9月前
|
机器学习/深度学习 存储 SQL
Web LLM 实验:利用 LLM 中不安全的输出处理
Web LLM 实验:利用 LLM 中不安全的输出处理
|
9月前
|
SQL 机器学习/深度学习 人工智能
Web LLM 实验:利用 LLM API 实现 SQL 注入
Web LLM 实验:利用 LLM API 实现 SQL 注入
|
9月前
|
机器学习/深度学习 SQL 人工智能
Web LLM 实验:利用 LLM API 实现命令注入
Web LLM 实验:利用 LLM API 实现命令注入
|
8月前
|
移动开发 Java Maven
基于OSGi的Virgo Server最简单Spring web实例
基于OSGi的Virgo Server最简单Spring web实例
89 0
|
9月前
|
负载均衡 Java 微服务
Java错误:com.netflix.client.ClientException: Load balancer does not have available server for client
Java错误:com.netflix.client.ClientException: Load balancer does not have available server for client