nginx和keeplive实现负载均衡高可用

一、 Keeplive服务介绍

Keeplive期初是专门为LVS设计的,专门用来监控LVS集群系统中各个服务节点的状态,后来又加入VRRP的功能,因此除了配合LVS服务以外,也可以作为其他服务(nginx,haroxy)的高可用软件,VRRP是Virtual Router Redundancy Protocol(虚拟路由冗余协议)的缩写,VRRP出现的目的就是为了解决静态路由出现的单点故障问题,它能够保证网络的不间断,稳定的运行。所以keepalive一方面具有LVS cluster nodes healthchecks功能,另一方面也具有LVS directors failover

1.1 Keepalived的用途

Keepalive服务的两大用途:healthcheck和failover

ha failover功能:实现LB Master主机和Backup主机之间故障转移和自动切换

这是针对有两个负载均衡器Direator同时工作而采取的故障转移措施,当主负载均衡器失效或者出现故障时,备份的负载均衡器(BACKUP)将自动接管主负载均衡器的所有工作(vip资源以及相关服务):一旦主负载均衡器故障恢复,MASTER又会接管回它原来的工作,二备份复杂均衡器(BACKUP)会释放master是小事它接管的工作,此时两者将恢复到最初各自的角色

1.2 LVS cluster nodes healthchecks功能

在keeplive.conf配置记忆可以实现LVS的功能

keeplive可以对LVS下面的集群节点进行健康检查

rs healthcheck功能:负载均衡定期检查RS的可用性决定是否给其分发请求

当虚拟的服务器中的某一个甚至是几个真实的服务器同时出现故障无法提供服务时,负载均衡器会自动将失效的RS服务器从转发队列中清除出去,从而保证用户的访问不收影响;当故障的RS服务器被修复后,系统又自动的将他们加入转发队列,分发请求提供正常服务。

工作原理

1.3 keepalive故障切换转换原理

Keepalived高可用对之间是通过 VRRP进行通信的, VRRP是遑过竞选机制来确定主备的,主的优先级高于备,因此,工作时主会优先获得所有的资源,备节点处于等待状态,当主挂了的时候,备节点就会接管主节点的资源,然后顶替主节点对外提供服务。

在 Keepalived服务对之间,只有作为主的服务器会一直发送 VRRP广播包,告诉备它还活着,此时备不会枪占主,当主不可用时,即备监听不到主发送的广播包时,就会启动相关服务接管资源,保证业务的连续性.接管速度最快可以小于1秒。

1.4 VRRP协议的简单介绍

1) VRRP,全称 Virtual Router Redundancy Protocol,中文名为虚拟路由冗余协议,VRRP的出现是为了解决静态路由的单点故障。

2) VRRP是通过一种竟选协议机制来将路由任务交给某台 VRRP路由器的。

3) VRRP用 IP多播的方式(默认多播地址(224.0_0.18))实现高可用对之间通信。

4) 工作时主节点发包,备节点接包,当备节点接收不到主节点发的数据包的时候,就启动接管程序接管主节点的开源。备节点可以有多个,通过优先级竞选,但一般 Keepalived系统运维工作中都是一对。

5) VRRP使用了加密协议加密数据,但Keepalived官方目前还是推荐用明文的方式配置认证类型和密码

二、配置Keepalived实现高可用

2.1 安装keepalive

[[email protected] ~]# cd /usr/local/src/

[[email protected] src]# wget https://www.keepalived.org/software/keepalived-2.0.15.tar.gz

[[email protected] src]# tar -xf keepalived-2.0.15.tar.gz

[[email protected] src]# cd keepalived-2.0.15

[[email protected] keepalived-2.0.15]# ./configure

Linker flags             :  -pie
Extra Lib                :  -lm -lcrypto  -lssl
Use IPVS Framework       : Yes
IPVS use libnl           : No
IPVS syncd attributes    : No
IPVS 64 bit stats        : No
HTTP_GET regex support   : No
fwmark socket support    : Yes
Use VRRP Framework       : Yes
Use VRRP VMAC            : Yes
Use VRRP authentication  : Yes
With ip rules/routes     : Yes
With track_process       : Yes
With linkbeat            : Yes
Use BFD Framework        : No
SNMP vrrp support        : No
SNMP checker support     : No
SNMP RFCv2 support       : No
SNMP RFCv3 support       : No
DBUS support             : No
SHA1 support             : No
Use JSON output          : No
libnl version            : None
Use IPv4 devconf         : No
Use iptables             : Yes
Use libiptc              : No
Use libipset             : No
Use nftables             : No
init type                : systemd
Strict config checks     : No
Build genhash            : Yes
Build documentation      : No

[[email protected] keepalived-2.0.15]# make

[[email protected] keepalived-2.0.15]# make install

lb02相同操作

[[email protected] ~]# cd /usr/local/src/
[[email protected] src]# wget https://www.keepalived.org/software/keepalived-2.0.15.tar.gz
[[email protected] src]# tar -xf keepalived-2.0.15.tar.gz
[[email protected] src]# cd keepalived-2.0.15
[[email protected] keepalived-2.0.15]# ./configure
[[email protected] keepalived-2.0.15]# make
[[email protected] keepalived-2.0.15]# make install

[[email protected] keepalived-2.0.15]# vim /usr/lib/systemd/system/keepalived.service

[Unit]
Description=LVS and VRRP High Availability Monitor
After=syslog.target network-online.target

[Service]
Type=forking
PIDFile=/var/run/keepalived.pid
KillMode=process
EnvironmentFile=-/etc/sysconfig/keepalived
ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

2.2 配置文件

[[email protected] keepalived-2.0.15]# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived      #!注释

global_defs {                            #全局变量
   notification_email {
     [email protected]                    #收件人
   }                                     #邮件发件人
   notification_email_from [email protected]
   smtp_server 192.168.200.1             #邮件服务器地址
   smtp_connect_timeout 30               #超时时间
   router_id LVS_01
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {               #keepalive或者vrrp的一个实例
    state MASTER                   #状态
    interface ens33                #通信端口
    virtual_router_id 51           #实例ID
    priority 150                   #优先级
    advert_int 1                   #心跳的间隔
    authentication {               #服务器之间通过密码验证
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.131                 #VIP
    }
}

2.3 启动看效果

[[email protected] keepalived]# systemctl start keepalived

[[email protected] keepalived]# ps -ef|grep keep

[[email protected] keepalived]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:12:2e:59 brd ff:ff:ff:ff:ff:ff
    inet 172.25.254.131/24 brd 172.25.254.255 scope global dynamic ens33
       valid_lft 1085sec preferred_lft 1085sec
    inet 10.0.0.131/24 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::8068:96e2:b57b:be1d/64 scope link
       valid_lft forever preferred_lft forever
3: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:12:2e:63 brd ff:ff:ff:ff:ff:ff

2.4 keepalive的VIP实现形式

[[email protected] keepalived]# ifconfig ens33:0 10.0.0.18 up

[[email protected] keepalived]# ip addr add 10.0.0.19 dev ens33

[[email protected] keepalived]# ip addr

inet 172.25.254.131/24 brd 172.25.254.255 scope global dynamic ens33
       valid_lft 1583sec preferred_lft 1583sec
    inet 10.0.0.131/24 scope global ens33
       valid_lft forever preferred_lft forever
    inet 10.0.0.18/8 brd 10.255.255.255 scope global ens33:0
       valid_lft forever preferred_lft forever
    inet 10.0.0.19/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::8068:96e2:b57b:be1d/64 scope link
       valid_lft forever preferred_lft forever

[[email protected] keepalived]# ip addr del 10.0.0.19 dev ens33

[[email protected] keepalived]# ifconfig ens33:0 10.0.0.18 down

[[email protected] keepalived]# scp /etc/keepalived/keepalived.conf  172.25.254.133:/etc/keepalived/

[[email protected] ~]# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
        283365585@qq.com
   }
   notification_email_from [email protected]
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_02
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    10.0.0.131/24
    }
} 

[[email protected] ~]# systemctl start keepalived

[[email protected] ~]# ps -ef |grep keep

配置成功

2.5 检测keepalibve效果

关闭MASTER的keepalive服务

[[email protected] keepalived]# systemctl stop keepalived

[[email protected] keepalived]# ip addr|grep 10.0.0.131

查看BACKUP端,是否有10.0.0.131

[[email protected] ~]# ip addr|grep 10.0.0.131

[[email protected] keepalived]# systemctl start keepalived

成功

三、 结合nginx实现高可用

3.1 配置

[[email protected] keepalived]# cd /usr/local/nginx/conf/

[[email protected] conf]# vim nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
upstream  web_pools {
        server 172.25.254.134:80 weight=5;
        server 172.25.254.135:80 weight=5;
#       server 172.25.254.158:80 weight=5  backup;

}
    server {
        listen       80;
        server_name  www.lbtest.com;
        location / {
           # root   html;
           # index  index.html index.htm;
            proxy_set_header Host $host;
            proxy_pass http://web_pools;
        }
    }
}

[[email protected] conf]# scp nginx.conf  172.25.254.133:/usr/local/nginx/conf/

[[email protected] conf]# nginx  -s reload
[[email protected] conf]# curl 172.25.254.134
172.25.254.134
[[email protected] conf]# curl 172.25.254.135
172.25.254.135
[[email protected] conf]# nginx  -s reload
[[email protected] ~]# curl 172.25.254.134
172.25.254.134
[[email protected] ~]# curl 172.25.254.135
172.25.254.135

在获取到VIP后,不在同一网段,为了方便测试,把VIP设置为172.25.254.254

[[email protected] ~]# ip addr|grep 172.25.254.254

3.2 发现不能访问的问题

访问测试,发现不能访问,也不能ping通

[[email protected] conf]# curl 172.25.254.254

curl: (7) Failed connect to 172.25.254.254:80; Connection timed out

[[email protected] conf]# ping 172.25.254.254

2 packets transmitted, 0 received, 100% packet loss, time 999ms

解决

[[email protected] conf]# vim /etc/keepalived/keepalived.conf

# vrrp_strict   # 注释掉vrrp_strict

[[email protected] conf]# systemctl restart keepalived

3.3 测试

[[email protected] conf]# curl 172.25.254.254
172.25.254.135
[[email protected] conf]# curl 172.25.254.254
172.25.254.134
[[email protected] conf]# curl 172.25.254.254
172.25.254.135
[[email protected] conf]# curl 172.25.254.254
172.25.254.134

关闭MASTER测试

[[email protected] conf]# systemctl stop keepalived   #这时VIP已经在BACKUP上,但是可以正常访问
[[email protected] conf]# curl 172.25.254.254
172.25.254.135
[[email protected] conf]# curl 172.25.254.254
172.25.254.134
[[email protected] conf]# curl 172.25.254.254
172.25.254.135
[[email protected] conf]# curl 172.25.254.254
172.25.254.134
[[email protected] conf]# curl 172.25.254.254
172.25.254.135

使用主机,域名访问

172.25.254.254  www.lbtest.com  #写hosts

正常访问

四、keepalived的其他特性

4.1 监控自动迁移脚本

keepalived解决的是主机级别的冗余,当nginx宕掉的时候,keepalive并不会迁移,这时VIP依然在该主机上,客户就不能访问到网站

使用脚本监控,当nginx挂掉,自动停掉keepalive,是VIP漂移,是业务不受影响

[[email protected] conf]# mkdir /script

[[email protected] conf]# vim /script/monitor.sh

#!/bin/bash
while true
do
if [ `ps -ef |grep nginx|grep -v grep |wc -l` -lt 2 ]
  then
      systemctl stop keepalived
fi
sleep 5
done

[[email protected] conf]# cd /script/

[[email protected] script]# chmod +x monitor.sh

[[email protected] script]# /script/monitor.sh &

关掉nginx

[[email protected] script]# nginx -s stop

VIP漂移到BACKUP上

[[email protected] ~]# ip addr|grep 254.254

inet 172.25.254.254/24 scope global secondary ens33

访问:

[[email protected] script]# curl 172.25.254.254
172.25.254.134
[[email protected] script]# curl 172.25.254.254
172.25.254.135
[[email protected] script]# curl 172.25.254.254
172.25.254.134
[[email protected] script]# curl 172.25.254.254
172.25.254.135

4.2  keepalive高可用脑裂脚本

[[email protected] script]# ps -ef |grep monitor
root 80993 68563 0 07:04 pts/0 00:00:00 /bin/bash /script/monitor.sh
[[email protected] script]# kill -9 80993
[1]+  Killed                  /script/monitor.sh
[[email protected] script]# ps -ef |grep monitor
root      82773  68563  0 07:13 pts/0    00:00:00 grep --color=auto monitor
[[email protected] script]# systemctl restart keepalived

[[email protected] ~]# mkdir /script

检测脑裂脚本,实现形式,当BACKUP可以ping通主,但是VIP依然在BACKUP,则认定为脑裂

[[email protected] script]# vim check_split_brain.sh

#!/bin/bash
while true
do
ping -c 2 -W 3 172.25.254.131 &>/dev/null
  if [ $? -eq 0 -a `ip addr|grep 172.25.254.254|wc -l` -eq 1 ]
    then
      echo "ha is split brain warning"
else
      echo "ha is OK"
fi
sleep 3
done

[[email protected] ~]# sh /script/check_split_brain.sh

ha is OK
ha is OK
[[email protected] ~]# systemctl start firewalld
ha is split brain warning
ha is split brain warning
[[email protected] ~]# ip addr |grep 172.25.254.254
inet 172.25.254.254/24 scope global secondary ens33
[[email protected] ~]# ip addr |grep 172.25.254.254
inet 172.25.254.254/24 scope global secondary ens33
[[email protected] ~]# systemctl stop firewalld
ha is OK
ha is OK

4.3 修改日志文件路径

配置文件默认在/var/log/messages

[[email protected] ~]# tail -f /var/log/messages
Apr 13 07:41:26 node2 Keepalived_vrrp[82796]: Sending gratuitous ARP on ens33 for 172.25.254.254
Apr 13 07:41:26 node2 Keepalived_vrrp[82796]: Sending gratuitous ARP on ens33 for 172.25.254.254
Apr 13 07:41:26 node2 Keepalived_vrrp[82796]: Sending gratuitous ARP on ens33 for 172.25.254.254
Apr 13 07:41:26 node2 Keepalived_vrrp[82796]: VRRP_Instance(VI_1) Received advert with lower priority 100, ours 150, forcing new election
Apr 13 07:41:26 node2 Keepalived_vrrp[82796]: Sending gratuitous ARP on ens33 for 172.25.254.254
Apr 13 07:41:26 node2 Keepalived_vrrp[82796]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 172.25.254.254

修改日志文件位置

[[email protected] ~]# vi /etc/sysconfig/keepalived

# Options for keepalived. See `keepalived --help‘ output and keepalived(8) and
# keepalived.conf(5) man pages for a list of all options. Here are the most
# common ones :
#
# --vrrp               -P    Only run with VRRP subsystem.
# --check              -C    Only run with Health-checker subsystem.
# --dont-release-vrrp  -V    Dont remove VRRP VIPs & VROUTEs on daemon stop.
# --dont-release-ipvs  -I    Dont remove IPVS topology on daemon stop.
# --dump-conf          -d    Dump the configuration data.
# --log-detail         -D    Detailed log messages.
# --log-facility       -S    0-7 Set local syslog facility (default=LOG_DAEMON)
#

KEEPALIVED_OPTIONS="-D -S 0 -d"

[[email protected] ~]# vim /etc/rsyslog.conf

local0.*                                                /var/log/keepalived.log

[[email protected] ~]# systemctl restart rsyslog

[[email protected] ~]# systemctl restart keepalived

[[email protected] ~]# tail -f /var/log/keepalived.log

Apr 13 07:46:23 node2 Keepalived_vrrp[84692]: Sending gratuitous ARP on ens33 for 172.25.254.254
Apr 13 07:46:23 node2 Keepalived_vrrp[84692]: Sending gratuitous ARP on ens33 for 172.25.254.254
Apr 13 07:46:23 node2 Keepalived_vrrp[84692]: Sending gratuitous ARP on ens33 for 172.25.254.254
Apr 13 07:46:23 node2 Keepalived_vrrp[84692]: VRRP_Instance(VI_1) Received advert with lower priority 100, ours 150, forcing new election
Apr 13 07:46:23 node2 Keepalived_vrrp[84692]: Sending gratuitous ARP on ens33 for 172.25.254.254
Apr 13 07:46:23 node2 Keepalived_vrrp[84692]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 172.25.254.254

4.4 keepalived多实例

[[email protected] ~]# vim /etc/keepalived/keepalived.conf

  1 ! Configuration File for keepalived
  2
  3 global_defs {
  4    notification_email {
  5         283365585@qq.com
  6    }
  7    notification_email_from [email protected]
  8    smtp_server 192.168.200.1
  9    smtp_connect_timeout 30
 10    router_id LVS_01
 11    vrrp_skip_check_adv_addr
 12   # vrrp_strict
 13    vrrp_garp_interval 0
 14    vrrp_gna_interval 0
 15 }
 16
 17 vrrp_instance VI_1 {
 18     state MASTER
 19     interface ens33
 20     virtual_router_id 51
 21     priority 150
 22     advert_int 1
 23     authentication {
 24         auth_type PASS
 25         auth_pass 1111
 26     }
 27     virtual_ipaddress {
 28     172.25.254.254/24
 29     }
 30 }
 31 vrrp_instance VI_2 {
 32     state BACKUP
 33     interface ens33
 34     virtual_router_id 52
 35     priority 100
 36     advert_int 1
 37     authentication {
 38         auth_type PASS
 39         auth_pass 1111
 40     }
 41     virtual_ipaddress {
 42     172.25.254.253/24
 43     }
 44 }

[[email protected]2 ~]# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
        283365585@qq.com
   }
   notification_email_from [email protected]
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_02
   vrrp_skip_check_adv_addr
  # vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    172.25.254.254/24
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 52
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    172.25.254.253/24
    }
}

检测

[[email protected] ~]# systemctl restart keepalived
[[email protected] ~]# systemctl restart keepalived
[[email protected] ~]# ip addr
 inet 172.25.254.131/24 brd 172.25.254.255 scope global dynamic ens33
       valid_lft 499sec preferred_lft 499sec
    inet 172.25.254.254/24 scope global secondary ens33
       valid_lft forever preferred_lft forever
[[email protected] ~]# ip addr
inet 172.25.254.133/24 brd 172.25.254.255 scope global dynamic ens33
       valid_lft 422sec preferred_lft 422sec
    inet 172.25.254.253/24 scope global secondary ens33
       valid_lft forever preferred_lft forever
[[email protected] ~]# systemctl stop keepalived
[[email protected] ~]# ip addr|grep 172.25.254
    inet 172.25.254.133/24 brd 172.25.254.255 scope global dynamic ens33
[[email protected] ~]# ip addr |grep 172.25.254
    inet 172.25.254.131/24 brd 172.25.254.255 scope global dynamic ens33
    inet 172.25.254.254/24 scope global secondary ens33
    inet 172.25.254.253/24 scope global secondary ens33
[[email protected] ~]# systemctl start keepalived
[[email protected] ~]# ip addr|grep 172.25.254
    inet 172.25.254.133/24 brd 172.25.254.255 scope global dynamic ens33
    inet 172.25.254.253/24 scope global secondary ens33
[[email protected] ~]# ip addr |grep 172.25.254
    inet 172.25.254.131/24 brd 172.25.254.255 scope global dynamic ens33
    inet 172.25.254.254/24 scope global secondary ens33

参考:老男孩教育视频公开课https://www.bilibili.com/video/av25869969/?p=25



nginx和keeplive实现负载均衡高可用

原文地址:https://www.cnblogs.com/zyxnhr/p/10727035.html

时间: 2024-10-11 15:50:18

nginx和keeplive实现负载均衡高可用的相关文章

linux系统下对网站实施负载均衡+高可用集群需要考虑的几点

随着linux系统的成熟和广泛普及,linux运维技术越来越受到企业的关注和追捧.在一些中小企业,尤其是牵涉到电子商务和电子广告类的网站,通常会要求作负载均衡和高可用的Linux集群方案. 那么如何实施linux集群架构,才能既有效保证网站健康运行,又能节省运维成本呢?下面依据近几年的运维经历,简单梳理下自己的一点感悟. (1)机房的选择如果有自己公司的机房那是再好不过的了:如果没有,建议放在BGP机房内托管,如果有选择的话,最好是选择带有硬件防火墙的机房,这样在安全方面也有保障:网站如若是放在

Nginx+Keepalived 实现反代 负载均衡 高可用(HA)配置

Nginx+Keepalived实现反代负载均衡高可用(HA)配置 Nginx+Keepalived实现反代负载均衡高可用配置 OS IP 子网掩码 路由网关 Centos6.6 nginx Keepalived Eth0:192.168.26.210 255.255.252.0 192.168.25.3 VIP:192.168.27.210 Centos6.6 Nginx Keepalived Eth0:192.168.26.211 255.255.252.0 192.168.25.3 VIP

CentOS Linux 负载均衡高可用WEB集群之Nginx+Keepalived配置

Nginx+Keepalived实现负载均衡高可用的WEB服务集群,nginx作为负载均衡器,keepalived作为高可用,当其中的一台负载均衡器(nginx)发生故障时可以迅速切换到备用的负载均衡器(nginx),保持业务的连续性. 1.服务器的环境配置及IP分配 操作系统:CentOS release 6.7 (Final) nginx版本:nginx/1.8.0 keepalived版本:Keepalived v1.2.13 Nginx + keepalived服务器的IP分配表 服务器

Nginx+Keepalived负载均衡高可用(双机热备)

Nginx+Keepalived负载均衡高可用(双机热备) 1.1 Nginx安装及配置 1.2 Keepalived安装及配置 1.3 WebServer安装 1.4 测试Nginx+Keepalived 环境如下: CentOS 6.4_64K eepalived-1.2.12 Nginx-1.4.4 vip:192.168.10.50 master:192.168.10.11 backup:192.168.10.12 webserver1:192.168.10.13 webserver2:

Nginx + Keepalived(主备模式)实现负载均衡高可用浅析

概述 目前关于负载均衡和高可用的架构方案能找到相当多且详尽的资料,此篇是自己学习相关内容的一个总结,防止将来遗忘再次重新查找资料,也避免踩相同的坑. 此次配置的负载均衡与高可用架构:Nginx + Keepalived(主备模式),Nginx 使用反向代理实现七层负载均衡. 众所周知,Nginx 是一款自由的.开源的.高性能HTTP服务器和反向代理服务器,也是一个IMAP.POP3.SMTP代理服务器. 也就是说Nginx本身就可以托管网站(类似于Tomcat一样),进行HTTP服务处理,也可以

Keepalived+Nginx实现负载均衡高可用

一.负载均衡高可用 Nginx作为负载均衡器,所有请求都到了Nginx,可见Nginx处于非常重点的位置,如果Nginx服务器宕机后端web服务将无法提供服务,影响严重. 为了避免负载均衡服务器的宕机故障,需要建立一个备份机.主备机上都运行高可用(High Availability)监控程序,通过传送心跳信息来监控对方的运行状况.当备份机不能在一定的时间内收到对方的正常心跳时,它就接管主服务器的服务IP并继续提供负载均衡服务:当备份管理器又从主管理器收到"I am alive"这样的信

Nginx负载均衡高可用

1.   Nginx负载均衡高可用 要实现nginx的高可用,需要实现备份机. 1.1. 什么是负载均衡高可用 nginx作为负载均衡器,所有请求都到了nginx(对外服务的唯一入口,唯一公网IP),可见nginx处于非常重点的位置,如果nginx服务器宕机后端web服务将无法提供服务,影响严重. 为了屏蔽负载均衡服务器的宕机,需要建立一个备份机.主服务器和备份机上都运行高可用(High Availability)监控程序,通过传送诸如“I am alive”这样的信息来监控对方的运行状况.当备

CentOS Linux 负载均衡高可用WEB集群之LVS+Keepalived配置

CentOS Linux 负载均衡高可用WEB集群之LVS+Keepalived配置 LB集群是locd balance集群的简称.翻译成中文是:负载均衡集群的意思:集群是一组相互独立的.通过高速网络互联的计算机相互之间构成一个组合,并以单一的系统的模式加以管理.LVS是Linux Virtual Server的简写,翻译中文是Linux虚拟服务器,是一个虚拟的服务器集群系统. 负载均衡集群:是为了企业提供更为实用,性价比更高的系统机构解决方案.负载均衡集群把用户的请求尽可能的平均分发到集群的各

HAproxy+Keepalived负载均衡-高可用web站

haproxy+keepalived负载均衡高可用web站   OS IP 子网掩码 路由网关 Centos6.6 HAproxy Keepalived Eth0:192.168.26.210 255.255.252.0 192.168.25.3 VIP:192.168.27.210 Centos6.6 HAporxy Keepalived Eth0:192.168.26.211 255.255.252.0 192.168.25.3 VIP:192.168.27.210 Centos6.6(WE