1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| ####################全局配置######################## #######参数是进程级的,通常和操作系统(OS)相关######### global maxconn 20480 #默认最大连接数 log 127.0.0.1 local0 #日志输出配置,所有日志都记录在本机系统日志,通过local0输出 log 127.0.0.1 local1 notice #notice 为日志级别,通常有24个级别(error warring info debug) chroot /var/haproxy #chroot服务自设置的根目录,一般需将此行注释掉 uid 99 #所属运行的用户uid gid 99 #所属运行的用户组 daemon #守护进程。以后台形式运行haproxy nbproc 1 #进程数量(可以设置多个进程提高性能) pidfile /var/run/haproxy.pid #haproxy的pid存放路径,启动进程的用户必须有权限访问此文件 ulimit-n 65535 #ulimit的数量限制
#####################默认设置###################### ##这些参数可以被利用配置到frontend,backend,listen组件## defaults log global #定义日志为global配置中的日志定义 mode http #所处理的类别 (#7层 http;4层tcp ) maxconn 20480 #最大连接数 option httplog #日志类别http日志格式 option httpclose #每次请求完毕后主动关闭http通道 option dontlognull #不记录健康检查的日志信息 option forwardfor #如果后端服务器需要获得客户端真实ip需要配置的参数,可以从Http Header中获得客户端ip option redispatch #serverId对应的服务器挂掉后,强制定向到其他健康的服务器 option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的连接 stats refresh 30 #统计页面刷新间隔 retries 3 #检查节点服务器失败次数,连续达到三次失败,则认为节点不可用 balance roundrobin #默认的负载均衡的方式,轮询方式 #balance source #默认的负载均衡的方式,类似nginx的ip_hash #balance leastconn #默认的负载均衡的方式,最小连接 contimeout 5000 #连接的超时时间 clitimeout 50000 #客户端的超时时间 srvtimeout 50000 #服务器的超时时间 timeout check 2000 #心跳检测的超时时间 ####################监控页面的设置####################### listen admin_status #Frontend和Backend的组合体,监控组的名称,按需自定义名称 bind 0.0.0.0:8189 #监听端口 mode http #http的7层模式 log 127.0.0.1 local3 err #错误日志记录 stats refresh 5s #每隔5秒自动刷新监控页面 stats uri /admin?stats #监控页面的url stats realm itnihao\ itnihao #监控页面的提示信息 stats auth admin:admin #监控页面的用户和密码admin,可以设置多个用户名 stats auth admin1:admin1 #监控页面的用户和密码admin1 stats hide-version #隐藏统计页面上的HAproxy版本信息 stats admin if TRUE #手工启用/禁用,后端服务器(haproxy-1.4.9以后版本) errorfile 403 /etc/haproxy/errorfiles/403.http errorfile 500 /etc/haproxy/errorfiles/500.http errorfile 502 /etc/haproxy/errorfiles/502.http errorfile 503 /etc/haproxy/errorfiles/503.http errorfile 504 /etc/haproxy/errorfiles/504.http
|