[root@localhost haproxy]# cat haproxy.cfg
global
log 127.0.0.1 local3 info
user nobody
group nobody
daemon
nbproc 1
pidfile /run/haproxy.pid
defaults
log global #日志使用全局配置
mode http #定义模式为 七层负载
maxconn 2048 #最大连接数 (优先级中)
retries 3 #健康检查 3次链接失败默认服务不可用
option redispatch #服务不可用后的操作 重定向到其它服务器
timeout connect 5000 #定义haproxy将客户端请求转发到后端服务器,所等待超时时长
timeout client 50000 #定义haproxy作为客户,跟后端服务器之间 空前时间 的超时时间
timeout server 50000 #定义haproxy作为服务器,和用户之间的超时时间
option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接
stats uri /admin?stats #设置proxy可视化界面的uri
stats realm Private lands #用户访问可视化界面的时候提示的内容
stats auth admin:123456 #设置可视化界面的用户密码
stats hide-version #隐藏ha的版本号
frontend http-in #负载均衡核心配置,配置相应的负载均衡策略
bind 0.0.0.0:80
mode http
log global
option httplog
option httpclose #关闭访问时间太长,没有发送信息的链接
acl html url_reg -i \.html$ #如果客户访问以.html结尾的url
use_backend html-server #就将请求发送给后端服务器处理
default_backend html-server
backend html-server
mode http
balance roundrobin
option httpchk /index.html
cookie SERVERID insert indirect nocache
#对后端服务器的健康检查状态间隔时间为2000ms,连续2次健康检查,则成功;连续5次失败,则失败;
server html-A 192.168.211.160:80 weight 1 cookie 3 check inter 2000 rise 2 fall 5
server html-B 192.168.211.161:80 weight 1 cookie 3 check inter 2000 rise 2 fall 5
HAproxy相关配置文件示例~
最新推荐文章于 2024-08-05 12:04:08 发布