打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
keepalived haproxy 实现web 双主模型的高可用负载均衡
[root@node2 ~]# yum -y install haproxy  安装haproxy
[root@node2 ~]# vim /etc/haproxy/haproxy.cfg
    #
    log         127.0.0.1 local2
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http      指定haproxy工作模式为http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close       当客户端超时时,允许服务端断开连接
    option forwardfor       except 127.0.0.0/8  在http的响应头部加入forwardfor
    option                  redispatch    #在使用了基于cookie的会话保持的时候,通常加这么一项,一旦后端某一server宕机时,能够将其会话重新派发到其它的upstream servers
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  main *: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 .php
    use_backend static          if url_static
    default_backend             dynamic
#---------------------------------------------------------------------
static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static   后端的静态请求响应
    balance     roundrobin
    server      static 192.168.1.100:80 inter 3000 rise 2 fall 3 check maxconn 5000
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend dynamic   后端的动态请求响应
    balance     roundrobin
    server  dynamic1 192.168.1.101:80 inter 3000 rise 2 fall 3 check maxconn 5000
    server  dynamic2 192.168.1.102:80 inter 3000 rise 2 fall 3 check maxconn 5000
listen statistics
        mode http
        bind *:8080
~       stats enable
        stats auth admin:admin
        stats uri /admin?stats   指定URI的访问路径
        stats admin if TRUE
        stats hide-version
        stats refresh 5s
        acl allow src 192.168.0.0/24   定义访问控制列表
        tcp-request content accept if allow
        tcp-request content reject
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
OpenFire源码学习之三十:haproxy负载均衡
Rancher Server部署方式及Rancher HA环境部署
haproxy参数配置说明
haproxy 命令配置实例
负载均衡集群解决方案(三)haproxy
自建CDN防御DDoS:架构设计、成本与部署细节
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服