Haproxy安装及设置
1、haproxy安装
sudo apt-get install haproxy
2、haproxy参数
mode http/tcp #指定负载协议类型
option #配置选项
server #定义后端real server
#注意:option后面加httpchk,smtpchk,mysql-check,pgsql-check,ssl-hello-chk方法,可用于实现更多应用层检测功能
check #对指定real进行健康状态检查,默认不开启
addr IP #可指定的健康状态监测IP
port num #指定的健康状态监测端口
inter num #健康状态检查间隔时间,默认2000 ms
fall num #后端服务器失效检查次数,默认为3
rise num #后端服务器从下线恢复检查次数,默认为2
weight #默认为1,最大值为256,0表示不参与负载均衡
backup #将后端服务器标记为备份状态
disabled #将后端服务器标记为不可用状态
redirect prefix http://www.magedu.net/ #将请求临时重定向至其它URL,只适用于http模式
maxconn <maxconn>:当前后端server的最大并发连接数
backlog <backlog>:当server的连接数达到上限后的后援队列长度
3、haproxy设置(/etc/haproxy/haproxy.cfg)
global //一般不设置
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
......................................................................
defaults //默认设置
log global
mode http
option httplog
option dontlognull
maxconn 2000 //最大连接数
timeout connect 5000 //连接超时时间ms
timeout client 5000s //客户端最长等待时间s
timeout server 5000s //后端服务器最长等待时间s
timeout check 5s //对后端服务器的默认检测超时时间s
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
frontend magedu-test //前端servername,类似于Nginx的一个虚拟主机 server和LVS服务集群。
bind :10000 //绑定端口
mode tcp //模式
use_backend magedu-test-nodes //指定后端服务器组
#default_backend magedu-test-nodes //指定后端服务器组
backend magedu-test-nodes //后端服务器组,等于nginx的upstream和LVS中的RS服务器
mode tcp //模式
balance roundrobin //负载均衡的算法为rr
server s1 IP1:PORT weight 1 check inter 5000 fall 3 rise 5 //服务器组设置 (权重为1 每5000ms检查一次后端服务器 失效检查3次 从下线恢复检查5次)
server s2 IP2:PORT weight 2 check inter 5000 fall 3 rise 5 //服务器组设置
listen admin_status //将frontend和backend合并在一起配置,相对于frontend和backend配置更简洁,生产常用
bind 0.0.0.0:8888 //监视端口
mode http //模式
log 127.0.0.1 local3 err //日志
stats refresh 5s //刷新间隔
stats uri /haproxy_stats //UI查看地址
stats realm itnihao\ welcome
stats auth admin:admin //用户名密码
stats hide-version //隐藏版本
stats admin if TRUE
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现