インストール手順と必要な起動スクリプト、Javaオプション設定ファイルを備忘録として記載します。
環境
- OS:Amazon Linux 2014.03
- apache-tomcat:7.0.55
- java:jdk-7u67
手順
$ sudo yum group install "Development Tools"
$ cd /usr/local/src/
$ sudo wget sudo wget http://ftp.kddilabs.jp/infosystems/apache/tomcat/tomcat-7/v7.0.55/bin/apache-tomcat-7.0.55.tar.gz
$ sudo wget --no-check-certificate --no-cookies - --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.tar.gz
$ sudo tar zxvf ./jdk-7u67-linux-x64.tar.gz -C /usr/local/
$ cd /usr/local
$ sudo ln -s ./jdk1.7.0_67 ./java
$ /usr/local/java/bin/java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
$ sudo groupadd -g 53 tomcat
$ sudo useradd -u 53 -g 53 -s /sbin/nologin -d /var/lib/tomcat -m tomcat
$ cd /usr/local/src
$ tar zxvf ./apache-tomcat-7.0.55.tar.gz -C /usr/local/
$ cd /usr/local/
$ sudo ln -s ./apache-tomcat-7.0.55 ./tomcat
$ sudo tar zxvf ./commons-daemon-native.tar.gz
$ cd ./commons-daemon-1.0.15-native-src/unix/
$ sudo ./configure --with-java=/usr/local/java
$ sudo make
$ sudo mv jsvc /usr/local/tomcat/bin/
$ sudo vi /etc/init.d/jsvc
// 下記を参照
$ sudo vi /usr/local/tomcat/bin/setenv.sh
// 下記を参照
$ sudo chmod +x /etc/init.d/jsvc
$ sudo chkconfig --add jsvc
$ sudo chkconfig jsvc on
$ sudo chkconfig --list jsvc
jsvc 0:off 1:off 2:on 3:on 4:on 5:on 6:off
$ sudo chmod +x /usr/local/tomcat/bin/setenv.sh
$ sudo service jsvc start
Shutting down tomcat: [OK]
ファイル関連
/etc/init.d/jsvc
#!/bin/bash
#
# chkconfig: - 80 20
# description: jsvc
. /etc/init.d/functions
JAVA_HOME=/usr/local/java
CATALINA_HOME=/usr/local/tomcat
DAEMON=$CATALINA_HOME/bin/jsvc
TOMCAT_USER=tomcat
TMP_DIR=/tmp
PIDFILE=/var/run/tomcat.pid
CATALINA_BASE=$CATALINA_HOME
LOCKFILE=/var/lock/subsys/tomcat
if [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
. "$CATALINA_HOME"/bin/setenv.sh
fi
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/tomcat-juli.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar
start(){
#
# Start Tomcat
#
echo -n "Starting tomcat: "
ulimit -n 8192
$DAEMON $JSVC_OPTS \
-user $TOMCAT_USER \
-home $JAVA_HOME \
-Dcatalina.home=$CATALINA_HOME \
-Dcatalina.base=$CATALINA_BASE \
-Djava.io.tmpdir=$TMP_DIR \
-wait 10 \
-pidfile $PIDFILE \
-outfile $CATALINA_HOME/logs/catalina.out \
-errfile '&1' \
$CATALINA_OPTS \
-cp $CLASSPATH \
org.apache.catalina.startup.Bootstrap
RETVAL=$?
if [ $RETVAL = 0 ]; then
echo_success
touch $LOCKFILE
else
echo_failure
fi
echo
}
stop(){
#
# Stop Tomcat
#
echo -n "Shutting down tomcat: "
$DAEMON \
-stop \
-pidfile $PIDFILE \
org.apache.catalina.startup.Bootstrap
RETVAL=$?
if [ $RETVAL = 0 ]; then
echo_success
rm -f $PIDFILE $LOCKFILE
else
echo_failure
fi
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status $DAEMON
RETVAL=$?
;;
*)
echo $"Usage: tomcat {start|stop|restart|status}"
exit 1
;;
esac
/usr/local/tomcat/bin/setenv.sh
#!/bin/sh
DATE=`date +'%Y%m%d-%H%M%s'`
CATALINA_OPTS="-server -XX:MaxPermSize=256m -XX:PermSize=256m -XX:SurvivorRatio=2 -Xmn256m -Xmx256m -Xms256m" //JVMのサイズは必要に応じて修正
CATALINA_OPTS="${CATALINA_OPTS} -XX:+PrintGCDetails -Xloggc:${CATALINA_BASE}/logs/gc.log.${DATE}"
CATALINA_OPTS="${CATALINA_OPTS} -Djava.security.egd=file:/dev/urandom" //この設定は検証環境の場合
export CATALINA_OPTS