有没有一种方法可以在不重新启动haproxy的情况下向haproxy添加更多后端服务器?


17

我们希望能够按需添加更多后端服务器。现在,我没有一种无需重启haproxy就可以将更多后端服务器添加到配置文件中的方法。

Answers:


15

我尚未测试此特定用例,但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
}

1
我已经尝试过了,但是发现它可以清除我的柜台。也许我是在以错误的方式做某事,还是预期的行为?
LeandroLópez,2010年

6

从手册中:

> 1.6)帮助流程管理

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)

1

另外,根据您的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。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.