keepalived+LVS搭建高可用负载均衡系统

相关架构设置:

1)vip : 192.168.137.6

2)DS master ip : 192.168.137.8

3)DS backup ip : 192.168.137.9

4)RS 1 ip: 192.168.137.100

5)RS 2 ip: 192.168.137.200

两台RS上的配置脚本:lvsrs

[[email protected] init.d]# cat /etc/init.d/lvsrs
#!/bin/sh
vip=192.168.137.6
. /etc/rc.d/init.d/functions

case "$1" in
start)
ifconfig lo:0 $vip netmask 255.255.255.255 broadcast $vip
route add -host $vip dev lo:0
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p > /dev/null 2>&1
echo "Real server start ok"
;;

stop)
ifconfig lo:0 down
route del $vip >/dev/null 2>&1
echo "0" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce
echo "Real server stoped"
;;

*)
echo "Usage: $0 {start|stop}"
exit 1
esac

DS master上的keepalived的配置文件:

[[email protected] ~]# cat /etc/keepalived/keepalived.conf
global_defs {
   #notification_email {
   #   [email protected]
   #   [email protected]
   #   [email protected]
   #}
   #notification_email_from [email protected]
   #smtp_server 192.168.137.1
   #smtp_connect_timeout 30
   router_id LVS_DS_IP
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.137.6
    }
}

virtual_server 192.168.137.6 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    persistence_timeout 0
    protocol TCP

    real_server 192.168.137.100 80 {
        weight 3
        TCP_CHECK {
                connect_timeout 10
                nb_get_retry 3
                delay_before_retry 3
                connect_port 80
        }
   }

   real_server 192.168.137.200 80 {
        weight 3
        TCP_CHECK {
                connect_timeout 10
                nb_get_retry 3
                delay_before_retry 3
                connect_port 80
        }
   }
}

DS backup上的keepalived的配置文件:

[[email protected] ~]# cat /etc/keepalived/keepalived.conf
global_defs {
   #notification_email {
   #  [email protected]
   #  [email protected]
   #  [email protected]
   #}
   #notification_email_from [email protected]
   #smtp_server 192.168.137.1
   #smtp_connect_timeout 30
   router_id LVS_DS_IP
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.137.6
    }
}

virtual_server 192.168.137.6 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    persistence_timeout 0
    protocol TCP

    real_server 192.168.137.100 80 {
        weight 3
        TCP_CHECK {
                connect_timeout 10
                nb_get_retry 3
                delay_before_retry 3
                connect_port 80
        }
   }

   real_server 192.168.137.200 80 {
        weight 3
        TCP_CHECK {
                connect_timeout 10
                nb_get_retry 3
                delay_before_retry 3
                connect_port 80
        }
   }
}

启动命令:

service keepalived start | stop

service lvsrs start | stop

查看DS上的keepalived是否配置成功:

tail -f /var/log/message

[[email protected] ~]# tail -f /var/log/messages
Feb  2 16:22:04 localhost Keepalived_healthcheckers[2498]: Activating healthchecker for service [192.168.137.100]:80
Feb  2 16:22:04 localhost Keepalived_healthcheckers[2498]: Activating healthchecker for service [192.168.137.200]:80
Feb  2 16:22:04 localhost Keepalived_vrrp[2499]: VRRP_Instance(VI_1) Transition to MASTER STATE
Feb  2 16:22:04 localhost Keepalived_vrrp[2499]: VRRP_Instance(VI_1) Received lower prio advert, forcing new election
Feb  2 16:22:05 localhost Keepalived_healthcheckers[2498]: TCP connection to [192.168.137.200]:80 failed !!!
Feb  2 16:22:05 localhost Keepalived_healthcheckers[2498]: Removing service [192.168.137.200]:80 from VS [192.168.137.6]:80
Feb  2 16:22:05 localhost Keepalived_vrrp[2499]: VRRP_Instance(VI_1) Entering MASTER STATE
Feb  2 16:22:05 localhost Keepalived_vrrp[2499]: VRRP_Instance(VI_1) setting protocol VIPs.
Feb  2 16:22:05 localhost Keepalived_vrrp[2499]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.137.6
Feb  2 16:22:05 localhost Keepalived_healthcheckers[2498]: Netlink reflector reports IP 192.168.137.6 added
Feb  2 16:22:10 localhost Keepalived_vrrp[2499]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.137.6

查看分发配置:

[[email protected] ~]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.137.6:http wrr
  -> 192.168.137.100:http         Route   3      0          0
  -> 192.168.137.200:http         Route   3      3          0
[[email protected] ~]#
时间: 2024-11-04 20:49:51

keepalived+LVS搭建高可用负载均衡系统的相关文章

DNS+keepalived+lvs实现高可用负载均衡集群

1.目的: 部署两台lvs调度器并利用keepalived实现主主模型,DNS添加两条A记录指向lvs调度器实现轮询,最终实现高可用负载均衡集群效果 2.拓扑规划: 3.配置实践 (1)同步所有机器时间 在每台机器实行ntp同步: [[email protected] ~]# ntpdate 10.1.0.1 26 Oct 20:10:57 ntpdate[5533]: step time server 10.1.0.1 offset -32408.643564 sec (2)先配置RS,在RS

Keepalived+LVS(dr)高可用负载均衡集群的实现

一 环境介绍 1.操作系统CentOS Linux release 7.2.1511 (Core) 2.服务keepalived+lvs双主高可用负载均衡集群及LAMP应用keepalived-1.2.13-7.el7.x86_64ipvsadm-1.27-7.el7.x86_64httpd-2.4.6-45.el7.centos.x86_64mariadb-5.5.52-1.el7.x86_64php-5.4.16-42.el7.x86_64 二 原理及拓扑图 1.vrrp协议vrrp(Vir

【Linux运维-集群技术进阶】Nginx+Keepalived+Tomcat搭建高可用/负载均衡/动静分离的Webserver集群

额.博客名字有点长.. . 前言 最终到这篇文章了,心情是有点激动的. 由于这篇文章会集中曾经博客讲到的全部Nginx功能点.包含主要的负载均衡,还有动静分离技术再加上这篇文章的重点.通过Keepalived实现的HA(High Available).为什么要实现高可用呢?曾经在搭建的时候仅仅用了一台Nginxserver,这种话假设Nginxserver宕机了,那么整个站点就会挂掉.所以要实现Nginx的高可用,一台挂掉还会有还有一台顶上去.从而保证站点能够持续的提供服务. 关于负载均衡和动静

Keepalived+LVS实现高可用负载均衡双主模式

LVS是一种集群(Cluster)技术:采用IP负载均衡技术和基于内容请求分发技术.调度器具有很好的吞吐率,将请求均衡地转移到不同的服务器上执行,且调度器自动屏蔽掉服务器的故障,从而将一组服务器构成一个高性能的.高可用的虚拟服务器.整个服务器集群的结构对客户是透明的,而且无需修改客户端和服务器端的程序.工作在四层,在内核空间工作,基于ipvs模块,不占用流量. 双机高可用方法目前分为两种: 1)双机主从模式:即前端使用两台服务器,一台主服务器和一台热备服务器,正常情况下,主服务器绑定一个公网虚拟

Keepalived+Haproxy搭建高可用负载均衡

global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server smtp.163.com stmp_connect_timeout 30 router_id lnmp_node2 } # 检测haproxy脚本 vrrp_script chk_haproxy { script "/etc/keepalived/check_haproxy.sh&

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

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

Nginx+Keepalived(双机热备)搭建高可用负载均衡环境(HA)

原文:https://my.oschina.net/xshuai/blog/917097 摘要: Nginx+Keepalived搭建高可用负载均衡环境(HA) http://blog.csdn.net/xyang81/article/details/52554398可以看更多介绍 Keepalived的介绍可以百度一堆一堆的资料.一定要看看哦. 1.基于上一篇博客总结,再次安装一个虚拟机当backup服务器,这个服务器只安装Keepalived+Nginx即可 2.Master还是上一篇博文的

RHEL 5.4下部署LVS(DR)+keepalived实现高性能高可用负载均衡

原文地址:http://www.cnblogs.com/mchina/archive/2012/05/23/2514728.html 一.简介 LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一. 目前有三种IP负载均衡技术(VS/NAT.VS/TUN和VS/DR):十种调度算法(rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq). K

CentOS 6.3下部署LVS(NAT)+keepalived实现高性能高可用负载均衡

一.系统环境 实验拓扑: 实验环境: Vmware 9.01 + Windows 8 x64 企业版+8G内存 虚拟机步骤: 1.安装一台CentOS 6.3 x64主机,内存为1GB,网络为NAT模式,注意检查Vmware中EDIT菜单下Virtual Network Editor中VMnet8 2. 加电,安装系统.基础知识了,不再多说,注意:选择英文而不要选择中文,选择是Basic Server模式,系统名称:LVS-MASTER 3.安装系统后,用root用户登录进去,执行 ifconf