Installing Tomcat 8 on a CentOS 7 Linux VPS

Installing Tomcat 8 on a CentOS 7 Linux VPSIn the following article we will guide you through the steps on how to install the latest Tomcat 8 on a CentOS 7 Linux VPS.

What is Tomcat?

Apache Tomcat (previously known as Jakarta Tomcat) is an application server developed by the Apache Software Foundation that executes Java servlets and renders Web pages that include Java Server Page coding.

System Requirements?

  • A Linux VPS Hosting
  • JAVA 7+ Server

UPDATE SYSTEM

First thing to do is to SSH to your CentOS 7 VPS, fire up a screen session and update your system using yum:

## screen -U -S tomcat8-centos7
## yum update

You may also want to install a text editor like nano or vim

## yum install vim nano

SETUP JAVA

Tomcat 8 requires JAVA 7+ in order to run. We are going to install the latest version of Oracle’s JAVA JDK 8. At the time of writing this article, the latest version of JAVA is 8u25 and can be downloaded and installed using the commands below:

DOWNLOAD JAVA

for 32-bit (x86) systems:

## wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-i586.rpm" \
-O /opt/jdk-8-linux-i586.rpm

for 64-bit (x86_64) systems:

## wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.rpm" \
-O /opt/jdk-8-linux-x64.rpm

INSTALL JAVA

for 32-bit (x86) systems:

## yum install /opt/jdk-8-linux-i586.rpm

for 64-bit (x86_64) systems:

## yum install /opt/jdk-8-linux-x64.rpm

CONFIGURE JAVA

configure the JAVA package using the alternatives command:

## JDK_DIRS=($(ls -d /usr/java/jdk*))
## JDK_VER=${JDK_DIRS[@]:(-1)}

## alternatives --install /usr/bin/java java /usr/java/"${JDK_VER##*/}"/jre/bin/java 20000
## alternatives --install /usr/bin/jar jar /usr/java/"${JDK_VER##*/}"/bin/jar 20000
## alternatives --install /usr/bin/javac javac /usr/java/"${JDK_VER##*/}"/bin/javac 20000
## alternatives --install /usr/bin/javaws javaws /usr/java/"${JDK_VER##*/}"/jre/bin/javaws 20000
## alternatives --set java /usr/java/"${JDK_VER##*/}"/jre/bin/java
## alternatives --set javaws /usr/java/"${JDK_VER##*/}"/jre/bin/javaws
## alternatives --set javac /usr/java/"${JDK_VER##*/}"/bin/javac
## alternatives --set jar /usr/java/"${JDK_VER##*/}"/bin/jar

VERIFY JAVA

You may want to check if JAVA has been properly setup on your CentOS Linux VPS using:

## java -version

SETUP TOMCAT

TOMCAT USER

Before proceeding with the Tomcat installation, let’s first create a separate system user which will run the Tomcat server:

## useradd -r tomcat8 --shell /bin/false

DOWNLOAD TOMCAT

Next, download the latest version of Tomcat 8 available at http://tomcat.apache.org/download-80.cgi . You can use wget to download it in /tmp, for example:

## wget http://mirror.tcpdiag.net/apache/tomcat/tomcat-8/v8.0.15/bin/apache-tomcat-8.0.15.tar.gz -P /tmp

INSTALL TOMCAT

Extract the contents of the Tomcat archive you just downloaded to /opt, create a symbolic link of tomcat directory to /opt/tomcat-latest and setup proper ownership using the following commands:

## tar -zxf /tmp/apache-tomcat-*.tar.gz -C /opt
## ln -s /opt/apache-tomcat-8.0.15 /opt/tomcat-latest
## chown -hR tomcat8: /opt/tomcat-latest /opt/apache-tomcat-*

START TOMCAT

Create the following systemd unit file in /etc/systemd/system/tomcat8.service

[Unit]
Description=Tomcat8
After=network.target

[Service]
Type=forking
User=tomcat8
Group=tomcat8

Environment=CATALINA_PID=/opt/tomcat-latest/tomcat8.pid
Environment=TOMCAT_JAVA_HOME=/usr/java/default
Environment=CATALINA_HOME=/opt/tomcat-latest
Environment=CATALINA_BASE=/opt/tomcat-latest
Environment=CATALINA_OPTS=
Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC -XX:MaxPermSize=128m -Xms512m -Xmx512m"

ExecStart=/opt/tomcat-latest/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

[Install]
WantedBy=multi-user.target

With the unit file in place, run the following commands to start the Tomcat servce:

## systemctl daemon-reload
## systemctl restart tomcat8
## systemctl enable tomcat8

ACCESS TOMCAT

Access your newly installed Tomcat at http://YOUR_IP:8080


Of course, you don’t have to do any of this if you use one of our Ultra-Fast VPS Hosting services, in which case you can simply ask our expert Linux admins to install Tomcat 8 for you. They are available 24×7 and will take care of your request immediately. You can also read our guide on how to Install Tomcat 9 on CentOS 7 for more information.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

8 thoughts on “Installing Tomcat 8 on a CentOS 7 Linux VPS”

  1. Hi sir,
    I tried to use :
    ## systemctl restart tomcat8
    but I get a error :
    Job for tomcat8.service failed. See ‘systemctl status tomcat8.service’ and ‘journalctl -xn’ for details.

    Please help me to solve it. Thanks so much !

    Reply
  2. Same issue. Output:

    Job for tomcat8.service failed. See ‘systemctl status tomcat8.service’ and ‘journalctl -xn’ for details.
    [x@x]$ systemctl status tomcat8.service
    tomcat8.service – Tomcat8
    Loaded: loaded (/etc/systemd/system/tomcat8.service; disabled)
    Active: failed (Result: exit-code) since Fri 2015-07-03 07:54:40 UTC; 11s ago
    Process: 12504 ExecStart=/opt/tomcat-latest/bin/startup.sh (code=exited, status=203/EXEC)

    Reply
  3. May 14 17:32:07 82.99.215.42.parsonline.net systemd[1]: Unit tomcat8.service entered failed state.
    May 14 17:32:07 82.99.215.42.parsonline.net systemd[1]: tomcat8.service failed.
    May 14 17:32:07 82.99.215.42.parsonline.net polkitd[52858]: Unregistered Authentication Agent for unix-process:41255:1327698410 (system bus name :1.22445, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, loc
    May 14 17:32:11 82.99.215.42.parsonline.net sshd[41239]: reverse mapping checking getaddrinfo for 210.30.65.218.broad.xy.jx.dynamic.163data.com.cn [218.65.30.210] failed – POSSIBLE BREAK-IN ATTEMPT!
    May 14 17:32:18 82.99.215.42.parsonline.net sshd[41239]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=218.65.30.210 user=root
    May 14 17:32:18 82.99.215.42.parsonline.net sshd[41239]: pam_succeed_if(sshd:auth): requirement “uid >= 1000” not met by user “root”
    May 14 17:32:20 82.99.215.42.parsonline.net sshd[41239]: Failed password for root from 218.65.30.210 port 34518 ssh2
    May 14 17:32:27 82.99.215.42.parsonline.net sshd[41239]: pam_succeed_if(sshd:auth): requirement “uid >= 1000” not met by user “root”
    May 14 17:32:29 82.99.215.42.parsonline.net sshd[41239]: Failed password for root from 218.65.30.210 port 34518 ssh2
    May 14 17:32:29 82.99.215.42.parsonline.net sshd[41239]: pam_succeed_if(sshd:auth): requirement “uid >= 1000” not met by user “root”
    May 14 17:32:31 82.99.215.42.parsonline.net sshd[41239]: Failed password for root from 218.65.30.210 port 34518 ssh2
    May 14 17:32:32 82.99.215.42.parsonline.net sshd[41239]: Received disconnect from 218.65.30.210: 11: [preauth]
    May 14 17:32:32 82.99.215.42.parsonline.net sshd[41239]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=218.65.30.210 user=root
    May 14 17:33:01 82.99.215.42.parsonline.net sshd[41312]: Disabling protocol version 1. Could not load host key
    May 14 17:33:06 82.99.215.42.parsonline.net sshd[41312]: Received disconnect from 116.31.116.49: 11: [preauth]
    May 14 17:33:09 82.99.215.42.parsonline.net sshd[41330]: Disabling protocol version 1. Could not load host key
    May 14 17:33:26 82.99.215.42.parsonline.net sshd[41330]: reverse mapping checking getaddrinfo for 210.30.65.218.broad.xy.jx.dynamic.163data.com.cn [218.65.30.210] failed – POSSIBLE BREAK-IN ATTEMPT!
    May 14 17:33:28 82.99.215.42.parsonline.net sshd[41330]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=218.65.30.210 user=root
    May 14 17:33:28 82.99.215.42.parsonline.net sshd[41330]: pam_succeed_if(sshd:auth): requirement “uid >= 1000” not met by user “root”
    May 14 17:33:30 82.99.215.42.parsonline.net sshd[41330]: Failed password for root from 218.65.30.210 port 39855 ssh2
    May 14 17:33:34 82.99.215.42.parsonline.net sshd[41330]: pam_succeed_if(sshd:auth): requirement “uid >= 1000” not met by user “root”
    May 14 17:33:36 82.99.215.42.parsonline.net sshd[41330]: Failed password for root from 218.65.30.210 port 39855 ssh2

    Reply

Leave a Comment