LVSの設定とパフォーマンス
前回の前編では、
今回の後編では、
最後に、
IPVSの構築
OpenBlockS 600でipvsadmコマンドをオプションなしで実行してください。図1のとおり表示されるはずです。
obs600# ipvsadmIP Virtual Server version 1.2.1 (size 4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConnInActConn
もし、
obs600# ipvsadmFATAL: Module ip_vs not found. Can t initialize ipvs: Protocol not availableAre you sure that IP Virtual Server is built inthe kernel or as module?
obs600# depmod -a
LVS-NAT
それではIPVSの設定をしていきましょう。これは、
仮想サーバテーブルの消去
まだIPVSの設定はしていませんが、
obs600# ipvsadm -C
仮想サービスの追加
仮想サービスを図5のとおり追加します。オプション-A は、
obs600# ipvsadm -A -t 192.168.253.120:80 -s rr
オプション-tは、
オプション-sで、
スケジューリングアルゴリズムは全部で10個あります。OpenBlockS 600のカーネルでは、
仮想サービスへのリアルサーバの追加
仮想サービスへリアルサーバを追加します
obs600# ipvsadm -a -t 192.168.253.120:80 -r 172.16.14.121:80 -m obs600# ipvsadm -a -t 192.168.253.120:80 -r 172.16.14.122:80 -m obs600# ipvsadm -a -t 192.168.253.120:80 -r 172.16.14.123:80 -m
オプション-aは、
パケットフォワーディング方法は、
仮想サーバテーブルの表示
IPVSの設定が図7のとおりになっているか確認してください。
obs600# ipvsadm IP Virtual Server version 1.2.1 (size 4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.253.120:www rr -> 172.16.14.123:www Masq 1 0 0 -> 172.16.14.122:www Masq 1 0 0 -> 172.16.14.121:www Masq 1 0 0
接続の確認
クライアントからcurlコマンドで仮想IPアドレスに接続してみてください。仮想サーバから図8のように応答があれば成功です。
client$ curl http://192.168.253.120/ realserver3 client$ curl http://192.168.253.120/ realserver2 client$ curl http://192.168.253.120/ realserver1
ここでは、
リアルサーバがダウンした場合
ところで、
client$ curl http://192.168.253.120/ curl: (7) couldn t connect to host client$ curl http://192.168.253.120/ realserver2 client$ curl http://192.168.253.120/ realserver1
リアルサーバの重みを0にする
そのような場合に対処するために、
obs600# ipvsadm -e -t 192.168.253.120:80 -r 172.16.14.123:80 -m -w 0 obs600# ipvsadm IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.253.120:www rr -> 172.16.14.123:www Masq 0 0 0 -> 172.16.14.122:www Masq 1 0 0
curlコマンドでの接続結果は、
client$ curl http://192.168.253.120/ realserver2 client$ curl http://192.168.253.120/ realserver1 client$ curl http://192.168.253.120/ realserver2
リアルサーバが復旧した場合
それでは、
リアルサーバの重みを1にする
仮想サービス中のリアルサーバrealserver3を図12のとおり編集してみましょう。リアルサーバrealserver3の重みを1にしました。
obs600# ipvsadm -e -t 192.168.253.120:80 -r 172.16.14.123:80 -m -w 1 obs600# ipvsadm IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.253.120:www rr -> 172.16.14.123:www Masq 1 0 0 -> 172.16.14.122:www Masq 1 0 0
curlコマンドでの接続結果は図8のようになり、
Keepalived
ここまで、
/etc/keepalived/keepalived.conf
OpenBlockS 600のKeepalivedの設定ファイル/etc/
virtual_server 192.168.253.120 80 {
delay_loop 6
lvs_sched rr
lvs_method NAT
protocol TCP
real_server 172.16.14.121 80 {
inhibit_on_failure
HTTP_GET {
url {
path /index.html
status_code 200
}
}
}
real_server 172.16.14.122 80 {
inhibit_on_failure
HTTP_GET {
url {
path /index.html
status_code 200
}
}
}
real_server 172.16.14.123 80 {
inhibit_on_failure
HTTP_GET {
url {
path /index.html
status_code 200
}
}
}
}
リスト1にはLVSコンフィグレーションが記述してあります。
virtual_
先のIPVSの設定に対応して、
real_
Keepalivedの起動
仮想サーバテーブルの消去
KeepalivedがIPVSの設定をするので、
Keepalivedの起動
図13のとおり、
obs600# /etc/init.d/keepalived start Starting keepalived: keepalived.
仮想サーバテーブルの表示
IPVSの設定の確認をすると、
接続の確認
クライアントからcurlコマンドで仮想IPアドレスに接続してみてください。仮想サーバから、
うまく動作しない場合、
リアルサーバがダウンした場合
さて、
curlコマンドの実行結果のうちには、
ipvsadmコマンドを実行して、
リアルサーバが復旧した場合
それでは、
curlコマンドでの接続結果は、
ipvsadmコマンドを実行して、
ベンチマーク
Webサーバの負荷分散ができるようになったので、
同時リクエスト数が多い場合
クライアントから仮想IPアドレスに対してabコマンドを実行します。図14にabコマンドの実行結果を示しました。
client$ ab -c 1000 -n 1000 http://192.168.253.120/ This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.253.120 (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache/2.2.15 Server Hostname: 192.168.253.120 Server Port: 80 Document Path: / Document Length: 12 bytes Concurrency Level: 1000 Time taken for tests: 0.626 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 277207 bytes HTML transferred: 12000 bytes Requests per second: 1597.64 [#/sec] (mean) Time per request: 625.924 [ms] (mean) Time per request: 0.626 [ms] (mean, across all concurrent requests) Transfer rate: 432.50 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 18 9.7 14 46 Processing: 20 135 79.1 127 319 Waiting: 20 134 78.9 127 319 Total: 32 153 86.5 142 363 Percentage of the requests served within a certain time (ms) 50% 142 66% 155 75% 218 80% 242 90% 293 95% 329 98% 348 99% 355 100% 363 (longest request)
abコマンドのオプションには、
得られた結果のうち、
LVS-NAT | [#/sec] |
---|---|
有 | 1605. |
無 | 992. |
LVS-NATを使用すると、
同時リクエスト数が少ない場合
同じ条件で、
LVS-NAT | [#/sec] |
---|---|
有 | 2183. |
無 | 4164. |
LVS-NATの処理がボトルネックとなっているものの、
ロードバランサ編:おわりに
OpenBlockS 600とオープンソースソフトウェアを組み合わせると、
ここでは、
参考ページ
- The Linux Virtual Server Project
- URL:http://
www. linuxvirtualserver. org/ - IPVS Software
- URL:http://
www. linuxvirtualserver. org/ software/ ipvs. html - Keepalived
- URL:http://
www. keepalived. org/ - こんなに簡単! Linuxでロードバランサ
(1) - URL:http://
dsas. blog. klab. org/ archives/ 50664843. html - こんなに簡単! Linuxでロードバランサ
(2) - URL:http://
dsas. blog. klab. org/ archives/ 50665382. html - ab - Apache HTTP server benchmarking tool
- URL:http://
httpd. apache. org/ docs/ 2. 2/ programs/ ab. html