2009年12月1日火曜日

[メモ] TomcatインストルからApacheの連携まで

CentoOSにTomcatをインストしてApacheと連携する。


1. jdkのインストル


[root@srv ~]# wget -O jdk-6u17-linux-i586.bin http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jdk-6u17-linux-i586.bin?BundledLineItemUUID=Bp9IBe.pnKQAAAEl_DsdbUiv&OrderID=sxRIBe.pyHUAAAEl7TsdbUiv&ProductID=lBFIBe.oSOMAAAEkGehn5G0y&FileName=/jdk-6u17-linux-i586.bin
......

100%[======================================================================================================================================>] 81,792,634 538.62K/s ETA 00:00

14:40:36 (761.59 KB/s) - `jdk-6u17-linux-i586.bin' を保存しました [81792634/81792634]
....

[root@srv ~]# chmod 755 jdk-6u17-linux-i586.bin
[root@srv ~]# ./jdk-6u17-linux-i586.bin
....
Press Enter to continue.....


Done.

[root@srv ~]# mv jdk1.6.0_17/ /usr/lib/
[root@srv etc]# vi /etc/bashrc
export JAVA_HOME=/usr/lib/jdk1.6.0_17 <- 最後の行に追加




2. Tomcatのインストル


[root@srv ~]# wget http://www.meisei-u.ac.jp/mirror/apache/dist/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.zip
......

100%[======================================================================================================================================>] 6,379,115 400.23K/s ETA 00:00

14:56:15 (332.39 KB/s) - `apache-tomcat-6.0.20.zip' を保存しました [6379115/6379115]

[root@srv ~]# unzip -d /usr/local/ apache-tomcat-6.0.20.zip
[root@srv bin]# chmod +x /usr/local/apache-tomcat-6.0.20/bin/*.sh
[root@srv local]# ln -s /usr/local/apache-tomcat-6.0.20/ /usr/local/tomcat

[root@srv ~]# vi /etc/init.d/tomcat
#!/bin/sh
#
# Startup script for Apache Tomcat 6
#
# chkconfig: 2345 85 15
# description: Apache Tomcat Java Servlets and JSP server
# processname: tomcat
# pidfile: /var/run/tomcat.pid
# config: /usr/local/tomcat/conf/server.xml

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

CATALINA_HOME=/usr/local/tomcat
TOMCAT_SCRIPT=$CATALINA_HOME/bin/catalina.sh
TOMCAT_USER=root

[ -f $TOMCAT_SCRIPT ] || exit 0

# See how we were called.
case "$1" in
start)
# Start daemons.
if [ -f /var/lock/subsys/tomcat ] ; then
echo "Tomcat already started!"
exit 1
fi
echo -n "Starting Tomcat: "
su -s /bin/bash - $TOMCAT_USER -c "$TOMCAT_SCRIPT start"
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat
;;
stop)
# Stop daemons.
if [ ! -f /var/lock/subsys/tomcat ] ; then
echo "Tomcat already stopped!"
exit 1
fi
echo -n "Shutting down Tomcat: "
$TOMCAT_SCRIPT stop
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/tomcat
;;
status)
status tomcat
exit $?
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $TOMCAT_PROG {start|stop|status|restart}"
exit 1
esac

exit 0


[root@srv ~]# chmod +x /etc/init.d/tomcat



3. Apache Tomcat Connector の設定

[root@srv modules]# cd /etc/httpd/modules/
[root@srv modules]# wget http://ftp.kddilabs.jp/infosystems/apache/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.28/i586/mod_jk-1.2.28-httpd-2.0.X.so
.....

100%[======================================================================================================================================>] 690,348 735.73K/s

15:06:02 (733.98 KB/s) - `mod_jk-1.2.28-httpd-2.0.X.so' を保存しました [690348/690348]

[root@srv modules]# chmod +x /etc/httpd/modules/mod_jk-1.2.28-httpd-2.0.X.so


- 「workers.properties」作成
[root@srv conf]# vi /etc/httpd/conf/workers.properties
# Define 1 real worker using ajp13
worker.list=babukumaWorker
# Set properties for worker1 (ajp13)
worker.
babukumaWorker.type=ajp13
worker.
babukumaWorker.host=localhost
worker.
babukumaWorker.port=8009

- 「httpd.conf」編集
[root@srv conf]# vi httpd.conf

LoadModule jk_module modules/mod_jk-1.2.28-httpd-2.0.X.so

# AJP
JkWorkersFile /etc/httpd/conf/workers.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile /etc/httpd/logs/mod_jk.shm
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile /etc/httpd/logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# Send everything for context /examples to worker named worker1 (ajp13)
JkMount /examples* babukumaWorker