-
Install Java on the VM by running the command
yum -y install java-1.8.0-openjdk.x86_64
-
Check the version of Java installed
java –version
-
Create a dedicated user for Apache Tomcat. For security purposes, you need to create a dedicated non-root user "tomcat" who belongs to the "tomcat" group:
groupadd tomcat useradd -s /bin/nologin -g tomcat -d /opt/tomcat tomcat
Note: In this fashion, you created a user "tomcat" who belongs to the group "tomcat". You cannot use this user account to log into the system. The home directory is /opt/tomcat, which is where the Apache Tomcat program will reside.
-
Downloading apache tomcat from internet.
wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.41/bin/apache-tomcat-8.0.41.tar.gz
-
Unizip the file
tar -zxvf apache-tomcat-8.0.41.tar.gz -C /opt/tomcat --strip-components=1
-
Set up the systemd unit file for tomcat for convenience (Enter the below content in the editor and then save and quit)
vi /etc/systemd/system/tomcat.service
[Unit] Description=Apache Tomcat Web Application Container After=syslog.target network.target [Service] Type=forking Environment=JAVA_HOME=/usr/lib/jvm/jre-1.8.0 Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid Environment=CATALINA_HOME=/opt/tomcat Environment=CATALINA_BASE=/opt/tomcat #Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC' Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom' ExecStart=/opt/tomcat/bin/startup.sh ExecStop=/bin/kill -15 $MAINPID User=tomcat Group=tomcat [Install] WantedBy=multi-user.target
-
Change the file permission on /opt/tomcat directory
chmod -R 777 /opt/tomcat
-
Start tomcat service :
systemctl start tomcat.service
-
Open firewall port 8080 on VM to access Apache webpage from host machine browser
firewall-cmd --permanent --add-port=8080/tcp
If firewalld is not installed, install by running "yum install firewalld" and then start the service using "systemctl start firewalld"
-
Reload the firewall settings
firewall-cmd --reload
I have installed tomcat in /apps/tomcat/ directory and was facing the issue:
SELinux is preventing /usr/lib/systemd/systemd from execute access on the file startup.sh.
Fixed it by using:
chcon -R -t bin_t /apps/tomcat/bin/