标签:nec forward sock 位置 turn global cal disable oba
yum install haproxy -y
yum install socat -y
global
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
# 这里很重要,level为admin,否则使用socat时会提示权限拒绝
stats socket /var/lib/haproxy/stats mode 600 level admin
defaults
mode tcp
log global
option dontlognull
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
frontend tcp
bind 0.0.0.0:6379 #发起http请求80端口,会被转发到设置的ip及端口
default_backend app
backend app
balance roundrobin
server redis1 10.10.116.206:6379 check
server redis2 10.10.48.62:6379 check
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
listen status
bind *:9090
stats enable
stats hide-version
#stats scope . //限定报告的区段,可以使用"listen","frontend","backend"区段的名称,"."表示当前区段
stats uri /haproxy?stats //修改url
stats realm "HAProxy statistics" //提示信息
stats auth admin:123445 //启用认证
#stats admin if TRUE //启用管理员模式,可以控制后端服务器
vim /etc/rsyslog.conf
# 下面2行的注释去掉
$ModLoad imudp
$UDPServerRun 514
# 新增加下面这行,位置可以自己定义 但目录一定要存在和有权限写入
local2.* /data/logs/haproxy.log
# 重启rsyslog
/etc/init.d/rsyslog restart
# 查看日志:
tail -f /data/logs/haproxy.log
# 查看haproxy的info 信息:
echo "show info" | socat stdio /var/lib/haproxy/stats
# 查看haproxy 的帮助信息:
echo "help" | socat stdio /var/lib/haproxy/stats
# 关闭app组内的redis1 服务器:
echo "disable server app/redis1" | socat stdio /var/lib/haproxy/stats
# 开启app组内的redis1 服务器:
echo "enable server app/redis1" | socat stdio /var/lib/haproxy/stats
# 查看status 信息:
echo "show stat " | socat stdio /var/lib/haproxy/stats
标签:nec forward sock 位置 turn global cal disable oba
原文地址:https://www.cnblogs.com/zhenxing06/p/12840258.html