16
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2014-02-15

##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/

16
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?