Docs/linux基础/HaProxy服务摘除.md
2022-10-18 16:59:37 +08:00

24 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

haproxy在多进程模式下无法直接对后端服务器直接进行软下线当输入软下线的命令时haproxy依旧可以将用户的请求调度到后端已经下下的服务器上这是应为haproxy的socket文件的关系一个socket文件对应一个进程当haproxy处于多进程的模式下时就需要有多个socket文件并将其和进程进行绑定对后端服务器进行软下线时需要对所有的socket文件下达软下线的指令。
```
global
maxconn 100000
chroot /usr/local/haproxy
stats socket /var/lib/haproxy/haproxy.sock1 mode 600 level admin process 1 #分别使用不用的socket文件名并使用process选项将其于进程进行绑定
stats socket /var/lib/haproxy/haproxy.sock2 mode 600 level admin process 2
uid 99
gid 99
daemon
nbproc 2 #haproxy进程数为2所以需要创建出2个socket文件
cpu-map 1 0
cpu-map 2 1
pidfile /usr/local/haproxy/run/haproxy.pid
log 127.0.0.1 local3 info
```
下线
```
## 对后端的服务器进行下线时分别对每个socket文件发送软下线指令
echo "disable server php_server/web1" | socat stdio /var/lib/haproxy/haproxy.sock1
echo "disable server php_server/web1" | socat stdio /var/lib/haproxy/haproxy.sock2
```