L8.1 lvs+heartbeat-ldirectord实现高可用负载均衡

lvs+heartbeat-ldirectord实现高可用负载均衡

IPVS规则与heartbeat

ipvs规则不再使用ipvsadm配置,而是依靠heartbeat的包工具ldirectord去生成规则

并且ldirectord有检测后端RS健康状况的机制(利用权重,非常正常剔除(w=0),正常后添加)。

删除之前 heartbeat v2 crm lamp配置的约束和资源

节点分别停止heartbeat:/etc/init.d/heartbeat stop

规划

ipvs-ld节点: 192.168.0.190  node1

ipvs-ld点: 192.168.0.201 node2

RS:192.168.0.202 node4 ,192.168.0.193 node3

lvs vip 192.168.0.199

ldirectord依赖于自己的配置文件生成ipvs规则,因此,定义集群服务,添加RS都在配置文件中指定,而无需手动执行ipvsadm命令;

ldirectord能对各RS的健康状态做检测,并能实现按需添加或者删除各RS。

1,两个节点安装 heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm 

[[email protected] heartbeat2]# rpm -ivh heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm 
error: Failed dependencies:
ipvsadm is needed by heartbeat-ldirectord-2.1.4-12.el6.x86_64
perl(LWP::Debug) is needed by heartbeat-ldirectord-2.1.4-12.el6.x86_64
perl(LWP::UserAgent) is needed by heartbeat-ldirectord-2.1.4-12.el6.x86_64
perl(Mail::Send) is needed by heartbeat-ldirectord-2.1.4-12.el6.x86_64

[[email protected] heartbeat2]#yum install heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm -y

依赖包如下:

2,LVS,DR模式配置

配置RS

node3 ,node4主机分别同样配置主机:

echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore

echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore

echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce

ifconfig eth0:0 192.168.0.199 broadcast 192.168.0.199 netmask 255.255.255.255

sysctl -p

route add -host 192.168.0.199 dev eth0:0

/etc/init.d/httpd start

curl 192.168.0.194

配置DR主机ipvs

ifconfig eth0:0 192.168.0.199 broadcast 192.168.0.199 netmask 255.255.255.255

route add -host 192.168.0.199 dev eth0:0

[[email protected] ~]# ipvsadm -A -t 192.168.0.199:80 -s rr
[[email protected] ~]# ipvsadm -a -t 192.168.0.199:80 -r 192.168.0.202 -g -w 1
[[email protected] ~]# ipvsadm -a -t 192.168.0.199:80 -r 192.168.0.194 -g -w 1

访问测试成功:

3,测试出成功后,删除ipvs规则;

[[email protected] ~]# ipvsadm -C
[[email protected] ~]# ipvsadm -L
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
[[email protected] ~]# route del -host 192.168.0.199

[[email protected] ~]# ifconfig eth0:0 down

4,使用ldirectord文件配置规则

cd /usr/share/doc/heartbeat-ldirectord-2.1.4/

cp ldirectord.cf /etc/ha.d/

配置文件说明:

# Global Directives
checktimeout=3  #超时时间间隔
checkinterval=1 #向后端检查的时间,即每1秒检查一次,3秒超时。
#fallback=127.0.0.1:80 #sorry page
autoreload=yes  #自己不用做reload,文件改变后自动装载。
logfile="/var/log/ldirectord.log"       #自己的日志
#logfile="local0"
#emailalert="[email protected]"
#emailalertfreq=3600
#emailalertstatus=all
quiescent=yes

...

以ftp为列说明:

#virtual=192.168.6.240:21    #vip
#       real=192.168.16.3:21 masq    #rs
#       real=192.168.16.5:21 masq    #rs
#       fallback=127.0.0.1:21            #sorry page
#       service=ftp                            #表示用ftp协议检查
#       checkport=21                        #表示检查21号端口,在tcp层
#       scheduler=wlc                        #调度算法
#       scheduler=rr                            #调度算法
#       #persistent=600                #持久连接时间为600秒。注视表示没开启持久连接
#       #netmask=255.255.255.255
#       protocol=tcp                            #集群服务协议类型
#       checktype=negotiate                #协商类型检查,表示下面的登录和密码
#       login="anonymous"                #用anonymous登录
#       passwd="[email protected]"    #密码
#       request="welcome.msg"            #请求获取到welcome.msg文件
#       receive="test"                            #回答test字符串

以http说明:

virtual=192.168.6.240:80
        real=192.168.6.2:80 gate
        real=192.168.6.3:80 gate
        real=192.168.6.6:80 gate
        fallback=127.0.0.1:80 gate
        service=http
        request="index.html"   #请求哪个页面
        receive="Test Page"        #必须返回哪个字符串,RS才算是正常的
        virtualhost=some.domain.com.au    #对虚拟主机单独检测
        scheduler=rr
        #persistent=600
        #netmask=255.255.255.255
        protocol=tcp
        checktype=negotiate
        checkport=80
        request="index.html"
        receive="Test Page"
        virtualhost=www.x.y.z

常用的检测类型:

checktype = connect|external|negotiate|off|on|ping|checktimeoutN

ip层:connect: syn ,ack就行了

网络层:ping

应用层:negotiate

配置文件修改:

# Sample for an http virtual service

virtual=192.168.0.199:80

real=192.168.0.194:80 gate

real=192.168.0.202:80 gate

fallback=127.0.0.1:80 gate

protocol=tcp

checkport=80

checktype=negotiate

service=http

request=".health.html"

receive="OK"

scheduler=rr

#persistent=600

#netmask=255.255.255.255

将配置文件复制到node2节点

[[email protected] ha.d]# scp ldirectord.cf node2:/etc/ha.d/

两台DR添加sorry page:

vim /var/www/html/index.html

node1 sorry server

两台RS 添加.health.html

vim /var/www/html/.health.html

测试网页都能访问。

5,配置hb_gui

定义组ipvs

定义集群ip clusterip

定义 ipvs规则 ipsrules  (使用ldirectord定义)

启动组

6,测试

注意:两个HA-DR应该开机自动启动httpd,sorry page页面展示

sorry server页面,两台RS,httpd都stop,HA-LVS权重Weight 为1

通过设置权重为0来剔除RS。

时间: 2024-12-26 14:32:17

L8.1 lvs+heartbeat-ldirectord实现高可用负载均衡的相关文章

LVS-DR模式的配置及Heartbeat+Ldirectord+DR高可用负载均衡集群的搭建

主机环境 redhat6.5 64位 实验环境 服务端1 ip172.25.25.113   主机名:server3.example.com         服务端2 ip 172.25.25.114   主机名:server4.example.com          调度端2 ip 172.25.25.112   主机名:server2.example.com         调度端1 ip 172.25.25.111   主机名:server1.example.com 防火墙状态:关闭 虚

LVS+Keepalived搭建MyCAT高可用负载均衡集群

LVS+Keepalived 介绍 LVS LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一.目前有三种IP负载均衡技术(VS/NAT.VS/TUN和VS/DR),十种调度算法(rrr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq). Keepalvied Keepalived在这里主要用作RealServer的健康状态检查以及Mast

LVS+KeepAlived,RabbitMQ高可用负载均衡

最近团队准备对项目进行重构,其中用到了RabbitMQ,也考虑了几个方案,下边着重介绍在项目中即将采用的方案.关于RabbitMQ就不在这里详细说明,具体查看 RabbitMQ中文手册.直接看架构图: 如图所示: 前端采用keepalived+lvs实现高可用负载均衡, RabbitMQ HA 队列(镜像队列)进行消息队列结构复制.本方案中搭建两个节点,并且都是磁盘节点(所有节点状态保持一致,节点完全对等),只要有任何一个节点能够工作,RabbitMQ 集群对外就能提供服务.任务处理进程同时监控

LVS+keepalived 实现web高可用负载均衡集群

1.实验环境 4台CentOS-7.5虚拟机web-1:192.168.18.103web-2:192.168.18.104keepalived-1(LVS-DR模式):192.168.18.107 keepalived-2(LVS-DR模式):192.168.18.108 vip:192.168.18.110其中keepalived和lvs安装在同一台机器,web单独一台安装客户端为:个人win10笔记本(192.168.18.102)4台虚机防火墙和selinux均已关闭 2.安装keepa

DNS部署(四)之lvs+keepalived+bind架构高可用负载均衡DNS系统

1.网络拓扑 2.环境描述 系统描述 IP地址 作用 LB-master 192.168.1.105 主备负载均衡器(同时做web和DNS调度) LB-backup 192.168.1.106 DNS-master 192.168.1.107 VIP:192.168.1.30(LVS DNS节点互为主辅同步) DNS-backup 192.168.1.108 Web节点组 192.168.1.201-203 VIP:192.168.1.40(LVS web节点) 3.配置LVS调度器keepal

LVS+Keepalived+Nginx+Tomcat高可用负载均衡集群配置(DR模式,一个VIP,多个端口)

一.概述 LVS作用:实现负载均衡 Keepalived作用:监控集群系统中各个服务节点的状态,HA cluster. 配置LVS有两种方式: 1. 通过ipvsadm命令行方式配置 2. 通过Redhat提供的工具piranha来配置LVS 软件下载: ipvsadm下载地址: http://www.linuxvirtualserver.org/software/kernel-2.6/ Keepalived下载地址: http://www.keepalived.org/software/ 安装

CentOS7下LVS+Keepalived实现高性能高可用负载均衡

一.规划  对外VIP:10.10.10.10    对内VIP:192.168.10.10 LVS_MASTER:10.10.10.28(eth0)            192.168.10.128(eth1) LVS_BACKUP:10.10.10.29(eth0)            192.168.10.129(eth1)       WEB1:192.168.10.130       WEB2:192.168.10.131 二.释义 LVS是Linux Virtual Server

Heartbeat+LVS+Ldirectord高可用&负载均衡

集群技术主要分为三大类: 高可用性(High Available Cluster),例:Linux-HA 负载均衡(Load balancing Cluster),例:LVS.MOSIX 高性能计算(High Performance Computing),例:Beowulf 我们这里使用 RHEL5.2,LVS,Linux-HA,Ldirectord,构造一个高可用的负载均 衡集群系统.如图: Load Balancer 是整个集群系统的前端,负责把客户请求转发到 Real Server 上.

LVS+Heartbeat高可用负载均衡

一,环境配置 VIP:192.168.222.222 RIP:192.168.222.134 RIP:192.168.222.135 DR_MASTER:eth0 192.168.222.128 eth1 172.16.0.1 (单网卡也行) DR_SLAVE:eth0 192.168.222.129 eth1 172.16.0.2 (单网卡也行) 二,DR配置 1,安装软件 yum install epel-release -y yum install ipvsadm -y yum insta