Centos install tomcat7

標準

一、      安裝JDK

1、         卸載伺服器自帶的jdk

# java –version                         –查看java版本

# rpm –qa | grep jdk                –查看伺服器自帶的jdk

# yum -y remove xxxx                  –卸載伺服器自帶jdk(xxx為顯示的版本資訊)

# rpm –qa | grep gcj

# yum –y remove xxxx

#sudo find /usr/ -name *jdk  –check java home

2、         安裝JDK

# cd /usr/local/src                    –進入套裝軟體的存放路徑

# mv /usr/local/src/jdk-6u35-linux-x64.bin /usr/local/jdk-6u35-linux-x64.bin  –把套裝軟體剪切到安裝目錄

# cd /usr/local                         –進入安裝目錄

# chmod 755 jdk-6u35-linux-x64.bin      –給套裝軟體添加執行許可權

# ./ jdk-6u35-linux-x64.bin        –執行安裝

3、         配置java環境變數

# cp /etc/profile /etc/profile.bak            –備份系統設定檔

# vi /etc/profile                                      –編輯設定檔(在最後追加如下內容)

export JAVA_HOME=/usr/local/jdk1.6.0_35

export JRE_HOME=/usr/local/jdk1.6.0_35/jre/

export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

# source /etc/profile                                          –重新載入設定檔

# java –version                                                   –查看安裝的jdk版本資訊

二、      安裝Tomcat

1、安裝Tomcat

# cd /usr/local/src                                      –進入安裝包存放目錄

# tar zxvf apache-tomcat-7.0.35.tar.gz        –解壓

# mv apache-tomcat-7.0.35 /usr/local/apache-tomcat-7.0.35          –資料夾剪切到安裝目錄

# /usr/local/apache-tomcat-7.0.35/bin/startup.sh         –啟動

# /usr/local/apache-tomcat-7.0.35/bin/shutdown.sh     –關閉

2、添加系統服務,自動開機啟動

# cd /etc/rc.d/init.d                               –進入系統服務資料夾

# vi tomcat                                           –創建tomcat系統服務設定檔(添加如下內容)

#

# chkconfig: 345 80 15

# description: Tomcat is a Servlet+JSP Engine.

# Enter the jdk installation directory

jdk_File=/usr/local/jdk1.6.0_35

# Enter the tomcat installation directory

tomcat_File=/usr/local/apache-tomcat-7.0.35

export JAVA_HOME=$jdk_File

# Source function library.

. /etc/rc.d/init.d/functions

start(){

if [ -z $(/sbin/pidof java) ]; then

echo “Starting tomcat"

$tomcat_File/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"

$tomcat_File/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)

$tomcat_File/bin/catalina.sh version

;;

*)

echo “Usage: $0 {start|stop|restart|status}"

esac

exit 0

:wq                                     –退出

# chmod 755 /etc/rc.d/init.d/tomcat                             –添加執行許可權

#chkconfig –add tomcat                                                   –添加系統服務

#chkconfig tomcat on                                                       –添加開機啟動

# service tomcat stop                                                  –停止

# service tomcat start                                                       –啟動

# service tomcat restart                                                –重啟

# service tomcat status                                                –查看狀態

開啟防火牆相應埠

開放8080埠的解決步驟如下:

1、修改/etc/sysconfig/iptables檔

# vi /etc/sysconfig/iptables

在22埠下添加如下一行:

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 8080 -j ACCEPT

2、重啟防火牆,這裡有兩種方式重啟防火牆

a) 重啟後生效

開啟: chkconfig iptables on

關閉: chkconfig iptables off

b) 即時生效,重啟後失效

開啟: service iptables start

關閉: service iptables stop

 

Another config

 

#!/bin/sh
#
# Tomcat Server
#
# chkconfig: 345 96 30
# description: Java servlet container

JAVA_HOME=/opt/jdk

PATH=${JAVA_HOME}/bin:${PATH}

TOMCAT_START=/opt/tomcat/bin/startup.sh

TOMCAT_STOP=/opt/tomcat/bin/shutdown.sh

export JAVA_HOME PATH

start()
{
        if [ -x ${TOMCAT_START} ]; then
                echo "Starting tomcat server..."
                ${TOMCAT_START} &
        else
                echo "Cannot start tomcat server"
        fi
}

stop()
{
        if [ -x ${TOMCAT_STOP} ]; then
                echo "Stopping tomcat server..."
                ${TOMCAT_STOP} &
        else
                echo "Cannot stop tomcat server"
        fi
}

restart()
{
        stop
        sleep 10
        start
}

status()
{
        echo "No status available for tomcat server"
}

case "$1" in
'start')
        start
        ;;
'stop')
        stop
        ;;
'restart')
        restart
        ;;
'status')
        status
        ;;
*)
        echo "Please supply an argument [start|stop|restart]"
esac

 

廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s