Install JDK and Tomcat under CentOS 64-bit and set up Tomcat boot-up operation steps

Keywords: Tomcat Java JDK Attribute

The preparatory documents are as follows:

1.CentOS-6.4-x86_64-bin-DVD1.iso
2.jdk-7u67-linux-x64.rpm
3.apache-tomcat-7.0.55.tar.gz

The installation steps are as follows:

Installation of 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]#

II. Installation of 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

Setting Environmental Variables

Execute the vim/etc/profile command and add the environment variable code as follows

#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

Execute the instruction source/etc/profile to refresh environment variables

IV. Start Tomcat

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

Open Web Site in Firefox Browser http://localhost:8080 test

Close the Tomcat command

sh /usr/local/tomcat7/bin/shutdown.sh

5. Start Tomcat script

5.1. Execute instruction vi/etc/rc.d/init.d/tomcat to generate script file, as follows

#!/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 installation directory
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. Add permission Chmod 755/etc/rc.d/init.d/tomcat to make the script file executable

5.3. Run: chkconfig --- add /etc/rc.d/init.d/tomcat # Add it to the service

5.4. Add the following statement to the vim/usr/local/tomcat7/bin/catalina.sh file:

#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

Start the tomcat service: service tomcat start
Stop tomcat service: service tomcat stop

Reprint: http://www.linuxidc.com/Linux/2015-01/111485.htm

Posted by andylyon87 on Thu, 14 Feb 2019 09:42:18 -0800