HAproxy 既可以实现高可用又可以实现负载均衡
`1.yum install -y haproxy`
2.设置haproxy 的日志环境
a.vim /etc/sysconfig/rsyslog 修改此文件
SYSLOGD_OPTIONS="-c 2 -r"
b.vim /etc/rsyslog.conf 编辑此文件,在62行添加如下代码
local2.* /var/log/haproxy.log
3. 编写haproxy.cfg配置文件
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 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
listen stats
mode http
bind *:1080 绑定检测的端口号
stats enable
stats hide-version
stats uri /haproxyadmin?stats
stats realm Haproxy\ Statistics
stats auth admin:admin //设置登录的密码
stats admin if TRUE
frontend web
bind *:80 绑定端口号
log global
option httpclose
option logasap
option dontlognull
capture request header Host len 20
capture request header Referer len 60
default_backend servers
backend servers 设置节点服务器
balance roundrobin //负载均衡的算法
server web1 192.168.9.129:80 check maxconn 4000
server web2 192.168.9.134:80 check maxconn 3000
HAproxy 个人总结
最新推荐文章于 2025-02-10 22:30:00 发布