Apacheのバランサの設定

やりたいこと。
htmlと画像ファイルを違うサーバに配置して、htmlはバランシングしたい。

構成
192.168.0.1 Windows
192.168.100.2 CentOS <-こいつにブラウザからアクセスする。
Apacheバージョン2.2.9

configureのオプション。
./configure --enable-so --enable-ssl --enable-rewrite --enable-proxy --enable-proxy-balancer

http.confの設定

ProxyRequests off
ProxyPass /test balancer://test timeout=2
<Proxy balancer://test>
 BalancerMember http://192.168.0.1 loadfactor=10
 BalancerMember http://192.168.100.2 loadfactor=10
</Proxy>

これでhttp://192.168.100.2/test/index.htmlってやると、
http://192.168.0.1/index.htmlもしくはhttp://192.168.100.2/index.htmlを参照する。
片方にしかないファイルについては、ある方だけを参照する。

http://192.168.100.2/test/index.html -> http://192.168.100.2/index.htmlを見に行くのは、ProxyPassの設定で、
http://192.168.0.1/index.htmlもしくはhttp://192.168.100.2/index.htmlを参照するのは、Proxyのバランサの設定。

じゃぁ、ルートディレクトリにあるファイルをバランシングしたいときは、ProxyPass / balancer://test timeout=2でいいの??

[Mon Oct 13 03:10:54 2008] [warn] proxy: No protocol handler was valid for the URL /index.html. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

らしい。

面倒くさくなったので、Apacheを入れ直す。

./configure --enable-so --enable-ssl --with-ssl=/usr/bin/openssl --enable-deflate=shared --enable-dav_fs=shared --enable-dav=shared --enable-setenvif=shared --enable-alias=shared --enable-auth_digest=shared --enable-authn_file=shared --enable-proxy=shared --enable-proxy_connect=shared --enable-proxy_ftp=shared --enable-proxy_http=shared --enable-proxy_ajp=shared --enable-proxy_balancer=shared --enable-cache=shared --enable-disk-cache=shared --enable-mem-cache=shared

なんかいろいろ適当に。
scharedにしてるからあとで削れるはず。

でもならなかった…
で、結論。
自分自身(のポート)では参照できないっぽい??
virtual hostでポート切って下のように割り振るとうまくいった。
きっと無限ループを防ぐためなんだろう。

<Proxy balancer://test>
        BalancerMember http://www.google.co.jp loadfactor=1
        BalancerMember http://192.168.100.2:8080 loadfactor=10
        BalancerMember http://192.168.0.1 loadfactor=5
</Proxy>

RewriteEngine on
RewriteRule ^/balancer_manager$ /balancer_manager [L]
RewriteRule ^/(.*\.(jpg|png|gif))$ - [L]
RewriteRule ^/(.*)$ balancer://test/$1 [P,L]

ということで、httpd-vhosts.confファイルにこんな感じ

<VirtualHost *:80>
ProxyRequests off
ProxyPass / balancer://test/
ProxyPassReverse / balancer://test/

<Proxy balancer://test>
        BalancerMember http://www.google.co.jp loadfactor=1
        BalancerMember http://192.168.100.2:8080 loadfactor=10
        BalancerMember http://192.168.0.1 loadfactor=5
</Proxy>

RewriteEngine on
RewriteRule ^/(.*\.(jpg|png|gif))$ - [L]
RewriteRule ^/(.*)$ balancer://test/$1 [P,L]

    ServerAdmin webmaster@dummy-host2.example.com
#    DocumentRoot "/usr/local/apache2/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
#    ErrorLog "logs/dummy-host2.example.com-error_log"
#    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>

<VirtualHost *:8080>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/local/apache2/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>

404エラーとかで繋がらなくなったらどうするんだろうね。
Apacheが死んでる場合にはアクセスしに行かないみたいだけど。
おそらく見に行くんだよな。404ステータスコード返しておしまいって感じだろうな。