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

简介:
前言:
在  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

相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
相关文章
|
6天前
|
开发框架 监控 .NET
Visual Basic的Web服务和REST API开发指南
【4月更文挑战第27天】本文探讨了使用Visual Basic(VB.NET)构建Web服务和RESTful API的方法。首先介绍了Web服务的基础和REST API的概念,然后阐述了.NET Framework与.NET Core/.NET 5+对VB.NET的支持,以及ASP.NET Core在Web开发中的作用。接着,详细讲解了创建RESTful API的步骤,包括控制器与路由设置、模型绑定与验证,以及返回响应。此外,还讨论了安全措施、测试方法、部署选项和监控策略。最后强调,VB.NET开发者可以通过ASP.NET Core涉足现代Web服务开发,拓宽技术领域。
|
8天前
|
应用服务中间件 网络安全 nginx
快速上手!使用Docker和Nginx部署Web服务的完美指南
快速上手!使用Docker和Nginx部署Web服务的完美指南
|
2月前
|
网络协议 Java Nacos
nacos常见问题之在web界面 上下线服务时报错 400如何解决
Nacos是阿里云开源的服务发现和配置管理平台,用于构建动态微服务应用架构;本汇总针对Nacos在实际应用中用户常遇到的问题进行了归纳和解答,旨在帮助开发者和运维人员高效解决使用Nacos时的各类疑难杂症。
34 0
|
2月前
|
监控 Serverless 测试技术
Serverless 应用引擎常见问题之做的web服务计费如何解决
Serverless 应用引擎(Serverless Application Engine, SAE)是一种完全托管的应用平台,它允许开发者无需管理服务器即可构建和部署应用。以下是Serverless 应用引擎使用过程中的一些常见问题及其答案的汇总:
410 3
|
2月前
|
负载均衡 Java 中间件
使用Go语言构建高性能Web服务
Go语言作为一种快速、高效的编程语言,其在构建高性能Web服务方面具有独特优势。本文将探讨如何利用Go语言开发和优化Web服务,以实现更高的性能和可伸缩性。
|
3月前
|
Arthas 监控 NoSQL
web服务性能监控方案
web服务性能监控方案
|
3天前
|
缓存 监控 测试技术
【Go语言专栏】使用Go语言构建高性能Web服务
【4月更文挑战第30天】本文探讨了使用Go语言构建高性能Web服务的策略,包括Go语言在并发处理和内存管理上的优势、基本原则(如保持简单、缓存和并发控制)、标准库与第三方框架的选择、编写高效的HTTP处理器、数据库优化以及性能测试和监控。通过遵循最佳实践,开发者可以充分利用Go语言的特性,构建出高性能的Web服务。
|
10天前
|
监控 Shell
Shell脚本监控WEB服务是否正常
Shell脚本监控WEB服务是否正常
|
16天前
|
JSON API 数据库
解释如何在 Python 中实现 Web 服务(RESTful API)。
在Python中实现Web服务(RESTful API)涉及选择框架(如Flask、Django、FastAPI),定义路由及处理函数(对应HTTP请求方法),处理请求,构建响应和启动服务器。以下是一个使用Flask的简单示例:定义用户列表,通过`@app.route`装饰器设置GET和POST请求处理函数,返回JSON响应,并用`app.run()`启动服务器。实际API会包含更复杂的逻辑和错误处理。
15 1
|
28天前
|
Ubuntu 网络安全 数据安全/隐私保护
ubuntu篇-配置FTP服务,本机和docker安装
通过以上步骤,你可以在Ubuntu上配置FTP服务,无论是本机安装还是Docker内安装,都可以提供FTP文件传输服务。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
22 1