Installing Tomcat on Redhat and Centos

Install Tomcat on Centos 6/7
[root@centos7test ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

Install java

[root@centos7test ~]# yum install java-1.8.0-openjdk.x86_64    -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.liquidweb.com
* extras: centos.mirror.lstn.net
* updates: mirrordenver.fdcservers.net
Package 1:java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64 already installed and latest version
Nothing to do
[root@centos7test ~]# java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
[root@centos7test ~]# which java
/usr/bin/java
In order to install tomcat you need to enable epel repo
[root@centos7test ~]# yum install epel-release
[root@centos7test ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
[root@centos7test ~]# yum repolist
Loaded plugins: fastestmirror
base                                                                                          | 3.6 kB  00:00:00
epel/x86_64/metalink                                                                          |  19 kB  00:00:00
epel                                                                                          | 3.2 kB  00:00:00
extras                                                                                        | 3.4 kB  00:00:00
updates                                                                                       | 3.4 kB  00:00:00
(1/7): epel/x86_64/group_gz                                                                   |  88 kB  00:00:00
(2/7): base/7/x86_64/group_gz                                                                 | 166 kB  00:00:00
(3/7): extras/7/x86_64/primary_db                                                             | 174 kB  00:00:00
(4/7): epel/x86_64/updateinfo                                                                 | 933 kB  00:00:01
(5/7): epel/x86_64/primary                                                                    | 3.6 MB  00:00:01
(6/7): base/7/x86_64/primary_db                                                               | 5.9 MB  00:00:04
(7/7): updates/7/x86_64/primary_db                                                            | 4.3 MB  00:00:05
Determining fastest mirrors
* base: mirror.den1.denvercolo.net
* epel: mirror.oss.ou.edu
* extras: centos.mirror.lstn.net
* updates: mirrordenver.fdcservers.net
epel                                                                                                     12642/12642
repo id                                 repo name                                                              status
base/7/x86_64                           CentOS-7 - Base                                                         9,911
epel/x86_64                             Extra Packages for Enterprise Linux 7 - x86_64                         12,642
extras/7/x86_64                         CentOS-7 - Extras                                                         370
updates/7/x86_64                        CentOS-7 - Updates                                                      1,042
repolist: 23,965

install tomcat tomcat-webapps and tomcat-admin-webapps

[root@centos7test ~]# yum -y install tomcat tomcat-webapps tomcat-admin-webapps tomcat-docs-webapp
[root@centos7test ~]# systemctl enable tomcat.service
Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat.service to /usr/lib/systemd/system/tomcat.service.
for centos6  chkconfig tomcat on

[root@centos7test ~]# systemctl start tomcat.service
for centos 6 service tomcat start
[root@centos7test ~]# systemctl status tomcat.service
● tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2018-08-13 20:46:55 MDT; 5s ago
Main PID: 9740 (java)
[root@centos7test ~]# netstat -tulpn | grep 80*
tcp6       0      0 :::8080                 :::*                    LISTEN      9740/java
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      9740/java
tcp6       0      0 :::8009                 :::*                    LISTEN      9740/java
[root@centos7test ~]# tomcat version
Server version: Apache Tomcat/7.0.76
Server built:   Apr 11 2018 03:37:53 UTC
Server number:  7.0.76.0
OS Name:        Linux
OS Version:     3.10.0-693.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_181-b13
JVM Vendor:     Oracle Corporation
disable firewalld,
[root@centos7test ~]# systemctl stop firewalld
[root@centos7test ~]# systemctl disable  firewalld
[root@centos7test ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
For centos 6 
service iptables stop
chkconfig iptables off

disable selinux

[root@centos7test ~]# setenforce 0
[root@centos7test ~]# vi /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
In webbrowser enter your ipaddress with port 8080 for eg:192.168.11.88:8080
To chang port from 8080 to something else go to /etc/tomcat/server.xml and change 8080 to port that you want
[root@centos7test ~]# vi  /etc/tomcat/server.xml
<Connector port="8090" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8090" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->

 

To access manager-gui add to tomcat-users.xml file between <tomcat-users> and </tomcat-users>
[root@centos7test ~]# vi /etc/tomcat/tomcat-users.xml
<role rolename="admin"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<user username="admin" password="letmein" roles="admin,manager,manager-gui"/>

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.