Saturday, 28 September 2019

How to install and configure Tomcat 9 on CentOS 7/RHEL 7



Apache Tomcat open source and free binary deployed by Apache Foundation. It is commonly used to run Java programs/applications for web and servlet container hosting.
Step 1. Java installation: Tomcat 9 requires Java 8 or latest version must be installed to run tomcat binaries. Follow the article How to install Java8/jdk1.8 using yum command on Centos 7 to install Java9/jdk9.

 

Step 2. Tomcat 9 installation: Use curl/wget to download tomcat binary tar file from Apache tomcat official site.

[root@linuxcloudy ~]# wget https://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.26/bin/apache-tomcat-9.0.26.tar.gz
--2019-09-14 10:59:29--  https://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.26/bin/apache-tomcat-9.0.26.tar.gz
Resolving www-us.apache.org (www-us.apache.org)... 40.79.78.1
Connecting to www-us.apache.org (www-us.apache.org)|40.79.78.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12326996 (12M) [application/x-gzip]
Saving to: ‘apache-tomcat-9.0.26.tar.gz’

100%[==============================================================================================================================>] 12,326,996   532KB/s   in 21s

2019-09-14 10:59:51 (575 KB/s) - ‘apache-tomcat-9.0.26.tar.gz’ saved [12326996/12326996]

[root@linuxcloudy ~]#

Step 3. Extract the tar file and move into /usr/local directory:

[root@linuxcloudy ~]# tar zxvf apache-tomcat-9.0.26.tar.gz
[root@linuxcloudy ~]# mv apache-tomcat-9.0.26 /usr/local/tomcat9
[root@linuxcloudy ~]#

Step 4. Set environment variables: Run the following command to set tomcat environment on current terminal:

[root@linuxcloudy ~]# echo "export CATALINA_HOME="/usr/local/tomcat9"" >> ~/.bashrc
[root@linuxcloudy ~]# source ~/.bashrc
[root@linuxcloudy ~]# echo $CATALINA_HOME
/usr/local/tomcat9
[root@linuxcloudy ~]#

Step 7. Add user for tomcat authentication: Add this below lines at the end of the file and before this line "</tomcat-users>" in tomcat users section.

[root@linuxcloudy ~]# vi $CATALINA_HOME/conf/tomcat-users.xml
……………………………..
<role rolename="manager-gui"/>
<role rolename="manager-status"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>

<role rolename="admin-gui"/>
<user username="admin" password="admin@123" roles="manager-gui,manager-script,manager-status,manager-jmx,admin-gui"/>

Step 8. Comment the following context to allow tomcat to access from remote host:

[root@linuxcloudy ~]# vi $CATALINA_HOME/webapps/host-manager/META-INF/context.xml
……………………………….
<!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->

[root@linuxcloudy ~]# vi $CATALINA_HOME/webapps/manager/META-INF/context.xml
……………………………….
<!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->

Step 10. Start tomcat service using the following command:

[root@linuxcloudy ~]# cd $CATALINA_HOME/bin
[root@linuxcloudy bin]# ./startup.sh
Using CATALINA_BASE:   /usr/local/tomcat9
Using CATALINA_HOME:   /usr/local/tomcat9
Using CATALINA_TMPDIR: /usr/local/tomcat9/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat9/bin/bootstrap.jar:/usr/local/tomcat9/b                                                                                        in/tomcat-juli.jar
Tomcat started.
[root@linuxcloudy bin]#

Step 11. Configure firewall to access tomcat service:

[root@linuxcloudy bin]# firewall-cmd --state
running
[root@linuxcloudy bin# firewall-cmd --permanent --add-port=8080/tcp
success
[root@linuxcloudy bin]# firewall-cmd --reload
success
[root@linuxcloudy bin]#

Step 12. Verification: Browse the url localhost/<IPAddress>:8080 on any browser and the following page will open. Login with credential created in Step 7.


















Done!!! Now Tomcat 9 is installed and configured.

No comments:

Post a Comment