Ansible contd…
Installing tomcat on ubuntu
To install Apache Tomcat 10 on Ubuntu 24.04, follow these steps:
Step 1: Update System
Ensure your system is up-to-date:
sudo apt update
Step 2: Install Java
Tomcat requires Java. Install OpenJDK:
sudo apt install openjdk-17-jdk -y
Verify the installation:
java -version
Step 3: Create a Dedicated Tomcat User
For security, create a non-root user for Tomcat:
sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat
Step 4: Download Tomcat
Download the latest version of Tomcat 10 from the official website. Replace ` with the latest version number (e.g.,10.1.39`):
cd /tmp
wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.39/bin/apache-tomcat-10.1.39.tar.gz
Extract the downloaded file:
sudo tar xzf apache-tomcat-10.1.39.tar.gz -C /opt/tomcat --strip-components=1
Step 5: Set Permissions
Set appropriate ownership and permissions:
sudo chown -R tomcat: /opt/tomcat
sudo chmod +x /opt/tomcat/bin/*.sh
Step 6: Configure Systemd Service
Create a systemd service file for Tomcat:
sudo nano /etc/systemd/system/tomcat.service
Add the following content:
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target
Reload systemd to apply changes:
sudo systemctl daemon-reload
sudo systemctl enable tomcat.service
sudo systemctl start tomcat.service
Check the service status:
sudo systemctl status tomcat.service
Step 7: Access Tomcat
Open your browser and navigate to:
http://public-ip:8080/
You should see the default Apache Tomcat page.
This process ensures a secure and functional installation of Apache Tomcat 10 on Ubuntu 24.04[3][5][7].
Citations:
[1] https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-10-on-ubuntu-20-04
[2] https://www.atlantic.net/dedicated-server-hosting/how-to-install-tomcat-10-on-ubuntu-22-04/
[3] https://tecadmin.net/how-to-install-and-configure-tomcat-on-ubuntu-24-04/
[4] https://www.hostinger.com/tutorials/how-to-install-tomcat-on-ubuntu/
[5] https://www.hostmycode.in/tutorials/how-to-install-apache-tomcat-10-on-ubuntu
[6] https://www.digitalocean.com/community/tutorials/install-tomcat-on-linux
[7] https://www.youtube.com/watch?v=pL7A7DWgEzA
[8] https://ubuntuforums.org/showthread.php?t=2498200
Writing Ansible Playbook for the above
- We have written a playbook which installs java, create a group and system user.
- It also downloads tomcat but extracts incorrectly Refer Here for the changes
Exercise:
- Make this playbook extract tomcat into /opt/tomcat directly rather than
/opt/tomcat/apache-tomcat-10.1.39 - Make this playbook comptabile with redhat/centos
