CentOS 64-bit下安装JDK和Tomcat并设置Tomcat开机启动操作步骤

准备文件如下:

1.CentOS-6.4-x86_64-bin-DVD1.iso

2.jdk-7u67-linux-x64.rpm

3.apache-tomcat-7.0.55.tar.gz

安装步骤如下:

一、安装JDK

[root@n1 /]# java -version
bash: java: command not found

[root@n1 /]# rpm -ivh /soft/jdk-7u67-linux-x64.rpm
Preparing...                ########################################### [100%]
   1:jdk                    ########################################### [100%]
Unpacking JAR files...
    rt.jar...
    jsse.jar...
    charsets.jar...
    tools.jar...
    localedata.jar...
    jfxrt.jar...
[root@n1 /]#

[root@n1 /]# 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)

[root@n1 /]# cd /usr/java
[root@n1 java]# ls
default  jdk1.7.0_67  latest
[root@n1 java]#

二、安装Tomcat

rm -rf /usr/local/tomcat7
cd /usr
cd /usr/local/tomcat7
ls
ls

cd /
tar zxvf /soft/apache-tomcat-7.0.55.tar.gz
mv /apache-tomcat-7.0.55 /usr/local/tomcat7
chmod +x /usr/local/tomcat7

三、设置环境变量

执行vim /etc/profile命令,添加环境变量代码如下

#jdk config
export JAVA_HOME=/usr/java/jdk1.7.0_67
export CALSSPATH=$JAVA_HOME/lib/*.*  
#tomcat config
export TOMCAT_HOME=/usr/local/tomcat7
export CATALINA_HOME=/usr/local/tomcat7
#path config
export PATH=$PATH:$JAVA_HOME/bin:$TOMCAT_HOME/bin

执行指令source /etc/profile刷新环境变量

四、启动Tomcat

sh /usr/local/tomcat7/bin/startup.sh

在火狐浏览器中打开网址http://localhost:8080测试

关闭Tomcat命令
sh /usr/local/tomcat7/bin/shutdown.sh

五、开机启动Tomcat脚本

5.1、执行指令vi /etc/rc.d/init.d/tomcat生成脚本文件,内容如下

#!/bin/bash

#

# /etc/rc.d/init.d/tomcat

# init script for tomcat precesses

#

# processname: tomcat

# description: tomcat is a j2se server

# chkconfig: 2345 86 16

# description: Start up the Tomcat servlet engine.

if [ -f /etc/init.d/functions ]; then

. /etc/init.d/functions

elif [ -f /etc/rc.d/init.d/functions ]; then

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

else

echo -e "\atomcat: unable to locate functions lib. Cannot continue."

exit -1

fi

RETVAL=$?

CATALINA_HOME="/usr/local/tomcat7" #tomcat安装目录

case "$1" in

start)

if [ -f $CATALINA_HOME/bin/startup.sh ];

then

echo $"Starting Tomcat"

$CATALINA_HOME/bin/startup.sh

fi

;;

stop)

if [ -f $CATALINA_HOME/bin/shutdown.sh ];

then

echo $"Stopping Tomcat"

$CATALINA_HOME/bin/shutdown.sh

fi

;;

*)

echo $"Usage: $0 {start|stop}"

exit 1

;;

esac

exit $RETVAL

5.2、添加权限chmod 755 /etc/rc.d/init.d/tomcat,使得脚本文件可执行

5.3、运行:chkconfig --add /etc/rc.d/init.d/tomcat #将其加到服务中

5.4、在vim /usr/local/tomcat7/bin/catalina.sh文件中加入以下语句:

#auto startup tomcat config
export JAVA_HOME=/usr/java/jdk1.7.0_67
export CATALINA_HOME=/usr/local/tomcat7
export CATALINA_BASE=/usr/local/tomcat7
export CATALINA_TMPDIR=/usr/local/tomcat7/temp

启动tomcat服务: service tomcat start
停止tomcat服务: service tomcat stop

上一篇:ZT ---- 给孩子的信(孩子写给爸爸妈妈的信在24、25、26楼)


下一篇:UVA数学入门训练Round1[6]