LVS+Keepalived构建高可用负载均衡(测试篇)

一、 启动LVS高可用集群服务

首先,启动每个real server节点的服务:
[root@localhost ~]# /etc/init.d/lvsrs start
start LVS of REALServer
然后,分别在主备Director Server启动Keepalived服务:
[root@DR1 ~]#/etc/init.d/Keepalived start
[root@DR1 ~]#/ ipvsadm -L
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP bogon:http rr
-> real-server1:http Route 1 1 0
-> real-server2:http Route 1 1 0
此时查看Keepalived服务的系统日志信息如下:
[root@localhost ~]# tail -f /var/log/messages
Feb 28 10:01:56 localhost Keepalived: Starting Keepalived v1.1.19 (02/27,2011)
Feb 28 10:01:56 localhost Keepalived_healthcheckers: Netlink reflector reports IP 192.168.12.25 added
Feb 28 10:01:56 localhost Keepalived_healthcheckers: Opening file '/etc/keepalived/keepalived.conf'.
Feb 28 10:01:56 localhost Keepalived_healthcheckers: Configuration is using : 12063 Bytes
Feb 28 10:01:56 localhost Keepalived: Starting Healthcheck child process, pid=4623
Feb 28 10:01:56 localhost Keepalived_vrrp: Netlink reflector reports IP 192.168.12.25 added
Feb 28 10:01:56 localhost Keepalived: Starting VRRP child process, pid=4624
Feb 28 10:01:56 localhost Keepalived_healthcheckers: Activating healtchecker for service [192.168.12.246:80]
Feb 28 10:01:56 localhost Keepalived_vrrp: Opening file '/etc/keepalived/keepalived.conf'.
Feb 28 10:01:56 localhost Keepalived_healthcheckers: Activating healtchecker for service [192.168.12.237:80]
Feb 28 10:01:57 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Feb 28 10:01:58 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Feb 28 10:01:58 localhost Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Feb 28 10:01:58 localhost Keepalived_healthcheckers: Netlink reflector reports IP 192.168.12.135 added
Feb 28 10:01:58 localhost avahi-daemon[2778]: Registering new address record for 192.168.12.135 on eth0.

二、 高可用性功能测试

高可用性是通过LVS的两个Director Server完成的,为了模拟故障,我们先将主Director Server上面的Keepalived服务停止,然后观察备用Director Server上Keepalived的运行日志,信息如下:
Feb 28 10:08:52 lvs-backup Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Feb 28 10:08:54 lvs-backup Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Feb 28 10:08:54 lvs-backup Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Feb 28 10:08:54 lvs-backup Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.12.135
Feb 28 10:08:54 lvs-backup Keepalived_vrrp: Netlink reflector reports IP 192.168.12.135 added
Feb 28 10:08:54 lvs-backup Keepalived_healthcheckers: Netlink reflector reports IP 192.168.12.135 added
Feb 28 10:08:54 lvs-backup avahi-daemon[3349]: Registering new address record for 192.168.12.135 on eth0.
Feb 28 10:08:59 lvs-backup Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.12.135
从日志中可以看出,主机出现故障后,备机立刻检测到,此时备机变为MASTER角色,并且接管了主机的虚拟IP资源,最后将虚拟IP绑定在eth0设备上。
接着,重新启动主Director Server上的Keepalived服务,继续观察备用Director Server的日志状态:
备用Director Server的日志状态:
Feb 28 10:12:11 lvs-backup Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert
Feb 28 10:12:11 lvs-backup Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
Feb 28 10:12:11 lvs-backup Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.
Feb 28 10:12:11 lvs-backup Keepalived_vrrp: Netlink reflector reports IP 192.168.12.135 removed
Feb 28 10:12:11 lvs-backup Keepalived_healthcheckers: Netlink reflector reports IP 192.168.12.135 removed
Feb 28 10:12:11 lvs-backup avahi-daemon[3349]: Withdrawing address record for 192.168.12.135 on eth0.
从日志可知,备机在检测到主机重新恢复正常后,重新返回BACKUP角色,并且释放了虚拟IP资源。

三、 负载均衡测试

这里假定两个real server节点配置www服务的网页文件根目录均为/webdata/www目录,然后分别执行如下操作:
在real server1 执行:
echo "This is real server1" /webdata/www/index.html
在real server2 执行:
echo "This is real server2" /webdata/www/index.html
接着打开浏览器,访问http://192.168.12.135这个地址,然后不断刷新此页面,如果能分别看到“This is real server1”和“This is real server2”就表明LVS已经在进行负载均衡了。

四、 故障切换测试

故障切换是测试当某个节点出现故障后,Keepalived监控模块是否能及时发现,然后屏蔽故障节点,同时将服务转移到正常节点来执行。
这里我们将real server 1节点服务停掉,假定这个节点出现故障,然后查看主、备机日志信息,相关日志如下:
Feb 28 10:14:12 localhost Keepalived_healthcheckers: TCP connection to [192.168.12.246:80] failed !!!
Feb 28 10:14:12 localhost Keepalived_healthcheckers: Removing service [192.168.12.246:80] from VS [192.168.12.135:80]
Feb 28 10:14:12 localhost Keepalived_healthcheckers: Remote SMTP server [192.168.12.1:25] connected.
Feb 28 10:14:12 localhost Keepalived_healthcheckers: SMTP alert successfully sent.
通过日志可以看出,Keepalived监控模块检测到192.168.12.246这台主机出现故障后,将此节点从集群系统中剔除掉了。
此时访问http://192.168.12.135这个地址,应该只能看到“This is real server2”了,这是因为节点1出现故障,而Keepalived监控模块将节点1从集群系统中剔除了。
下面重新启动real server 1节点的服务,可以看到Keepalived日志信息如下:
Feb 28 10:15:48 localhost Keepalived_healthcheckers: TCP connection to [192.168.12.246:80] success.
Feb 28 10:15:48 localhost Keepalived_healthcheckers: Adding service [192.168.12.246:80] to VS [192.168.12.135:80]
Feb 28 10:15:48 localhost Keepalived_healthcheckers: Remote SMTP server [192.168.12.1:25] connected.
Feb 28 10:15:48 localhost Keepalived_healthcheckers: SMTP alert successfully sent.
从日志可知,Keepalived监控模块检测到192.168.12.246这台主机恢复正常后,又将此节点加入了集群系统中。
此时再次访问http://192.168.12.135这个地址,然后不断刷新此页面,应该又能分别看到“This is real server1”和“This is real server2”页面了,这说明在real server 1节点恢复正常后,Keepalived监控模块将此节点加入了集群系统中。

本文出自 “技术成就梦想” 博客

(0)

相关推荐

  • haproxy+keepalived实现高可用负载均衡(理论篇)

    HAProxy相比LVS的使用要简单很多,功能方面也很丰富.当 前,HAProxy支持两种主要的代理模式:"tcp"也即4层(大多用于邮件服务器.内部协议通信服务器等),和7层(HTTP).在4层模式 下,HAProxy仅在客户端和服务器之间转发双向流量.7层模式下,HAProxy会分析协议,并且能通过允许.拒绝.交换.增加.修改或者删除请求 (request)或者回应(response)里指定内容来控制协议,这种操作要基于特定规则. 我现在用HAProxy主要在于它有以下优点,这里我

  • Keepalived+HAProxy实现MySQL高可用负载均衡的配置

     Keepalived 由于在生产环境使用了mysqlcluster,需要实现高可用负载均衡,这里提供了keepalived+haproxy来实现. keepalived主要功能是实现真实机器的故障隔离及负载均衡器间的失败切换.可在第3,4,5层交换.它通过VRRPv2(Virtual Router Redundancy Protocol) stack实现的. Layer3:Keepalived会定期向服务器群中的服务器.发送一个ICMP的数据包(既我们平时用的Ping程序),如果发现某台服务的

  • haproxy+keepalived实现高可用负载均衡(实例配置)

    作者:split_two 环境四台机器都是RedHat4.8(64位)版本: IP地址             用处192.168.5.55       MASTER192.168.2.73       BACKUP192.168.5.54       负载A192.168.5.57       负载B192.168.2.100      VIP 1.MASTER上安装haproxy 复制代码 代码如下: wget http://haproxy.1wt.eu/download/1.3/src/h

  • LVS+Keepalived构建高可用负载均衡配置方法(配置篇)

    一. LVS简介    LVS是Linux Virtual Server的简称,也就是Linux虚拟服务器, 是一个由章文嵩博士发起的自由软件项目,它的官方站点是www.linuxvirtualserver.org.现在LVS已经是 Linux标准内核的一部分,在Linux2.4内核以前,使用LVS时必须要重新编译内核以支持LVS功能模块,但是从Linux2.4内核以后,已经完全内置了LVS的各个功能模块,无需给内核打任何补丁,可以直接使用LVS提供的各种功能.使用LVS技术要达到的目标是:通过

  • keepalived实现nginx高可用

    keepalived直译就是保持存活,在网络里面就是保持在线了,也就是所谓的高可用或热备,用来防止单点故障(单点故障是指一旦某一点出现故障就会导致整个系统架构的不可用)的发生,keepalived实现的基础是vrrp,至于vrrp是什么请直接看这里vrrp,下面我们直接看应用吧. keepalived使用 为了方便使用,写了一个基于ubuntu 16.04 server 的一键配置脚本,配置使用相关就在脚本里见吧 #!/bin/bash # nginx+keepalived 高可用一键脚本for

  • LVS+Keepalived构建高可用负载均衡(测试篇)

    一. 启动LVS高可用集群服务 首先,启动每个real server节点的服务: [root@localhost ~]# /etc/init.d/lvsrs start start LVS of REALServer 然后,分别在主备Director Server启动Keepalived服务: [root@DR1 ~]#/etc/init.d/Keepalived start [root@DR1 ~]#/ ipvsadm -L IP Virtual Server version 1.2.1 (s

  • 详解.net core下如何简单构建高可用服务集群

    一说到集群服务相信对普通开发者来说肯定想到很复杂的事情,如zeekeeper ,反向代理服务网关等一系列的搭建和配置等等:总得来说需要有一定经验和规划的团队才能应用起来.在这文章里你能看到在.net core下的另一种集群构建方案,通过Beetlex即可非常便捷地构建高可用的集群服务. 简述 Beetlex的Webapi集群应用并没有依赖于第三方服务,而是由Beetlex自身完成:它主要是通过Client和策略监控服务相结合的方式来实现集群化的服务负载访问.以下是服务结构: client一旦从配

  • Keepalived+HAProxy高可用集群K8S实现

    目录 本文采用Keepalived+HAProxy的方式构建高可用集群.当你如果你有硬件负载均衡设备当然更好了. 准备环境: 主机 ip k8s-master01 192.168.10.4 k8s-master02 192.168.10.5 k8s-master03 192.168.10.6 VIP 192.168.10.150 架构图 注意:master集群采用奇数台数,3.5.7… 所有节点都进行hosts文件解析 tail -3 /etc/hosts 192.168.10.4 k8s-ma

  • 使用nginx+tomcat+keepalived实现高可用的详细步骤

    目录 架构设计 安装tomcat服务 192.168.166.128 192.168.166.129 安装nginx服务 安装keepalived 验证 架构设计 IP 服务应用 192.168.166.128 nginx/tomcat/keepalived 192.168.166.129 nginx/tomcat/keepalived 192.168.166.130 虚拟IP 我这是测试环境,防火墙全部关闭了. # 查看防火墙状态 systemctl status firewalld # 关闭

  • keepalived+nginx高可用实现方法示例

    1.keepalived介绍 keepalived最初是专为LVS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后来又加入了实现高可用的VRRP功能.keepalived除了能够管理LVS软件外,还能支持其他服务的高可用解决方案. keepalived通过VRRP协议实现高可用功能的.VRRP(Virtual Router Redundancy Protocol)虚拟路由冗余协议.VRRP出现的目的就是为了解决静态路由单点故障问题,它能保证当个别节点宕机时,整个网络可以不

  • Django高并发负载均衡实现原理详解

    1 什么是负载均衡? 当一台服务器的性能达到极限时,我们可以使用服务器集群来提高网站的整体性能.那么,在服务器集群中,需要有一台服务器充当调度者的角色,用户的所有请求都会首先由它接收,调度者再根据每台服务器的负载情况将请求分配给某一台后端服务器去处理. 那么在这个过程中,调度者如何合理分配任务,保证所有后端服务器都将性能充分发挥,从而保持服务器集群的整体性能最优,这就是负载均衡问题. 下面详细介绍负载均衡的四种实现方式 2 HTTP重定向实现负载均衡 过程描述 当用户向服务器发起请求时,请求首先

随机推荐