首页 > 代码库 > Ubuntu 16.04 haproxy + keeplive

Ubuntu 16.04 haproxy + keeplive

WEB架构

技术分享

阐述各服务器用途:

   1、haproxy        实现后端Web服务器负载均衡

   2、keepalived    实现对haproxy的高可用

   3、apache static     实现静态页面的访问

   4、aoache dynamic    实现动态页面的访问

What is Keepalived ?

Keepalived is a routing software written in C. The main goal of this project is to provide simple and robust facilities(能力) for loadbalancing and high-availability to Linux system and Linux based infrastructures. Loadbalancing framework relies(依赖) on well-known and widely used Linux Virtual Server (IPVS) kernel module providing Layer4 loadbalancing. On the other hand high-availability is achieved by VRRP protocol.

 

1、安装Keepalived

~# apt-get install keepalived

 

2、配置Keepalived

一个功能比较完整的keepalived 的配置文件,其配置文件keepalived.conf 可以包含三个文本块:

全局定义块

VRRP 实例定义块

虚拟服务器定义块

 

haproxy

安装配置链接

配置文件:

global
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    pidfile /var/run/haproxy.pid
    maxconn 4000
    stats socket /run/haproxy/admin.sock mode 660 level admin
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

    # Default SSL material locations
    ca-base /etc/ssl/certs
    crt-base /etc/ssl/private

    # Default ciphers to use on SSL-enabled listening sockets.
    # For more information, see ciphers(1SSL). This list is from:
    #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
    ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
    ssl-default-bind-options no-sslv3

defaults
    log    global
    mode    http
    option    httplog
    option    dontlognull
    option  http-server-close
    option  forwardfor except 127.0.0.0/8
    maxconn 60000
    retries 3
        timeout connect 10s
        timeout client  1m
        timeout server  1m
    timeout check  10s
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http

listen stats
    bind 0.0.0.0:1080
    stats refresh 30s
    stats uri /stats
    stats realm Haproxy Manager
    stats auth admin:admin
    
frontend main
    bind 0.0.0.0:80
    
    acl url_static path_beg -i /static /images /javascript /stylesheets
    acl url_static path_end -i .jpg .gif .png .css .js
    acl url_dynamic path_end -i .jsp
    use_backend static if url_static
    use_backend dynamic if url_dynamic
    default_backend static


backend static
    balance roundrobin
    server websrv1 192.168.20.178:80 check maxconn 1000
    server websrv2 192.168.20.179:80 check maxconn 1000

backend dynamic
    balance roundrobin
    server dynamic1 192.168.20.177:8080 inter 3000 rise 2 fall 3 check maxconn 100
    server dynamic2 192.168.20.181:8080 inter 3000 rise 3 fall 3 check maxconn 100

 

Ubuntu 16.04 haproxy + keeplive