Load-Balancing

有沒有辦法在不重新啟動 haproxy 的情況下向 haproxy 添加更多後端伺服器?

  • December 22, 2017

我們希望能夠按需添加更多後端伺服器。現在我看不到在不重新啟動 haproxy 的情況下將更多後端伺服器添加到配置文件的方法。

我還沒有測試過這個特定的案例,但 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
}

引用自:https://serverfault.com/questions/165883