Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
14
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@imp954sti

さくらVPSにtomcatをインストールする

1.JDKのインストール

インストール
$yum install java-1.7.0-openjdk-devel.x86_64

パスの設定
$vi /etc/profile

最終行に追加

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51.x86_64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

設定を反映する
$source /etc/profile

2.tomcatのインストール

インストール

$cd /usr/local/tmp
wget http://ftp.tsukuba.wide.ad.jp/software/apache/tomcat/tomcat-7/v7.0.50/bin/apache-tomcat-7.0.50.tar.gz
tar -xvf apache-tomcat-7.0.50.tar.gz
mv ./apache-tomcat-7.0.50 /usr/local/tomcat

パスの設定
$vi /etc/profile

export TOMCAT_HOME=/usr/local/tomcat
export CATALINA_HOME=/usr/local/tomcat
export CLASSPATH=$CLASSPATH:$CATALINA_HOME/common/lib

設定を反映する
$source /etc/profile

3.接続確認

http://IPアドレス:8080/
に接続してtomcatのページが表示されればOK

ファイヤーウォールの設定で8080ポートに接続できない場合
curl http://localhost:8080/
でも確認できるっぽい。

4.自動起動設定

tomcat用の環境設定ファイルを作る
$vi /etc/profile.d/tomcat.sh

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51.x86_64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
export TOMCAT_HOME=/usr/local/tomcat
export CATALINA_HOME=/usr/local/tomcat
export CLASSPATH=$CLASSPATH:$CATALINA_HOME/common/lib

1と2で/etc/profileに記述したexport部分要らなくなる?

起動シェル作成
$vi /etc/rc.d/init.d/tomcat

#!/bin/bash
#
# Startup script for the tomcat
#
# chkconfig: 345 80 15
# description: Tomcat is a Servlet+JSP Engine.

# Source function library.
. /etc/rc.d/init.d/functions
source /etc/profile.d/tomcat.sh

start(){
    if [ -z $(/sbin/pidof java) ]; then
        echo "Starting tomcat"
        /usr/local/tomcat/bin/startup.sh
        touch /var/lock/subsys/tomcat
    else
        echo "tomcat allready running"
    fi
}

stop(){
    if [ ! -z $(/sbin/pidof java) ]; then
        echo "Shutting down tomcat"
        /usr/local/tomcat/bin/shutdown.sh
        until [ -z $(/sbin/pidof java) ]; do :; done
        rm -f /var/lock/subsys/tomcat
    else
        echo "tomcat not running"
    fi
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    status)
        /usr/local/tomcat/bin/catalina.sh version
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
esac

exit 0

実行権限追加
$chmod +x /etc/rc.d/init.d/tomcat

自動起動設定
$chkconfig --add tomcat
$chkconfig tomact on

tomcat起動
$/etc/rc.d/init.d/tomcat start

参考サイト

http://centossrv.com/tomcat6.shtml
http://javatechnology.net/service/vps-java-tomcat/

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
14
Help us understand the problem. What are the problem?