yum安装后的配置文件,内容仅作参考
#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
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#可选(tcp|http|health),tcp是4层,http是7层,health只会返回ok log global#采用全局定义的日志 option httplog#日志的类别http日志格式 option dontlognull#不记录健康检擦的日志信息 option http-server-close option forwardfor except 127.0.0.0/8#如果后端服务器需要获得客户端真是ip需要的配置参数。可从http Header得到 option redispatch retries 3##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 *:5000#默认端口 acl url_static path_beg -i /static /images /javascript /stylesheets #acl后是规则名,-i忽略大小写,i后是要访问的 acl url_static path_end -i .jpg .gif .png .css .js
use_backend static if url_static#如url_static规则被触发,就将请求分配到static default_backend app #不满足上面的规则就默认访问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 server ng 192.168.242.133:80 check