Answers:
我尚未测试此特定用例,但haproxy确实支持“热重载”:
2.4.1) Hot reconfiguration
--------------------------
The '-st' and '-sf' command line options are used to inform previously running
processes that a configuration is being reloaded. They will receive the SIGTTOU
signal to ask them to temporarily stop listening to the ports so that the new
process can grab them. If anything wrong happens, the new process will send
them a SIGTTIN to tell them to re-listen to the ports and continue their normal
work. Otherwise, it will either ask them to finish (-sf) their work then softly
exit, or immediately terminate (-st), breaking existing sessions. A typical use
of this allows a configuration reload without service interruption :
# haproxy -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)
如果您有一个用于启动和停止haproxy的初始化脚本,则它可能reload
通过以下函数支持该参数:
haproxy_reload()
{
$HAPROXY -f "$CONFIG" -p $PIDFILE -D $EXTRAOPTS -sf $(cat $PIDFILE) \
|| return 2
return 0
}
从手册中:
Haproxy现在支持pidfile的概念。如果在命令行后跟-p命令行参数或pidfile全局选项,则将删除该文件,然后填充所有子代的pid,每行一个(仅在守护程序模式下)。该文件不在chroot中,该文件允许使用只读chroot。它由启动过程的用户所有,并将具有权限0644。
global
daemon
quiet
nbproc 2
pidfile /var/run/haproxy-private.pid
# to stop only those processes among others :
# kill $(</var/run/haproxy-private.pid)
# to reload a new configuration with minimal service impact and without
# breaking existing sessions :
# haproxy -f haproxy.cfg -p /var/run/haproxy-private.pid -sf $(</var/run/haproxy-private.pid)
另外,根据您的HA-proxy版本,您可能要考虑haproxy.com在此页面中描述的HA-Proxy Dynamic API:https ://www.haproxy.com/blog/dynamic-scaling-for-microservices-with -runtime-api /
HA-Proxy Dynamic API随企业版一起提供。
如果您想按惯例快速添加/删除服务器,或者您的项目暗含了这种用例,则应考虑使用HA-Proxy动态API。