Tomcat Server Install on CentOS

Tomcat is an application server or web server?

When package or compile an application, it can either be packaged as a .war or .ear, Tomcat is categorized as a web server since it can handle only .war files. But in the traditional developer world, we can refer to the tomcat as an application server, where it can host strictly Java Web-based Applications.

A web server is responsible for process servlets and JSP’s, whereas an application server, should be able to process EJB’s(Enterprise Java Beans), JSF (Java Server Faces) along with servlets and JSP’s. Tomcat can process servlets, JSP’s, Java Expression Language, and Java WebSocket technologies thus making it more than a web server.

A web server is often said to be a part of an application server since an application server exhibits all the features that a web server possesses and in addition to it also contains attributes such as load balancing, data persistence, messaging to name a few. However, vice versa does not apply.

Web Server:

Web server just serves the web pages and some dynamic static pages and it cannot enforce any application logic.

Apache Tomcat vs Apache HTTPd:

The biggest difference between Tomcat and Apache HTTP Server is that Tomcat runs on a JVM. Apache HTTP Server also is known as the Apache webserver and requires only a modern Windows, Linux distribution, or Unix to run. Tomcat users will need to deploy a JDK and properly configure the JAVA_HOME variable to run. The final conclusion is, an application server also contains the webserver.

Follow the steps to achieve the setup of the tomcat application server.  

Step1: Start with JDK installation, as it is mandatory and also a pre-requisite to make tomcat server up and run on Java Runtime Environment. 

$ sudo yum install java-1.8.0-openjdk-devel

$ export JAVA_HOME=/usr/lib/jvm/jre

cp ~/.bashrc ~/.bashrc_backup

sed -i -e '$aJAVA_HOME=/usr/lib/jvm/jre' ~/.bashrc  # Keep the JAVA_HOME consistent through out reboots and new shell prompts. 

Step2: Prepare the right level of access for this tomcat application server to administrate.

$ sudo groupadd tomcat   # Create a group for tomcat user

sudo useradd -M -s /bin/nologin -g tomcat -d /opt/tomcat tomcat  # Create a tomcat user with no shell login capability

Step3: Download or copy the binaries to the desired home directory and assign the right user and group (home: /opt/tomcat, User&group: tomcat)

$ wget

# Choose the desired version from offical website

$ unzip -d /opt/tomcat

$ sudo chown -R tomcat:tomcat /opt/tomcat/apache-tomcat-8.5.59 && cd /opt/tomcat/apache-tomcat-8.5.59 && sudo chmod 755 webapps temp work && sudo chmod +x bin

Step4 : Try to start in traditional way and check everything was working as expected.



$ curl http://localhost:8080 # ( If fails, check the installed firewall utility and rules)

Firewall rules with IPtable:

sudo iptables -A INPUT -p tcp --dport 8080 -j ACCEPT

sudo /sbin/iptables-save > /etc/sysconfig/iptables  (or)

sudo service iptables save


firewall-cmd --permanent --zone=public --add-port=8080/tcp

firewall-cmd --reload


Make the systemd to manage httpd service:

cat > /etc/systemd/system/tomcat.service

# Systemd unit file for tomcat
Description=Apache Tomcat Web Application Container

Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'

ExecStop=/bin/kill -15 $MAINPID



$ sudo systemctl daemon-reload && sudo systemctl start tomcat && sudo systemctl enable tomcat


Create an Admin user to access the manager application:

sudo vi /opt/tomcat/apache-tomcat-8.5.59/conf/tomcat-users.xml  (# Add the below section at the end of the tomcat-users.xml file)

    <user username="admin" password="password" roles="manager-gui,admin-gui"/>

For manager app type comment out the below section to remove the IP restriction:

$ sudo vi /opt/tomcat/apache-tomcat-8.5.59/webapps/host-manager/META-INF/context.xml

<Context antiResourceLocking="false" privileged="true" >
  <!--<Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />-->

Conclusion: Install and configure of basic tomcat is quite straightway but the power and usage of the tomcat server are quite immense, so try to explore more use cases and complex setup to support production application with high availability and fault-tolerant environment setup. 


Popular Posts