LVS+keepalived DR模式配置高可用负载均衡集群

实验环境

LVS-Master 10.0.100.201
VIP:10.0.100.203

LVS-Slave       10.0.100.204
WEB1-Tomcat 10.0.2.29 gateway:10.0.2.253
WEB2-Tomcat 10.0.100.202

(注意:应保持所有服务器的时间一致)

Install LVS

# ln -s /usr/src/kernels/2.6.32-431.el6.i686/ /usr/src/linux
//若找不到这个目录则先安装kernel-devel
# yum -y install kernel-devel

# tar xf ipvsadm-1.24.tar.gz 

# cd /soft/ipvsadm-1.24

# make;make install

# ipvsadm -L
  IP Virtual Server version 1.2.1 (size=4096)
  Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

Install keepalived

# tar –xvf keepalived-1.2.12.tar.gz

# ./configure --sysconf=/etc/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.i686/
Keepalived version       : 1.2.12
Compiler                 : gcc
Compiler flags           : -g -O2
Extra Lib                : -lssl -lcrypto -lcrypt
Use IPVS Framework       : Yes   //表示使用ipvs框架也代表启动ipvs功能
IPVS sync daemon support : Yes   //表示启动ipvs的同步功能,--disabled-lvs-sysncd此参数可以关闭
IPVS use libnl           : No    //表示使用新的libn1版本,如果想使用新的版本,需要重新安装libn1的包
Use VRRP Framework       : Yes   //表示使用VRRP框架,这个实现keepalived高可用的必须功能
Use VRRP VMAC            : Yes   //表示使用基础VMAC接口的xmit VRRP包
SNMP support             : No
SHA1 support             : No
Use Debug flags          : No

# make;make install

# cp /soft/keepalived-1.2.12/bin/keepalived /usr/bin/

配置

1. LVS-Master的Keepalived配置

! Configuration File for keepalived
//全局定义
global_defs {
   notification_email     //定义邮件
   {
      [email protected]163.com    //定义邮件地址
   }
   notification_email_from [email protected]163.com
   smtp_server mail.163.com //定义邮件服务器
   smtp_connect_timeout 30  //邮件超时时间
   router_id LVS_DEVEL      //route_id标识
}

//定义VRR组
vrrp_instance VI_1 {
    state MASTER           //定义为MASTER
    interface eth0         //对外访问的网络接口
    virtual_router_id 100  //虚拟路由标识(注意要主从一致)
    priority 100           //优先级(主肯定比从高)
    nopreempt              //不抢占模式
    advert_int 1           //广播周期秒数
    authentication {
        auth_type PASS
        auth_pass 2209
    }
    virtual_ipaddress {
        10.0.100.203      //VIP地址
 }
}

//VIP地址与端口等设置-->注意DR模式的VIP端口和所有WEB端口应该保持一致
virtual_server 10.0.100.203 80 {
    delay_loop 6  //健康检查时间间隔,单位秒
    lb_algo rr    //调度算法为rr
    lb_kind DR    //模式为DR
    persistence_timeout 0 //设置同一IP多少秒内的请求都发送到同一个realserver
    protocol TCP   //使用TCP协议

//realserver的IP与端口等设置
    real_server 10.0.2.29 80{
        weight 1
        TCP_CHECK {
        connect_timeout 10   //连接超时时间,单位s
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80      //连接端口
} 

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

LVS-Master:keepalived.conf

2. LVS-Slave的keepalived配置

! Configuration File for keepalived
global_defs {
   notification_email
   {
      [email protected]163.com
   }
   notification_email_from [email protected]163.com
   smtp_server mail.163.com
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP      //这里的角色是BACKUP
    interface eth0
    virtual_router_id 100  //这里注意和MASTER保持一致
    priority 90           //优先级设置应比MASTER低
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2209
    }
    virtual_ipaddress {
        10.0.100.203
 }
}

virtual_server 10.0.100.203 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 0
    protocol TCP  

    real_server 10.0.2.29 80{
        weight 1
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
}
}
    real_server 10.0.100.202 80 {
        weight 1
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
}

LVS-Slave:keepalived.conf

3. 利用脚本配置所有的WEB服务器

#!/bin/bash
# Written by NetSeek
# description: Config realserver lo and apply noarp
WEB_VIP="10.0.100.203"        //这里是VIP地址

. /etc/rc.d/init.d/functions

case "$1" in
start)
       ifconfig lo:0 $WEB_VIP netmask 255.255.255.255 broadcast $WEB_VIP
       /sbin/route add -host $WEB_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 "RealServer Start OK"
       ;;
stop)
       ifconfig lo:0 down
       route del $WEB_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 "RealServer Stoped"
       ;;
status)
        # Status of LVS-DR real server.
        islothere=`/sbin/ifconfig lo:0 | grep $WEB_VIP`
        isrothere=`netstat -rn | grep "lo:0" | grep $web_VIP`
        if [ ! "$islothere" -o ! "isrothere" ]
        then
            echo "LVS-DR real server Stopped."
        else
            echo "LVS-DR Running."
        fi
        ;;
*)
        # Invalid entry.
        echo "$0: Usage: $0 {start|status|stop}"
        exit 1
        ;;
esac
exit 0

realserver.sh

启动与验证

1. 在所有WEB服务器运行脚本,并查看是否都有了VIP?

WEB1:10.0.2.29
# ./realserver.sh start
RealServer Start OK
# ip add show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet 10.0.100.203/32 brd 10.0.100.203 scope global lo:0
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever

WEB2:10.0.100.202 
# ./realserver.sh start
RealServer Start OK
# ip add show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet 10.0.100.203/32 brd 10.0.100.203 scope global lo:0
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever

2. 在MASTER和SLAVE都启动LVS,查看VIP位置

LVS-Master:10.0.100.201
# /etc/init.d/keepalived start
正在启动 keepalived:                                      [确定]
# ip add show
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:0c:29:0f:bf:4a brd ff:ff:ff:ff:ff:ff
    inet 10.0.100.201/16 brd 10.0.255.255 scope global eth0
    inet 10.0.100.203/32 scope global eth0
    inet6 fe80::20c:29ff:fe0f:bf4a/64 scope link
       valid_lft forever preferred_lft forever

LVS-Slave:10.0.100.204
# /etc/init.d/keepalived start
正在启动 keepalived:                                      [确定]
# ip add show
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:0c:29:2e:1d:0d brd ff:ff:ff:ff:ff:ff
    inet 10.0.100.204/16 brd 10.0.255.255 scope global eth0
    inet6 fe80::20c:29ff:fe2e:1d0d/64 scope link
       valid_lft forever preferred_lft forever

3. 访问测试(可通过浏览器访问VIP,我们测试是否在两个实验WEB服务器访问中实现了负载均衡)

LVS-Master:10.0.100.201
# ipvsadm -L
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.0.100.203:http rr
  -> 10.0.100.202:http            Route   1      0          0
  -> 10.0.2.29:http               Route   1      0          0  

LVS-Slave:10.0.100.204
# ipvsadm -L
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.0.100.203:http rr
  -> 10.0.100.202:http            Route   1      0          0
  -> 10.0.2.29:http               Route   1      0          0   
时间: 2024-10-05 04:58:29

LVS+keepalived DR模式配置高可用负载均衡集群的相关文章

apache+inotify-tools+keepalived+lvs-DR模式配置高可用负载均衡集群

环境:虚拟机VMware workstation 9 操作系统:Redhat 5.6 i386 一.keepalived+LVS-DR模式配置高可用负载均衡 拓扑如下: 二.服务器IP配置信息 四台服务器均有VMware虚拟机实现,两台HA主机.两台web服务器.网络方式都设置为NAT模式 1.master:192.168.80.145 2.slaver:192.168.80.137 3.web1:192.168.80.144 4.web2:192.168.80.134 5.VIP:192.16

Linux下Keepalived+LVS-DR模式配置高可用负载均衡集群

一.环境说明:     操作系统:Centos-6.5_x86_64    keepalived软件安装在node2和node3机器上.     实际安装之前,先关闭keepalived节点(node2,node3)上的防火墙. [[email protected] ~]# service iptables stop 二.软件安装:     这里需要安装的软件是keepalived.node2和node3都需要安装. [[email protected] ~]# yum install keep

ubuntu 14.04.3 LTS 版本 通过 nginx + keepalived 配置 高可用 负载均衡集群演示

系统版本:ubuntu 14.04.3 LTS 服务器准备: lb01-> ifconfig 显示结果: 192.168.91.136 作用:安装keepalived 及 nginx lb02-> ifconfig 显示结果: 192.168.91.135 作用:安装keepalived 及 nginx web01-> ifconfig 显示结果: 192.168.91.134 作用:安装nginx 负责展示 index.html页面 web02-> ifconfig 显示结果:

nginx+keepalived的高可用负载均衡集群构建

实验架构图: 实验环境 Nginx和Keepalived原理介绍 参考博客:http://467754239.blog.51cto.com/4878013/1541421 1.nginx Nginx进程基于于Master+Slave(worker)多进程模型,自身具有非常稳定的子进程管理功能.在Master进程分配模式下,Master进程永远不进行业务处理,只是进行任务分发, 从而达到Master进程的存活高可靠性,Slave(worker)进程所有的业务信号都 由主进程发出,Slave(wor

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

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高可用负载均衡集群架构

实验环境: LVS和keepalived介绍: 1.keepalived的设计目标是构建高可用的LVS负载均衡群集,可以调用ipvsadm工具来创建虚拟服务器,管理服务器池,而不仅仅用来做双机热备. 使用keepalived构建LVS群集更加简便易用,主要优势体现在: 对LVS负载调度器实现热备切换,提高可用性: 对服务器池中的节点进行健康检查,自动移除失效节点,恢复后再重新加入. 2.在基于LVS+Keepalived实现的LVS群集结构中,至少包括两台热备的负载调度器,两台以上的节点服务器,

LVS基础及LVS+Keepalived实现双主高可用负载均衡

LVS基础及LVS+Keepalived实现双主高可用负载均衡 LB集群: (Load  Balancing)即负载均衡集群,其目的是为了提高访问的并发量及提升服务器的性能,其    实现方式分为硬件方式和软件方式. 硬件实现方式: 常用的有 F5公司的BIG-IP系列.A10公司的AX系列.Citrix公司的 NetScaler系列等 软件实现方式: LVS工作于传输层.nginx工作于应用层.haproxy工作于传输层和应用层 本文主要讲解LVS. 一.什么是LVS ? 1. LVS:(Li

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