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

本文涉及的产品
网络型负载均衡 NLB,每月750个小时 15LCU
传统型负载均衡 CLB,每月750个小时 15LCU
应用型负载均衡 ALB,每月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)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
相关文章
|
3月前
|
弹性计算 监控 负载均衡
|
2天前
|
负载均衡 网络协议 Linux
LVS,软负载均衡
LVS(Linux Virtual Server)是一项广泛应用的负载均衡技术,由章文嵩博士于1998年发起,自Linux 2.4.24版本起成为官方内核的一部分。LVS通过四层负载均衡技术实现高性能、高可用的服务器集群,支持多种调度算法和工作模式(如D-NAT、full-NAT、IP隧道、DR),适用于HTTP、数据库等应用。相比7层负载均衡器(如Nginx、HAProxy),LVS具有更高的并发处理能力和更低的资源消耗,适合大规模流量分发。本期文章详细介绍了LVS的工作原理、优势与不足,并对比了常见的负载均衡产品,帮助读者根据具体需求选择合适的解决方案。
LVS,软负载均衡
|
3月前
|
运维 负载均衡 算法
|
2月前
|
负载均衡 算法 Linux
LVS+Keepalived:实现高效软负载均衡的利器
本文介绍了如何使用LVS(Linux Virtual Server)和Keepalived搭建高可用负载均衡集群。LVS通过不同调度算法将请求转发给后端服务器,而Keepalived基于VRRP协议实现服务高可用,避免IP单点故障。具体步骤包括环境准备、安装配置ipvsadm和Keepalived、启动服务及测试。文中还详细解释了配置文件中的关键参数,并提供了故障转移测试方法。最后,文章简要对比了软件、硬件和云负载均衡方案的特点,帮助读者选择合适的负载均衡策略。
416 4
|
4月前
|
消息中间件 监控 Ubuntu
大数据-54 Kafka 安装配置 环境变量配置 启动服务 Ubuntu配置 ZooKeeper
大数据-54 Kafka 安装配置 环境变量配置 启动服务 Ubuntu配置 ZooKeeper
153 3
大数据-54 Kafka 安装配置 环境变量配置 启动服务 Ubuntu配置 ZooKeeper
|
5月前
|
运维 负载均衡 网络协议
LVS+Keepalived 负载均衡
LVS+Keepalived 负载均衡
126 8
LVS+Keepalived 负载均衡
|
4月前
|
负载均衡 Kubernetes 区块链
随机密码生成器+阿里k8s负载均衡型服务加证书方法+移动终端设计+ico生成器等
随机密码生成器+阿里k8s负载均衡型服务加证书方法+移动终端设计+ico生成器等
90 1
|
5月前
|
域名解析 运维 负载均衡
LVS+Keepalived 负载均衡(二)28-1
【8月更文挑战第28天】LVS+Keepalived 负载均衡 配置 LVS VIP
95 5
|
6月前
|
存储 设计模式 缓存
OpenFeign集成Ribbon负载均衡-过滤和选择服务核心实现
该文章主要介绍了如何在OpenFeign中集成Ribbon以实现负载均衡,并详细分析了Ribbon中服务选择和服务过滤的核心实现过程。文章还涉及了Ribbon中负载均衡器(ILoadBalancer)和负载均衡策略(IRule)的初始化方式。
OpenFeign集成Ribbon负载均衡-过滤和选择服务核心实现
|
6月前
|
缓存 Ubuntu 前端开发
在Ubuntu上手动与自动启动Nginx的踩坑经历、以及重启服务
本文分享了作者在Ubuntu系统上手动和自动启动Nginx服务的踩坑经历,包括创建启动脚本、解决依赖问题、配置服务自动启动以及通过命令行管理Nginx服务的方法。
524 0
在Ubuntu上手动与自动启动Nginx的踩坑经历、以及重启服务