Skip to content

Instantly share code, notes, and snippets.

@swarupdonepudi
Last active October 18, 2023 09:42
Show Gist options
  • Save swarupdonepudi/a899aff32f6098fab7c42cd97e6a58f8 to your computer and use it in GitHub Desktop.
Save swarupdonepudi/a899aff32f6098fab7c42cd97e6a58f8 to your computer and use it in GitHub Desktop.
Installation instructions for tomcat on CentOS 7
  1. Install Java on the VM by running the command

    yum -y install java-1.8.0-openjdk.x86_64
  2. Check the version of Java installed

    java –version
  3. 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.

  4. 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
  5. Unizip the file

    tar -zxvf apache-tomcat-8.0.41.tar.gz -C /opt/tomcat --strip-components=1
  6. 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
     
  7. Change the file permission on /opt/tomcat directory

    chmod -R 777 /opt/tomcat
  8. Start tomcat service :

    systemctl start tomcat.service
  9. 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"


  1. Reload the firewall settings

    firewall-cmd --reload
@bkrajendra
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment