您的位置:首页 > 其它

haproxy 实用配置解析

2017-10-31 22:25 239 查看
LB Cluster:

四层: lvs, nginx(stream), haproxy(mode tcp)

七层: http: nginx(http), haproxy(mode http), httpd…

 HAProxy: http://www.haproxy.org

 文档: https://cbonte.github.io/haproxy-dconv/

Haproxy功能

HAProxy是TCP / HTTP反向代理服务器,尤其适合于高可用

性环境

 可以针对HTTP请求添加cookie,进行路由后端服务器

 可平衡负载至后端服务器,并支持持久连接

 支持基于cookie进行调度

 支持所有主服务器故障切换至备用服务器

 支持专用端口实现监控服务

 支持不影响现有连接情况下停止接受新连接请求

 可以在双向添加,修改或删除HTTP报文首部

 支持基于pattern实现连接请求的访问控制

 通过特定的URI为授权用户提供详细的状态信息

 支持http反向代理

 支持动态程序的反向代理

 支持基于数据库的反向代理

配置段:

 global:全局配置段

进程及安全配置相关的参数

性能调整相关参数

Debug参数

 proxies:代理配置段

defaults:为frontend, backend, listen提供默认配置

fronted:前端,相当于nginx, server {}

backend:后端,相当于nginx, upstream {}

listen:同时拥有前端和后端,适用于一对一环境

defaults
mode                    http
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
log                     global
option                  httplog
option                  dontlognull
option http-server-close
option forwardfor       except 127.0.0.0/8
option                  redispatch
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 http 192.168.1.33:80
stats enable
stats uri /hastats
stats auth ha1:centos
#stats auth ha2:mage
default_backend webs
backend webs
balance roundrobin
option httpchk GET /index.html HTTP/1.1\r\nhost:
cookie SRV insert nocache
server web1 192.168.10.30:80 check
server web2 192.168.10.32:80 check maxconn 5000

#frontend http 192.168.1.33:80

#frontend  main *:5000
#   acl url_static       path_beg       -i /static /images /javascript /stylesheets

#  acl url_static       path_end       -i .jpg .gif .png .css .js

#   use_backend static          if url_static
#  default_backend             app

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
#backend static
#   balance     roundrobin
#   server      static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
#backend app
#   balance     roundrobin
#  server  app1 127.0.0.1:5001 check
# server  app2 127.0.0.1:5002 check
# server  app3 127.0.0.1:5003 check
# server  app4 127.0.0.1:5004 check`这里写代码片`


未完待续。。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  haproxy