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

本文涉及的产品
传统型负载均衡 CLB,每月750个小时 15LCU
应用型负载均衡 ALB,每月750个小时 15LCU
网络型负载均衡 NLB,每月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月前
|
Ubuntu
百度搜索:蓝易云【Ubuntu开机自启服务systemd.service配置教程】
现在,你的服务将在Ubuntu开机时自动启动,并在之后的启动中持续运行。记得根据你的实际需求修改 `your_service_name.service`文件中的相关信息。
135 2
|
4月前
|
监控 Ubuntu 安全
Ubuntu开启FTP服务教程
在Ubuntu服务器上配置FTP服务是一个常见的需求,无论是用于文件分享、网站管理还是数据备份。FTP(文件传输协议)是一种用于在网络上传输文件的协议,它可以让用户通过身份验证下载或上传文件。本文将指导您如何在Ubuntu系统上安装和配置FTP服务器,以及如何管理用户权限来保证服务器的安全性。
349 0
Ubuntu20.04 Ntp服务安装及验证
Ubuntu20.04 Ntp服务安装及验证
|
4月前
|
Kubernetes Ubuntu 安全
Linux|科普扫盲帖|配置网络软件源---阿里云镜像仓库服务使用(centos,Ubuntu)
Linux|科普扫盲帖|配置网络软件源---阿里云镜像仓库服务使用(centos,Ubuntu)
2605 0
|
4月前
|
存储 Ubuntu 应用服务中间件
【Nginx】centos和Ubuntu操作系统下载Nginx配置文件并启动Nginx服务详解
【Nginx】centos和Ubuntu操作系统下载Nginx配置文件并启动Nginx服务详解
74 1
|
28天前
|
缓存 Ubuntu 前端开发
在Ubuntu上手动与自动启动Nginx的踩坑经历、以及重启服务
本文分享了作者在Ubuntu系统上手动和自动启动Nginx服务的踩坑经历,包括创建启动脚本、解决依赖问题、配置服务自动启动以及通过命令行管理Nginx服务的方法。
131 0
在Ubuntu上手动与自动启动Nginx的踩坑经历、以及重启服务
|
3月前
|
Ubuntu
ubuntu搭建NFS服务 磁盘共享 nfs 搭建
ubuntu搭建NFS服务 磁盘共享 nfs 搭建
128 2
|
3月前
|
Ubuntu
ubuntu 开启dhcp服务并配置
ubuntu 开启dhcp服务并配置
188 2
|
3月前
|
Linux Ubuntu
蓝易云 - Linux学习之Ubuntu20使用systemd管理OpenResty服务
这就是在Ubuntu 20使用systemd管理OpenResty服务的基本方法。
63 3
|
4月前
|
Ubuntu Python CDN
Ubuntu将自建服务配置开机启动项
在Ubuntu上设置Python Flask应用为开机启动服务,需要通过Systemd进行管理。首先,创建并编辑Systemd服务单元文件,指定`ExecStart`为Python解释器及Flask入口脚本,`WorkingDirectory`为应用目录,`User`和`Group`为运行用户,以及必要的环境变量。然后,使用`systemctl`命令进行daemon-reload,启用并启动服务。最后,检查服务状态以确保启动成功。重启机器测试,确认应用能自动启动。
130 5