您的位置:首页 > 理论基础 > 计算机网络

HAProxy提供高可用性、负载均衡以及基于TCP和HTTP应用的代理配置

2013-07-23 20:27 691 查看
global
log 127.0.0.1 local3 # 日志服务器
maxconn 4096 # 单个进程的最大并发数
user nobody # 用户身份
group nobody # 组身份
daemon # 守护进程后台运行
nbproc 1 # 工作进程数量
defaults
log global # 记录日志
mode http # 工作模式 http layer7
option httplog
option dontlognull # 记录空连接日志
retries 3
option redispatch # 强制转换健康服务器
maxconn 2000 # 最大连接数
stats uri /stats
option forwardfor # 后端服务器用forwardfor获取用户IP
contimeout 5000 # 连接超时 毫秒
clitimeout 50000 # 客户端超时
srvtimeout 50000 # 服务器超时
# qiantai
frontend httpd-in
bind 0.0.0.0:80
mode http
log global
option httplog
option httpclose
option forwardfor
#logs
capture request header Host len 20
capture request header User-Agent len 16
capture request header Content-Length len 10
capture request header Referer len 20
capture response header Content-Length len 10
#acl ctrol
acl api_php url_reg -i \.php$
acl api_html url_reg -i \.html$
use_backend php-server if api_php
use_backend html-server if api_html
default_backend html-server

#backend php
backend php-server
mode http
balance roundrobin
server web1 192.168.122.11:80 weight 3 check
server web2 192.168.122.12:80 weight 2 check
option httpchk GET /index.html

#backend html
backend html-server
mode http
balance roundrobin
server web3 192.168.122.15:80 weight 3 check
server web4 192.168.122.16:80 weight 4 check
option httpchk GET /index.php

#listen web 0.0.0.0:80
# mode http
# balance roundrobin # 负载均衡的方式
# cookie SERVERID indirect nocache # 客户端的cookie信息
# option httpclose # 打开支持主动关闭功能
# option forwardfor
# option httpchk HEAD /index.html HTTP/1.0 # 健康检查
# server server1 192.168.122.11:80 cookie 1 check inter 2000 rise 2 fall 5
# server server2 192.168.122.12:80 cookie 2 check inter 2000 rise 2 fall 5
#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息