AMP AMP

How to install Tomcat 9 on CentOS 6

To install Tomcat 9 on CentOS 6

Apache Tomcat is an open-source web server and servlet container is used to serve JAVA application. It follows Java EE specifications and provides a HTTP web server. The installation of Apache Tomcat 9 on CentOS 6 is covered in this tutorial.


Install Java

Before installing Tomcat you need to install Java in your system so run the following command to do that.

[root@linuxhelp ~]# yum install java-1.8.0-openjdk.x86_64 -y
 
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
epel/metalink                                                                                                                          | 6.2 kB     00:00     
 * base: mirrors.viethosting.com
 * epel: kartolo.sby.datautama.net.id
 * extras: mirrors.vonline.vn
 * updates: mirrors.viethosting.com
base                                                                                                                                   | 3.7 kB     00:00     
epel                                                                                                                                   | 4.7 kB     00:00     
epel/primary_db                                                                                                                        | 6.0 MB     00:00     
extras                                                                                                                                 | 3.4 kB     00:00     
updates                               
.
.
.
Verifying  : 1:java-1.8.0-openjdk-1.8.0.151-1.b12.el6_9.x86_64                                                                                          2/2 

Installed:
  java-1.8.0-openjdk.x86_64 1:1.8.0.151-1.b12.el6_9                                                                                                           

Dependency Installed:
  java-1.8.0-openjdk-headless.x86_64 1:1.8.0.151-1.b12.el6_9                                                                                                         | 3.4 kB     00:00    


After doing that, you need to download the latest stable version of Tomcat using the wget command in the following manner.

[root@linuxhelp ~]# wget http://redrockdigimark.com/apachemirror/tomcat/tomcat-9/v9.0.1/bin/apache-tomcat-9.0.1.tar.gz
--2017-11-17 16:04:51--  http://redrockdigimark.com/apachemirror/tomcat/tomcat-9/v9.0.1/bin/apache-tomcat-9.0.1.tar.gz
Resolving redrockdigimark.com... 119.18.61.94
Connecting to redrockdigimark.com|119.18.61.94|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9397803 (9.0M) [application/x-gzip]
Saving to: “ apache-tomcat-9.0.1.tar.gz” 

100%[====================================================================================================================================================================> ] 9,397,803   53.3M/s   in 0.2s    

2017-11-17 16:05:08 (53.3 MB/s) - “ apache-tomcat-9.0.1.tar.gz”  saved [9397803/9397803]


After downloading the package, you need to extract it by making use of the following command.

[root@linuxhelp ~]# tar -xzf apache-tomcat-9.0.1.tar.gz

And then, rename it as per your convenience.

[root@linuxhelp ~]# mv apache-tomcat-9.0.1 /opt/tomcat/

Now, move inside the installed directory through the following command.

[root@linuxhelp ~]# cd /opt/tomcat/bin

And then, you need to run the script to start your service as follows.

[root@linuxhelp bin]# sh startup.sh
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.

You shall now switch to your browser and give http://YourIP:8080 as URL. But you can’ t view information so for that you need to get back to your terminal.

Open your tomcat-users file and authenticate it by providing your user name, password and roles.

[root@linuxhelp tomcat]# vim webapps/manager/META-INF/context.xml

< ?xml version=" 1.0"  encoding=" UTF-8" ?> 
.
.
< 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|192.168.7.219"  /> 
.
.
< /Context> 

Also, do the same for your Host manager.

[root@linuxhelp tomcat]# vim webapps/host-manager/META-INF/context.xml
< ?xml version=" 1.0"  encoding=" UTF-8" ?> 
< 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|192.168.7.219"  /> 
.
.
.
< /Context> 

Once all of it is done, you shall start the Tomcat service by running the following command.

[root@linuxhelp tomcat]# cd bin/
[root@linuxhelp bin]# sh startup.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.

And then you should create a script inside /etc/init.d/ in the following manner.

[root@linuxhelp bin]# vim /etc/init.d/tomcat9
#!/bin/bash  
# description: Tomcat Start Stop Restart  
# processname: tomcat  
# chkconfig: 234 20 80  
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el6_9.x86_64/jre
export JAVA_HOME  
PATH=$JAVA_HOME/bin:$PATH
export PATH  
CATALINA_HOME=/opt/tomcat

case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
  
stop)
sh $CATALINA_HOME/bin/shutdown.sh
  
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
  
esac
exit 0


Again switch to your browser and type http://192.168.7.219:8080 in the URL field. To check on the server status click on that button.

And give your login credentials in the popup that appears, click on the OK button.

The Server Status page of Tomcat now appears.

Same way you can check the your Tomcat Application Manager page.

With this, the installation of Tomcat9 on CentOS 6 gets completed.

Tag : CentOS Tomcat
Comment
mikeh
Jul 31 2018
It should be noted, that 50 megabytes is a maximum WAR upload size for the click button to deploy. You should add mention that you can fix this by changing it in the /tomcat/webapps/manager/WEB-INF/web.xml file. I've edited this for approximately 500 megabytes. 524288000 524288000 0
Add a comment
FAQ
Q
How can I start the Tomcat service?
A
Run the following command:
# cd bin/
# sh startup.sh
Q
Is Tomcat faster than serving static HTML pages than Apache httpd?
A
Yes depending on how you tune it. And NO depending on how you tune it. Anything less starts a religious war. We recommend performing your own benchmarks and see for yourself.
Q
What is Tomcat 9?
A
Apache Tomcat is an open-source web server and servlet container is used to serve JAVA application. It follows Java EE specifications and provides an HTTP web server.
Q
How do I configure apache tomcat connectors for a heavy load site?
A
The official site is here: You can be used it
http://people.apache.org/~mturk/docs/article/ftwai.html
Q
How to Install Java in Tomcat 9?
A
Run the following command:
# yum install java-1.8.0-openjdk.x86_64