The instructions below are assuming you’re logged in as root, if you are logged in as another user remember to prepend sudo to the commands shown below.
Install the necessary packages
First of all update your server and install the necessary packages using the following commands:
First of all update your server and install the necessary packages using the following commands:
yum -y update
yum -y install curl libcap-devel
yum -y groupinstall “Development tools”
yum -y install curl libcap-devel
yum -y groupinstall “Development tools”
Download/Install Java JDK 8
We’ll download and install the latest Java JDK 8, from the Oracle webite. Download the rpm package according to your architecture:
curl -LO ‘http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-x64.rpm’ -H ‘Cookie: oraclelicense=accept-securebackup-cookie’
alternatives –install /usr/bin/java java /usr/java/jdk1.8.0_51/jre/bin/java 1
alternatives –install /usr/bin/jar jar /usr/java/jdk1.8.0_51/bin/jar 1
alternatives –install /usr/bin/javac javac /usr/java/jdk1.8.0_51/bin/javac 1
alternatives –install /usr/bin/javaws javaws /usr/java/jdk1.8.0_51/javaws 1
alternatives –install /usr/bin/jar jar /usr/java/jdk1.8.0_51/bin/jar 1
alternatives –install /usr/bin/javac javac /usr/java/jdk1.8.0_51/bin/javac 1
alternatives –install /usr/bin/javaws javaws /usr/java/jdk1.8.0_51/javaws 1
alternatives –set java /usr/java/jdk1.8.0_51/jre/bin/java
alternatives –set javaws /usr/java/jdk1.8.0_51/jre/bin/javaws
alternatives –set javac /usr/java/jdk1.8.0_51/bin/javac
alternatives –set jar /usr/java/jdk1.8.0_51/bin/jar
alternatives –set javaws /usr/java/jdk1.8.0_51/jre/bin/javaws
alternatives –set javac /usr/java/jdk1.8.0_51/bin/javac
alternatives –set jar /usr/java/jdk1.8.0_51/bin/jar
http://mirror.nus.edu.sg/apache/tomcat/tomcat-8/v8.0.24/bin/apache-tomcat-8.0.24.tar.gz
Build Jsvc
Jsvc is a set of libraries and applications for making Java applications run on UNIX more easily and we’ll use it to start/stop the Tomcat instance. The building process is pretty straightforward:
Jsvc is a set of libraries and applications for making Java applications run on UNIX more easily and we’ll use it to start/stop the Tomcat instance. The building process is pretty straightforward:
cd /usr/tomcat/bin
tar xvfz commons-daemon-native.tar.gz
cd commons-daemon-*-native-src/unix
./configure –with-java=/usr/java/latest
make
cp jsvc ../..
tar xvfz commons-daemon-native.tar.gz
cd commons-daemon-*-native-src/unix
./configure –with-java=/usr/java/latest
make
cp jsvc ../..
Create tomcat user
The following commands will create a dedicated user who will run the Tomcat instance and change the ownership of all files in the /opt/tomcat directory to the newly created tomcat user.
useradd -r -s /sbin/nologin tomcat
chown -R tomcat: /usr/tomcat
chown -R tomcat: /usr/tomcat
Create a systemd service
Create a new file named tomcat.service:
Create a new file named tomcat.service:
vi /usr/lib/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
PIDFile=/var/run/tomcat.pid
Environment=CATALINA_PID=/var/run/tomcat.pid
Environment=JAVA_HOME=/usr/java/default
Environment=CATALINA_HOME=/usr/tomcat
Environment=CATALINA_BASE=/usr/tomcat
Environment=CATALINA_OPTS=
Type=forking
PIDFile=/var/run/tomcat.pid
Environment=CATALINA_PID=/var/run/tomcat.pid
Environment=JAVA_HOME=/usr/java/default
Environment=CATALINA_HOME=/usr/tomcat
Environment=CATALINA_BASE=/usr/tomcat
Environment=CATALINA_OPTS=
ExecStart=/usr/tomcat/bin/jsvc \
-Dcatalina.home=${CATALINA_HOME} \
-Dcatalina.base=${CATALINA_BASE} \
-cp ${CATALINA_HOME}/bin/commons-daemon.jar:${CATALINA_HOME}/bin/bootstrap.jar:${CATALINA_HOME}/bin/tomcat-juli.jar \
-user tomcat \
-java-home ${JAVA_HOME} \
-pidfile /var/run/tomcat.pid \
-errfile SYSLOG \
-outfile SYSLOG \
$CATALINA_OPTS \
org.apache.catalina.startup.Bootstrap
-Dcatalina.home=${CATALINA_HOME} \
-Dcatalina.base=${CATALINA_BASE} \
-cp ${CATALINA_HOME}/bin/commons-daemon.jar:${CATALINA_HOME}/bin/bootstrap.jar:${CATALINA_HOME}/bin/tomcat-juli.jar \
-user tomcat \
-java-home ${JAVA_HOME} \
-pidfile /var/run/tomcat.pid \
-errfile SYSLOG \
-outfile SYSLOG \
$CATALINA_OPTS \
org.apache.catalina.startup.Bootstrap
ExecStop=/usr/tomcat/bin/jsvc \
-pidfile /var/run/tomcat.pid \
-stop \
org.apache.catalina.startup.Bootstrap
-pidfile /var/run/tomcat.pid \
-stop \
org.apache.catalina.startup.Bootstrap
[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
You can change the line with CATALINA_OPTS to suit your needs.
To enable the Tomcat service to start on boot run:
To enable the Tomcat service to start on boot run:
systemctl enable tomcat.service
Now, you can use the following commands to start, stop, restart and check the status the Tomcat service:
systemctl start tomcat
systemctl stop tomcat
systemctl restart tomcat
systemctl status tomcat
systemctl stop tomcat
systemctl restart tomcat
systemctl status tomcat
Final steps
If you need to open port 8080 in the firewall, run:
If you need to open port 8080 in the firewall, run:
firewall-cmd –zone=public –add-port=8080/tcp –permanent
firewall-cmd –reload
firewall-cmd –reload
That’s it, Tomcat installation is complete. To open Tomcat, point your browser at:
Recent Comments