web-dev-qa-db-ja.com

haproxyを再起動せずにバックエンドサーバーをhaproxyに追加する方法はありますか?

オンデマンドでバックエンドサーバーを追加できるようにしたいと考えています。現時点では、haproxyを再起動せずに構成ファイルにバックエンドサーバーを追加する方法がわかりません。

17
Jan Deinhard

この特定の使用例はテストしていませんが、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を開始および停止するinitスクリプトがある場合、おそらく次のような関数でreload引数をサポートしています。

haproxy_reload()
{
    $HAPROXY -f "$CONFIG" -p $PIDFILE -D $EXTRAOPTS -sf $(cat $PIDFILE) \
        || return 2
    return 0
}
16
Kyle Brandt

マニュアルから:

> 1.6)プロセス管理の支援

Haproxyはpidfileの概念をサポートするようになりました。 '-p'コマンドライン引数、または 'pidfile'グローバルオプションの後にファイル名が続く場合、このファイルは削除され、すべての子のpidが1行に1つずつ入力されます(デーモンモードのみ)。このファイルは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)
6

また、HAプロキシのバージョンによっては、このページのhaproxy.comで説明されているHA-Proxy Dynamic APIを検討することをお勧めします。 https://www.haproxy.com/blog/dynamic-scaling-for -microservices-with-runtime-api /

HA-Proxy Dynamic APIはEnterpriseバージョンに付属しています。

通常の方法でサーバーを即座に追加/削除したい場合、またはプロジェクトがそのようなユースケースを示唆している場合は、HA-Proxy Dynamic APIを検討する必要があります。

2
Mike Mountrakis