Linux, 应用部署

HAProxy+Keepalived 搭建高可用负载均衡集群

1、HAProxy介绍

HAProxy提供高可用性、负载均衡以及基于TCP和HTTP应用层的代理,支持虚拟主机,它是免费、快速并且可靠的一种解决方案。基于TCP (四层),HTTP (七层) 应用的负载均衡软件,HAProxy特别适用于那些负载特别大的web站点,这些站点通常有需要会话保持或七层处理。

HAProxy软件优点

(1)可靠性和稳定性非常好,可以与硬件级F5负载均衡设备媲美

(2)最高可同事维护4W-5W个并发连接,单位时间内最大请求为20000个,最大数据处理能力可达10Gbps。

(3)支持多于8中负载均衡算法,同事支持会话保持。

(4)支持虚拟主机功能

(5)从1.3版本后支持拒绝连接,全透明代理,这些功能室其他负载均衡所不具备的

(6)HAProxy拥有一个强大的服务器状态监控页面,可以通过此页面实时了解系统状况

(7)HAproxy拥有功能强大的ACL支持,给使用上带来很大方面

(8)HAProxy是借助于操作系统的技术特性来实现性能最大化的,因此,在使用HAProxy时对操作系统的性能调优是非常重要的。

(9)能够补充Nginx的一些缺点,比如Session的保持,Cookie的引导等工作,支持url检测后端的服务器出问题的检查会有很好的帮助,它和LVS一样,本身仅仅就只是一款负载均衡软件。

2、拓扑图及规划

3、HAProxy安装设置

调度服务器1、2的配置:

[root@localhost ~]# cat /etc/haproxy/haproxy.cfg 
global
log 127.0.0.1 local0 info 
maxconn 256
chroot /usr/local/haproxy
uid 1000
gid 1000
daemon
defaults
mode http
timeout connect 1500ms
timeout client 5000ms
timeout server 5000ms
option httpclose
option dontlognull
option forwardfor
option redispatch
option abortonclose
frontend http-in
bind *:80
log global
default_backend servers
backend servers
option httpchk GET /index.html
balance roundrobin
server server1 192.168.168.142:80 check inter 2000 rise 2 fall 2 
server server2 192.168.168.143:80 check inter 2000 rise 2 fall 2 
listen stats
mode http
bind 0.0.0.0:9999
stats enable
log global
stats uri /status
stats auth haadmin:qm123com

4、Keepalived的安装配置

调度服务器1的配置:

[root@localhost ~]# cat /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_147
   vrrp_skip_check_adv_addr
#   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.168.188
    }
}
调度服务器2的配置:

[root@localhost ~]# cat /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_148
   vrrp_skip_check_adv_addr
#   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens32
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.168.188
    }
}

5、其它设置

1)NFS服务器的安装及配置好后,把网站文件所在目录共享给服务器池使用即可。

2)服务器池1、2安装配置好httpd,并且把NFS共享存储挂载到httpd的文档根目录下即可。

6、验证

Leave a Reply