Apache 2 と Tomcat 4 を mod_jk2 で接続してみる。

OS: Debian GNU/Linux Sarge


必要なパッケージのインストール


# apt-get install apache2
# apt-get install tomcat4
# apt-get install libapache2-mod-jk2

jk2.conf の設定

/etc/apache2/mods-enabled/jk2.conf の最下行をコメントアウト(uncomment)する。


# cat /etc/apache2/mods-enabled/jk2.conf
# To enable mod_jk2, customize workers2.properties* from
# /usr/share/doc/libapache2-mod-jk2/examples and copy it to
# /etc/apache2/workers2.properties. Then uncomment the following line:
JkSet config.file /etc/apache2/workers2.properties

workers2.properties の設定

workers2.properties のサンプルファイルが /usr/share/doc/libapache2-mod-jk2/examples/workers2.properties にある。
これを /etc/apache2/workers2.properties にコピーして設定ファイルとして使う。


# cp /usr/share/doc/libapache2-mod-jk2/examples/workers2.properties /etc/apache2/

次に /etc/apache2/workers2.properties の内容を修正する。
今回は # added by me :-) 以下の内容を追加しただけ。
正直、設定内容の意味はわかっていない:-P


# cat /etc/apache2/workers2.properties
[logger]
level=DEBUG
 
[config:]
file=${serverRoot}/conf/workers2.properties
debug=0
debugEnv=0
 
[uriMap:]
info=Maps the requests. Options: debug
debug=0
 
# Alternate file logger
#[logger.file:0]
#level=DEBUG
#file=${serverRoot}/logs/jk2.log
 
[shm:]
info=Scoreboard. Required for reconfiguration and status with multiprocess servers
file=${serverRoot}/logs/jk2.shm
size=1000000
debug=0
disabled=0
 
[workerEnv:]
info=Global server options
timing=1
debug=0
# Default Native Logger (apache2 or win32 )
# can be overriden to a file logger, useful
# when tracing win32 related issues
#logger=logger.file:0
 
[lb:lb]
info=Default load balancer.
debug=0
 
[lb:lb_1]
info=A second load balancer.
debug=0
 
[channel.socket:localhost:8009]
info=Ajp13 forwarding over socket
debug=0
tomcatId=localhost:8009
 
[channel.socket:localhost:8019]
info=A second tomcat instance.
debug=0
tomcatId=localhost:8019
lb_factor=1
group=lb
group=lb_1
disabled=0
 
[channel.un:/opt/33/work/jk2.socket]
info=A second channel connecting to localhost:8019 via unix socket
tomcatId=localhost:8019
lb_factor=1
debug=0
 
[channel.jni:jni]
info=The jni channel, used if tomcat is started inprocess
 
[status:]
info=Status worker, displays runtime informations
 
[vm:]
info=Parameters used to load a JVM in the server process
#JVM=C:\jdk\jre\bin\hotspot\jvm.dll
classpath=${TOMCAT_HOME}/bin/tomcat-jni.jar
classpath=${TOMCAT_HOME}/server/lib/commons-logging.jar
OPT=-Dtomcat.home=${TOMCAT_HOME}
OPT=-Dcatalina.home=${TOMCAT_HOME}
OPT=-Xmx128M
#OPT=-Djava.compiler=NONE
disabled=1
 
[worker.jni:onStartup]
info=Command to be executed by the VM on startup. This one will start tomcat.
class=org/apache/jk/apr/TomcatStarter
ARG=start
# For Tomcat 5 use the 'stard' for startup argument
# ARG=stard
disabled=1
stdout=${serverRoot}/logs/stdout.log
stderr=${serverRoot}/logs/stderr.log
 
[worker.jni:onShutdown]
info=Command to be executed by the VM on shutdown. This one will stop tomcat.
class=org/apache/jk/apr/TomcatStarter
ARG=stop
disabled=1
 
[uri:/jkstatus/*]
info=Display status information and checks the config file for changes.
group=status:
 
[uri:127.0.0.1:8003]
info=Example virtual host. Make sure myVirtualHost is in /etc/hosts to test it
alias=myVirtualHost:8003
 
[uri:127.0.0.1:8003/ex]
info=Example webapp in the virtual host. It'll go to lb_1 ( i.e. localhost:8019 )
context=/ex
group=lb_1
 
[uri:/examples]
info=Example webapp in the default context.
context=/examples
debug=0
 
[uri:/examples1/*]
info=A second webapp, this time going to the second tomcat only.
group=lb_1
debug=0
 
[uri:/examples/servlet/*]
info=Prefix mapping
 
[uri:/examples/*.jsp]
info=Extension mapping
 
[uri:/examples/*]
info=Map the whole webapp
 
[uri:/examples/servlet/HelloW]
info=Example with debug enabled.
debug=10
 
# added by me :-)
[uri:/hoge/*]
info=hoge hoge hoge hoge foo bar foo bar.
#context=/hoge
debug=0

Apache2 を再起動

Tomcat は普通に使っていて、ウェブアプリケーション /hoge も配備済みという前提。

Apache2 を再起動すると、いろいろたくさんメッセージが出てくる。
workers2.properties をちゃんと設定していないのがいけないのかもしれない。


# /etc/init.d/apache2 restart
Forcing reload of web server: Apache2
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done logger
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done config:
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done uriMap:
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done shm:
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done workerEnv:
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done lb:lb
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done lb:lb_1
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done channel.socket:localhost:8009
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done channel.socket:localhost:8019
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done channel.un:/opt/33/work/jk2.socket
[Tue Aug 28 22:23:24 2007] [error] env.createBean2(): Factory error creating channel.jni:jni ( channel.jni, jni)
[Tue Aug 28 22:23:24 2007] [error] config.update(): Can't create channel.jni:jni
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done status:
[Tue Aug 28 22:23:24 2007] [error] env.createBean2(): Factory error creating vm: ( vm, )
[Tue Aug 28 22:23:24 2007] [error] config.update(): Can't create vm:
[Tue Aug 28 22:23:24 2007] [error] env.createBean2(): Factory error creating worker.jni:onStartup ( worker.jni, onStartup)
[Tue Aug 28 22:23:24 2007] [error] config.update(): Can't create worker.jni:onStartup
[Tue Aug 28 22:23:24 2007] [error] env.createBean2(): Factory error creating worker.jni:onShutdown ( worker.jni, onShutdown)
[Tue Aug 28 22:23:24 2007] [error] config.update(): Can't create worker.jni:onShutdown
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done uri:/jkstatus/*
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done uri:127.0.0.1:8003
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done uri:127.0.0.1:8003/ex
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done uri:/examples
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done uri:/examples1/*
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done uri:/examples/servlet/*
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done uri:/examples/*.jsp
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done uri:/examples/*
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done uri:/examples/servlet/HelloW
[Tue Aug 28 22:23:24 2007] [notice] config.update(): done uri:/hoge/*

それでも、http://localhost/hoge/ に http アクセスすると http://localhost:8180/hoge/ の内容を返してくれるようになった。
とりあえず、mod_jk2 設定完了。

Ref. ちろきんぐす -Debian/Tomcat4とApache2の連携

tags: zlashdot Linux Apache Debian Tomcat

Posted by NI-Lab. (@nilab)