2008/5/11 12:37
poundによる負荷分散 パソコン・インターネット
apache2とlighttpdを併用しながらpoundによる分散を行った。
以下作業メモ。
--------
http://www.lighttpd.net/
http://www.kozupon.com/lighttpd/
http://www.cyberciti.biz/tips/howto-lighttpd-web-server-setting-up-virtual-hosting.html
http://d.hatena.ne.jp/rx7/20070306/p1
http://www.apsis.ch/pound/index_html
http://www.eitaro-saba.com/001/pound_1.html
http://tech.bayashi.jp/archives/entry/server/2007/001945.html
http://stderr.net/apache/rpaf/
http://www.drk7.jp/MT/archives/000573.html
--------
ユーザーを作成する。
adduser pound
vipwで/sbin/nologinへ変更する。deamonを参考にした。
変更後
pound:x:501:501:pound load balancer:/sbin:/sbin/nologin
--------
/usr/local/etc/pound.cfg
を作成し、以下を記述。
下記の設定では
/image/内 /skin/*.js /skin/pangya/内をlighttpdへ
それ以外をapache2へ分けている
User "pound"
Group "pound"
LogLevel 3
Alive 60
Daemon 0
LogFacility local1
ListenHTTP
Address 192.168.11.250
Port 80
Service
URL "/image/.*"
BackEnd
Address 127.0.0.1
Port 8001
End
End
Service
URL "/skin/pangya/.*"
BackEnd
Address 127.0.0.1
Port 8001
End
End
Service
URL "/skin/.*.js"
BackEnd
Address 127.0.0.1
Port 8001
End
End
Service
BackEnd
Address 127.0.0.1
Port 8000
End
End
End
--------
/etc/init.d/pound
を作成し、以下を記述
#! /bin/sh
# chkconfig: 2345 95 95
# description: pound
POUND_HOME=/usr/local
POUND_PID=/var/run
NAME=pound
DESC="pound"
set -e
#Remove write permission for others
umask 002
case "$1" in
start)
echo -n "Starting $DESC: "
/usr/sbin/pound -v -f $POUND_HOME/etc/pound.cfg -p $POUND_PID/pound.pid 2>&1 &
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
kill `cat $POUND_PID/pound.pid`
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
kill `cat $POUND_PID/pound.pid`
sleep 1s
/usr/sbin/pound -v -f $POUND_HOME/etc/pound.cfg -p $POUND_PID/pound.pid 2>&1 &
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart}" >&2
exit 1
;;
esac
--------
/etc/syslog.conf
に追加
# Pound
local1.* /var/log/pound
--------
/etc/logrotate.d/pound
を作成し、以下を記述
/var/log/pound {
missingok
notifempty
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/pound.pid 2>/dev/null` 2> /dev/null || true
endscript
}
--------
init.dの追加を行う。
/etc/init.d/pound にchkconfigとdescriptionの記述があれば簡単。
chkconfig --add pound
--------
mod_rpafを導入
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
で取得する。すでにインストール済みであればいいが、そうでない場合は
yum install httpd-devel
も必要。Makefileのapxsを変更する
#APXS2=$(shell which apxs2)
APXS2=$(shell which apxs)
ビルド&インストール
/etc/httpd/conf/httpd.confに以下を追加する
LoadModule rpaf_module modules/mod_rpaf-2.0.so
RPAFenable On
RPAFsethostname Off
RPAFproxy_ips 127.0.0.1
--------
mod_extforwardを導入
/etc/lighttpd/lighttpd.conf
の中を修正。
まずserver.modulesにmod_extforwardを追加。
次に設定を記述
## extforward
extforward.forwarder = ("127.0.0.1" => "trust")
--------
pukiwiki plus!ではPROXY制限をかけている。
そこでlib/proxy.cls.phpを変更する。
// array('HTTP_X_FORWARDED_FOR', 1,1), // プロキシサーバ経由の生IP
array('HTTP_X_FORWARDED_FOR', 0,1), // プロキシサーバ経由の生IP
以下作業メモ。
--------
http://www.lighttpd.net/
http://www.kozupon.com/lighttpd/
http://www.cyberciti.biz/tips/howto-lighttpd-web-server-setting-up-virtual-hosting.html
http://d.hatena.ne.jp/rx7/20070306/p1
http://www.apsis.ch/pound/index_html
http://www.eitaro-saba.com/001/pound_1.html
http://tech.bayashi.jp/archives/entry/server/2007/001945.html
http://stderr.net/apache/rpaf/
http://www.drk7.jp/MT/archives/000573.html
--------
ユーザーを作成する。
adduser pound
vipwで/sbin/nologinへ変更する。deamonを参考にした。
変更後
pound:x:501:501:pound load balancer:/sbin:/sbin/nologin
--------
/usr/local/etc/pound.cfg
を作成し、以下を記述。
下記の設定では
/image/内 /skin/*.js /skin/pangya/内をlighttpdへ
それ以外をapache2へ分けている
User "pound"
Group "pound"
LogLevel 3
Alive 60
Daemon 0
LogFacility local1
ListenHTTP
Address 192.168.11.250
Port 80
Service
URL "/image/.*"
BackEnd
Address 127.0.0.1
Port 8001
End
End
Service
URL "/skin/pangya/.*"
BackEnd
Address 127.0.0.1
Port 8001
End
End
Service
URL "/skin/.*.js"
BackEnd
Address 127.0.0.1
Port 8001
End
End
Service
BackEnd
Address 127.0.0.1
Port 8000
End
End
End
--------
/etc/init.d/pound
を作成し、以下を記述
#! /bin/sh
# chkconfig: 2345 95 95
# description: pound
POUND_HOME=/usr/local
POUND_PID=/var/run
NAME=pound
DESC="pound"
set -e
#Remove write permission for others
umask 002
case "$1" in
start)
echo -n "Starting $DESC: "
/usr/sbin/pound -v -f $POUND_HOME/etc/pound.cfg -p $POUND_PID/pound.pid 2>&1 &
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
kill `cat $POUND_PID/pound.pid`
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
kill `cat $POUND_PID/pound.pid`
sleep 1s
/usr/sbin/pound -v -f $POUND_HOME/etc/pound.cfg -p $POUND_PID/pound.pid 2>&1 &
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart}" >&2
exit 1
;;
esac
--------
/etc/syslog.conf
に追加
# Pound
local1.* /var/log/pound
--------
/etc/logrotate.d/pound
を作成し、以下を記述
/var/log/pound {
missingok
notifempty
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/pound.pid 2>/dev/null` 2> /dev/null || true
endscript
}
--------
init.dの追加を行う。
/etc/init.d/pound にchkconfigとdescriptionの記述があれば簡単。
chkconfig --add pound
--------
mod_rpafを導入
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
で取得する。すでにインストール済みであればいいが、そうでない場合は
yum install httpd-devel
も必要。Makefileのapxsを変更する
#APXS2=$(shell which apxs2)
APXS2=$(shell which apxs)
ビルド&インストール
/etc/httpd/conf/httpd.confに以下を追加する
LoadModule rpaf_module modules/mod_rpaf-2.0.so
RPAFenable On
RPAFsethostname Off
RPAFproxy_ips 127.0.0.1
--------
mod_extforwardを導入
/etc/lighttpd/lighttpd.conf
の中を修正。
まずserver.modulesにmod_extforwardを追加。
次に設定を記述
## extforward
extforward.forwarder = ("127.0.0.1" => "trust")
--------
pukiwiki plus!ではPROXY制限をかけている。
そこでlib/proxy.cls.phpを変更する。
// array('HTTP_X_FORWARDED_FOR', 1,1), // プロキシサーバ経由の生IP
array('HTTP_X_FORWARDED_FOR', 0,1), // プロキシサーバ経由の生IP
