Install JDK
Download the JDK on the Oracle Java SEDownload page.
(1) Check "Accept License Agreement 」
(2) click jdk-8u91-linux-x64.rpm 」
If the system is 64-bit, select x64, and if the system is 32-bit, select i586.
(3) upload the downloaded file to the server over FTP.
(4) install JDK
# Rpm-ivh./jdk-8u91-linux-x64.rpm
Install Tomcat
In Apache Tomcat-Welcome! Download Tomcat from the Downloads page.
# Wget http://ftp.kddilabs.jp/infosystems/apache/tomcat/tomcat-7/v7.0.70/bin/apache-tomcat-7.0.70.tar.gz
# Tar zxvf./apache-tomcat-7.0.70.tar.gz-C/usr/local/
(2) add a tomcat user
# Useradd-m-d/home/tomcat
# Chown-R tomcat: Maid/usr/local/apache-tomcat-7.0.70/
(3) the apache-tomcat-7.0.7 directory is too long. Make a soft link to/usr/local/tomcat and modify the user
# Ln-s/usr/local/apache-tomcat-7.0.70/usr/local/tomcat
# Chown-h tomcat./usr/local/tomcat
(4) Start tomcat
# Sudo-u tomcat/usr/local/tomcat/bin/startup. sh
(5) enter http: // IP address: 8080/
Run the following command to stop Tomcat.
# Sudo-u tomcat/usr/local/tomcat/bin/shutdown. sh
Create a Tomcat startup/Stop script
(1) create the/etc/init. d/tomcat file.
| The code is as follows: |
Copy code |
|
#! /Bin/bash
# Chkconfig: 2345 10 90
# Description: tomcat service
# Source function library.
./Etc/init. d/functions
CATALINA_HOME = "/usr/local/tomcat"
CATALINA_PID = "/usr/local/tomcat/catalina. pid"
TOMCAT_USER = "tomcat"
NAME = "tomcat"
RETVAL =$?
Case "$1" in
Start)
If [-f "/var/lock/subsys/$ {NAME}"]; then
Echo "Tomcat is already running"
Exit 1
Fi
Echo "Starting Tomcat"
Sudo-u $ {TOMCAT_USER }$ {CATALINA_HOME}/bin/catalina. sh start
Touch/var/lock/subsys/tomcat
;;
Stop)
If [! -F "/var/lock/subsys/$ {NAME}"]; then
Echo "Tomcat is already stopping"
Exit 1
Fi
Echo "Stopping Tomcat"
Sudo-u $ {TOMCAT_USER }$ {CATALINA_HOME}/bin/catalina. sh stop-force
Rm-f/var/lock/subsys/tomcat
;;
Restart)
$0 stop
Sleep 10
$0 start
;;
Status)
If [-f "$ {CATALINA_PID}"]; then
Read kpid <$ {CATALINA_PID}
If [-d "/proc/$ {kpid}"]; then
Echo "$ {NAME} (pid $ {kpid}) is running ..."
Else
Echo "$ {NAME} is not running, but PID file exists"
Fi
Else
Echo "$ {NAME} is stopped"
Fi
;;
*)
Echo "Usage: $0 {start | stop | restart | status }"
Exit 1
;;
Esac
Exit $ {RETVAL} |
Startup. sh and shutdown. sh are not used here. You can use catalina. sh to start and stop tomcat directly.
(2) grant the execution permission to the script
# Chmod + x/etc/init. d/tomcat
(3) configure automatic start upon startup
# Chkconfig -- add tomcat
# Chkconfig -- list | grep tomcat
# Chkconfig tomcat on
Apache and Tomcat
Listen on port 80 of Apache and use Apache ProxyPass to enable Tomcat.
# Vi/etc/httpd/conf/httpd. conf
ProxyPass/tomcat/ajp: // localhost: 8009/
ProxyPass/examples/ajp: // localhost: 8009/examples/
Restart httpd to access Tomcat through port 80.