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.168.80.200

三、安装配置keepalived

1、主辅服务器部署keepalived

yum install gcc gcc-c++ autoconf automake wget openssl-devel kernel-devel  -y
tar -zxf keepalived-1.1.20.tar.gz -C /usr/src
cd /usr/src/keepalived-1.1.20
./configure --prefix=/usr/local/keepalived --sysconf=/etc --with-kernel-dir=/usr/src/kernels/2.6.18-238.el5
make && make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin
cp /usr/local/keepalived/bin/genhash /usr/sbin/
/etc/init.d/keepalived start
chkconfig keepalived on

注:主要难点解决依赖关系

2、分别设置web服务器1和2

yum install httpd -y
echo "web1/web2 ok!!!">/var/www/html/index.html
echo "check web1 ok!!! /check web2 ok !!!">/var/www/html/check_web1.html
/etc/init.d/httpd start

3、主辅服务器部署ipvsadm

tar -zxf ipvsadm-1.24.tar.gz -C /usr/src
cd /usr/src/ipvsadm-1.24
make && make install

注:安装前检查内核是否支持ipvsadm

 cat /boot/config-2.6.18-238.el5 |grep -i ipvs
# IPVS transport protocol load balancing support
# IPVS scheduler
# IPVS application helper

modprobe -l |grep ipvs
/lib/modules/2.6.18-238.el5/kernel/net/ipv4/ipvs/ip_vs.ko
/lib/modules/2.6.18-238.el5/kernel/net/ipv4/ipvs/ip_vs_dh.ko
/lib/modules/2.6.18-238.el5/kernel/net/ipv4/ipvs/ip_vs_ftp.ko
/lib/modules/2.6.18-238.el5/kernel/net/ipv4/ipvs/ip_vs_lblc.ko
/lib/modules/2.6.18-238.el5/kernel/net/ipv4/ipvs/ip_vs_lblcr.ko
/lib/modules/2.6.18-238.el5/kernel/net/ipv4/ipvs/ip_vs_lc.ko
/lib/modules/2.6.18-238.el5/kernel/net/ipv4/ipvs/ip_vs_nq.ko
/lib/modules/2.6.18-238.el5/kernel/net/ipv4/ipvs/ip_vs_rr.ko
/lib/modules/2.6.18-238.el5/kernel/net/ipv4/ipvs/ip_vs_sed.ko
/lib/modules/2.6.18-238.el5/kernel/net/ipv4/ipvs/ip_vs_sh.ko
/lib/modules/2.6.18-238.el5/kernel/net/ipv4/ipvs/ip_vs_wlc.ko
/lib/modules/2.6.18-238.el5/kernel/net/ipv4/ipvs/ip_vs_wrr.ko

4、配置主辅keepalived配置文件

/etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id httpd
}

vrrp_script check_http {
        script "/root/bash/check_httpd.sh"
        weight -5
        interval 1
    }

vrrp_instance VI_1 {
    state MASTER/BACKUP
    interface eth0
    virtual_router_id 240
    priority 100/98
    advert_int 1
#    track_script {
#        check_http
#    }
    authentication {
        auth_type PASS
        auth_pass 3333
    }
    virtual_ipaddress {
       192.168.80.200/24 dev eth0
    }
}
virtual_server 192.168.80.200 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 0
    protocol TCP

    real_server 192.168.80.134 80 {
        weight 1
        HTTP_GET {
            url {
              path /check_web1.html
              digest 68f36ac34591233a3ca3b5def1bace34
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.80.144 80 {
        weight 1
        HTTP_GET {
            url {
              path /check_web1.html
              digest 68f36ac34591233a3ca3b5def1bace34
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

注:(1)、主辅设置优先级

(2)、genhash值的计算、web1、web2的httpd服务开启时才能

(3)、使用的是HTTP_GET检查web服务器的健康状态

(4)、lvs模式设定

(5)、persistence_timeout 设置为0 方便后面测试

5、检查部署情况

master检查ipvsadm 情况

ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.80.200:80 rr
  -> 192.168.80.144:80            Route   1      0          0         
  -> 192.168.80.134:80            Route   1      0          0

6、主服务器重启keepalived服务

tail -f /var/log/messages

May 17 00:37:48 master Keepalived: Terminating on signal
May 17 00:37:48 master Keepalived: Stopping Keepalived v1.1.20 (05/16,2014) 
May 17 00:37:48 master Keepalived_vrrp: Terminating VRRP child process on signal
May 17 00:37:49 master Keepalived_healthcheckers: Terminating Healthchecker child process on signal
May 17 00:37:49 master Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.
May 17 00:37:49 master avahi-daemon[3543]: Withdrawing address record for 192.168.80.200 on eth0.
May 17 00:37:49 master Keepalived: Starting Keepalived v1.1.20 (05/16,2014) 
May 17 00:37:49 master Keepalived_healthcheckers: Netlink reflector reports IP 192.168.80.145 added
May 17 00:37:49 master Keepalived_healthcheckers: Registering Kernel netlink reflector
May 17 00:37:49 master Keepalived_healthcheckers: Registering Kernel netlink command channel
May 17 00:37:49 master Keepalived: Starting Healthcheck child process, pid=12821
May 17 00:37:49 master Keepalived: Starting VRRP child process, pid=12822
May 17 00:37:49 master Keepalived_vrrp: Netlink reflector reports IP 192.168.80.145 added
May 17 00:37:49 master Keepalived_vrrp: Registering Kernel netlink reflector
May 17 00:37:49 master Keepalived_vrrp: Registering Kernel netlink command channel
May 17 00:37:49 master Keepalived_vrrp: Registering gratutious ARP shared channel
May 17 00:37:49 master Keepalived_vrrp: Opening file ‘/etc/keepalived/keepalived.conf‘. 
May 17 00:37:49 master Keepalived_vrrp: Configuration is using : 37747 Bytes
May 17 00:37:49 master Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
May 17 00:37:49 master Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(10,11)]
May 17 00:37:49 master Keepalived_healthcheckers: Opening file ‘/etc/keepalived/keepalived.conf‘. 
May 17 00:37:49 master Keepalived_healthcheckers: Configuration is using : 14817 Bytes
May 17 00:37:49 master Keepalived_healthcheckers: Using LinkWatch kernel netlink reflector...
May 17 00:37:49 master Keepalived_healthcheckers: Activating healtchecker for service [192.168.80.134:80]
May 17 00:37:49 master Keepalived_healthcheckers: Activating healtchecker for service [192.168.80.144:80]
May 17 00:37:50 master Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
May 17 00:37:51 master Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
May 17 00:37:51 master Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
May 17 00:37:51 master Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.80.200
May 17 00:37:51 master Keepalived_vrrp: Netlink reflector reports IP 192.168.80.200 added
May 17 00:37:51 master Keepalived_healthcheckers: Netlink reflector reports IP 192.168.80.200 added
May 17 00:37:51 master avahi-daemon[3543]: Registering new address record for 192.168.80.200 on eth0.
May 17 00:37:56 master Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.80.200
May 17 00:38:05 master Keepalived: Terminating on signal
May 17 00:38:05 master Keepalived: Stopping Keepalived v1.1.20 (05/16,2014) 
May 17 00:38:05 master Keepalived_vrrp: Terminating VRRP child process on signal
May 17 00:38:05 master Keepalived_healthcheckers: Terminating Healthchecker child process on signal
May 17 00:38:05 master Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.
May 17 00:38:05 master avahi-daemon[3543]: Withdrawing address record for 192.168.80.200 on eth0.
May 17 00:38:52 master Keepalived: Starting Keepalived v1.1.20 (05/16,2014) 
May 17 00:38:52 master Keepalived_healthcheckers: Netlink reflector reports IP 192.168.80.145 added
May 17 00:38:52 master Keepalived_healthcheckers: Registering Kernel netlink reflector
May 17 00:38:52 master Keepalived_healthcheckers: Registering Kernel netlink command channel
May 17 00:38:52 master Keepalived: Starting Healthcheck child process, pid=12838
May 17 00:38:52 master Keepalived: Starting VRRP child process, pid=12839
May 17 00:38:52 master Keepalived_vrrp: Netlink reflector reports IP 192.168.80.145 added
May 17 00:38:52 master Keepalived_vrrp: Registering Kernel netlink reflector
May 17 00:38:52 master Keepalived_vrrp: Registering Kernel netlink command channel
May 17 00:38:52 master Keepalived_vrrp: Registering gratutious ARP shared channel
May 17 00:38:52 master Keepalived_healthcheckers: Opening file ‘/etc/keepalived/keepalived.conf‘. 
May 17 00:38:52 master Keepalived_healthcheckers: Configuration is using : 14817 Bytes
May 17 00:38:52 master Keepalived_healthcheckers: Using LinkWatch kernel netlink reflector...
May 17 00:38:52 master Keepalived_healthcheckers: Activating healtchecker for service [192.168.80.134:80]
May 17 00:38:52 master Keepalived_vrrp: Opening file ‘/etc/keepalived/keepalived.conf‘. 
May 17 00:38:52 master Keepalived_healthcheckers: Activating healtchecker for service [192.168.80.144:80]
May 17 00:38:52 master Keepalived_vrrp: Configuration is using : 37747 Bytes
May 17 00:38:52 master Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
May 17 00:38:52 master Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(10,11)]
May 17 00:38:53 master Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE

7、在web服务器上分别执行以下脚本

#!/bin/bash
#description:start realserver
#chkconfig
VIP1=192.168.80.200
case "$1" in
start)
echo " start LVS of REALServer"
/sbin/ifconfig lo:0 $VIP1 broadcast $VIP1 netmask 255.255.255.255 up
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
;;
stop)
/sbin/ifconfig lo:0 down
echo "close LVS Directorserver"
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 "Usage: $0 {start|stop}"
exit 1
esac

8、现在重启主辅服务器上的keepalived服务、web服务器上的httpd服务,关闭master的keepalived服务做测试。

keepalived+LVS-DR模式就部署就完成了

9、在web1上部署inotify-tools工具、web2上部署rsync服务,用于当web1网页内容变化时,web2服务器的网页内容的一致性问题

web1上部署inotify-tools

tar -zxf inotify-tools-3.13.tar.gz -C /usr/src
cd /usr/src/inotify-tools-3.13
./configure --prefix=/usr/local/inotify_tools
make && make install 
cp /usr/local/inotify_tools/bin/inotifywait /usr/sbin/
cp /usr/local/inotify_tools/bin/inotifywatch /usr/sbin/

chmod 755 inotify-rsync.sh
inotify-rsync.sh
#!/bin/bash
host1=192.168.80.137
src=/var/www/html
dst1=test
user1=root
/usr/local/inotify_tools/bin/inotifywait -mrq --timefmt ‘%d/%m/%y %H:%M‘ --format ‘%T %w%f%e‘ -e modify,delete,create,attrib  $src | while read files
        do
        /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsync.passwd [email protected]$host1::$dst1
                echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
         done
         
         
inotify-rsync.sh  &

web2上部署rsync服务

chmod 600 /etc/rsync.passwd

/etc/rsync.passwd
root:strong

/etc/rsyncd.conf
strict modes = yes
port = 873
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd
use chroot =
timeout =

[test]
path = /var/www/
comment = rsync files
max connections = 5
uid = root
gid = root
ignore errors
read only = no
write only = no
list = no
hosts allow = *
hosts deny = 10.1.1.1
auth users = root
secrets file = /etc/rsync.passwd

启动rsync服务
chkconfig rsync on
/etc/init.d/xinted restart

10、至此apache+rsync+inotify-tools+keepalived+lvs-DR模式HA负载均衡部署就此结束

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

时间: 2024-09-28 15:52:36

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

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 //若找不到这个目录则先安装ker

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 显示结果:

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群集结构中,至少包括两台热备的负载调度器,两台以上的节点服务器,

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实现调度、高可用、高性能集群

6.keepalived+lvs实现调度.高可用.高性能集群 Keepalived的作用是: 检 测web服务器的状态,如果有一台web服务器死机,或工作出现故障,Keepalived将检测到,并将有故障的web服务器从系统中剔除,当web服 务器工作正常后Keepalived自动将web服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉,需要人工做的只是修复故障的web服务 器       (1)安装keepalived     # ./configure --prefix=/usr

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

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