
私は、HAProxy と Apache の間に Varnish を入れることを考えています。これは機能していますが、間に Varnish を入れると、HAProxy が Varnish を監視します。Apache がダウンすると、他の Apache にフェイルオーバーされません。
この問題を克服する HAProxy の設定はありますか?
答え1
VarnishがHAproxyとApacheの間にある場合は、Varnishに次のことをさせるだけで済みます。負荷分散ただし、HAproxy が提供するオプションほど堅牢ではありません。
より良い方法は、HAproxy が静的コンテンツを Varnish に送信し、残りをバックエンド サーバーに直接送信することです。
Haproxy.comには、その方法についての非常に良い記事があります。ここ。
HAproxyでVarnishの状態をチェックしたい場合はそしてApache を同時に(同じホスト上に)実行する場合、2 つのオプションがあります。
HAProxy でダミーのバックエンド/サーバーを設定し、Apache をチェックして、対応する Varnish サーバーがダミーを追跡するようにします。
frontend HTTP-IN mode http default_backend Varnishes # All traffic goes here backend Varnishes mode http balance roundrobin server Varnish-1 1.1.1.1:80 track Apache-1/Apache-1 server Varnish-2 2.2.2.2:80 track Apache-2/Apache-2 # No traffic ever goes here # Just used for taking servers out of rotation in 'backend Varnishes' backend Apache-1 server Apache-1 1.1.1.1:8080 check backend Apache-2 server Apache-2 2.2.2.2:8080 check
Varnish に、Apache のステータスに一致するヘルス チェック結果 (Apache が起動している場合は OK、それ以外の場合は FAILED) を返すようにします。
ワニス.vcl
backend default { .host = "127.0.0.1"; .port = "8080"; } # Health Check if (req.url == "/varnishcheck") { if (req.backend.healthy) { return(synth(751, "OK!")); } else { return(synth(752, "FAILED!")); } } sub vcl_synth { # Health Checks if (resp.status == 751) { set resp.status = 200; return (deliver); } if (resp.status == 752) { set resp.status = 503; return (deliver); } }
ハプロキシ.cfg
frontend HTTP-IN mode http default_backend Varnishes backend Varnishes mode http balance roundrobin option httpchk HEAD /varnishcheck http-check expect status 200 server Varnish-1 1.1.1.1:80 check server Varnish-2 2.2.2.2:80 check