HAProxyを導入
クライアントiOSアプリのバックエンドサーバーで時々ロードバランサーが機能していない時があり、これを契機にkeepalivedとipvsadmとHAProxyによる高可用性クラスタを組むことになりました。
ただ、データセンター側の制約でHAIP(VIP)が構成出来ないことが発覚して、急きょHAProxyとDNSラウンドロビンでAppサーバーにラウンドロビンすることになりました。以下、設定メモです。
HAProxyのインストール
1 |
sudo yum install -y haproxy |
/etc/haproxy/haproxy.cfgの構成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
global chroot /var/lib/haproxy daemon log 127.0.0.1 daemon pidfile /var/run/haproxy.pid maxconn 4192 user haproxy group haproxy tune.ssl.default-dh-param 2048 defaults mode http log global option httplog option dontlognull option http-server-close option forwardfor option redispatch retries 3 timeout http-request 20s timeout queue 10m timeout connect 30s timeout client 10m timeout server 10m timeout http-keep-alive 30s timeout check 40s maxconn 3000 frontend ssl_proxy mode http maxconn 1024 timeout client 40s bind *:443 ssl crt /etc/haproxy/server.pem http-request set-header X-Forwarded-Host %[req.hdr(host)] option forwardfor use_backend default_ssl frontend multiple_domains mode http maxconn 1024 timeout client 40s bind *:80 bind *:8008 bind *:8080 acl is_v1 hdr_beg(host) -i *****.com acl is_v2 hdr_beg(host) -i *****.com acl is_v3 hdr_beg(host) -i *****.com acl is_v4 hdr_beg(host) -i *****.com redirect prefix http://*****.com code 301 if { hdr(host) -i *****.com } use_backend virtual_web if is_v1 use_backend virtual_api if is_v2 use_backend virtual_admin if is_v3 use_backend virtual_q if is_v4 frontend http-in bind *:8088 stats enable stats auth admin:******** stats hide-version stats show-node stats refresh 60s stats uri /haproxy?stats backend virtual_web mode http balance static-rr timeout connect 40s timeout server 40s timeout check 15s option httplog server default_web01 *****:80 check inter 5000 fall 2 backend default_ssl mode http balance static-rr stick-table type ip size 200k expire 60m stick on src timeout connect 40s timeout server 40s timeout check 15s option httplog server default_ssl01 ***** check inter 5000 fall 2 server default_ssl02 ***** check inter 5000 fall 2 server default_ssl03 ***** check inter 5000 fall 2 backend virtual_api mode http balance static-rr timeout connect 40s timeout server 40s timeout check 15s option httplog server appapi01 *****:3000 check inter 5000 fall 2 server appapi02 *****:3000 check inter 5000 fall 2 server appapi03 *****:3000 check inter 5000 fall 2 backend virtual_admin mode http balance static-rr timeout connect 40s timeout server 40s timeout check 15s option httplog server appadmin01 *****:8080 check inter 5000 fall 2 server appadmin02 *****:8080 check inter 5000 fall 2 server appadmin03 *****:8080 check inter 5000 fall 2 backend virtual_q mode http balance static-rr timeout connect 40s timeout server 40s timeout check 15s option httplog server appq01 *****:443 check inter 5000 fall 2 server appq02 *****:443 check inter 5000 fall 2 server appq03 *****:443 check inter 5000 fall 2 |
追記
デバッグ用にフェイルオーバーする時間が長くなっているので、こちら短くするように調整です。
HAProxyの設定に関してブログに書きました。