Ansible contd..
Installing tomcat 10 on redhat 10
-
Install Java
Tomcat requires Java to run. You can install OpenJDK on RHEL 10 with:
sudo dnf install java-17-openjdk-devel -y
Verify the installation with:
java -version -
Create a Tomcat User
For security, create a non-root user to run Tomcat:
sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat -
Download Apache Tomcat 10
Download the latest Tomcat 10 tar.gz from the official Apache site. For example:
sudo curl -O https://dlcdn.apache.org/tomcat/tomcat-10/v10.0.23/bin/apache-tomcat-10.0.23.tar.gz
(Check the latest version on Apache’s official download page.) -
Extract and install Tomcat
Create the install directory and extract files:
sudo mkdir /opt/tomcat
sudo tar -xvzf apache-tomcat-10.0.23.tar.gz -C /opt/tomcat --strip-components=1 -
Set permissions
Assign ownership to the tomcat user:
sudo chown -R tomcat: /opt/tomcat
sudo chmod -R u+x /opt/tomcat/bin -
Create a systemd Service
Create a systemd service file/etc/systemd/system/tomcat.servicewith contents to manage Tomcat as a service. An example service file content:
“`
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/java-17-openjdk"
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=/opt/tomcat/bin/shutdown.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
“`
-
Start and enable Tomcat
Reload systemd, start Tomcat and enable at boot:
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl enable tomcat -
Configure firewall (if using firewall)
Allow default HTTP port 8080:
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
This procedure manually installs Tomcat 10 on RHEL 10, as official support or packages might not yet be fully integrated into RHEL 10 repositories. This approach aligns with practices for RHEL 8/9 and other Fedora-based systems.[1][3][5][6][8]
If you want, I can provide the exact systemd service file content or help with configuring Tomcat users and roles for your use case. Let me know!
[1] https://www.ubuntumint.com/install-apache-tomcat-rhel-9/
[2] https://www.hostmycode.in/tutorials/how-to-install-apache-tomcat-10-on-ubuntu
[3] https://www.ubuntumint.com/install-apache-tomcat-rhel-8/
[4] https://utho.com/docs/linux/ubuntu/how-to-install-tomcat-on-ubuntu/
[5] https://maggiminutes.com/latest-apache-tomcat-installation/
[6] https://oracle-base.com/articles/linux/apache-tomcat-10-installation-on-linux
[7] https://www.digitalocean.com/community/tutorials/install-tomcat-on-linux
[8] https://access.redhat.com/solutions/661403
[9] https://tomcat.apache.org/download-10.cgi
[10] https://access.redhat.com/solutions/5826391
Implementation
- Lets try to reuse the same playbook for both redhat and ubuntu.
- Refer Here for the changes done
- we are experiencing the service failure in redhat
- to be fixed in next session
