Tomcat
Tomcat 8.5 installation
Create Tomcat user
sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat
syntax : useradd [OPTIONS] USERNAME
- m : create home directory
- d: specify directory
- s : new user login shell
- U : Create a group with the same name as the user, and add the user to this group
Download Tomcat
- Install wget to download and unzip to extract the Tomcat archive
sudo apt install unzip wget
- Download Tomcat
cd /tmp
wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.55/bin/apache-tomcat-8.5.55.zip
Note :
- https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.55/bin/apache-tomcat-8.5.55.zip
- https://downloads.apache.org/tomcat/tomcat-8/v8.5.55/bin/apache-tomcat-8.5.55.zip
- unzip the file and move it to the /opt/tomcat
unzip apache-tomcat-*.zip
sudo mkdir -p /opt/tomcat
sudo mv apache-tomcat-8.5.55 /opt/tomcat/
- Creating symbolic link (like shortcuts in windows, a file that points to another file/ directory)
sudo ln -s /opt/tomcat/apache-tomcat-8.5.55 /opt/tomcat/latest
Benefit : Later if you want to upgrade your Tomcat installation you can simply unpack the newer version and change the symlink to point to the latest version
- Add owner permissions
sudo chown -R tomcat: /opt/tomcat
- Add executable permissions to the scripts inside bin directory
sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'
- Create a systemd unit (service) file '/etc/systemd/system/tomcat.service'
[Unit]
Description=Tomcat 8.5 servlet container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_OPTS=-Xms1024m -Xmx4096m -XX:PermSize=512m -XX:+UseParallelGC -server -Dhttps.protocols=TLSv1.2 -Doracle.jdbc.timezoneAsRegion=false"
Environment="CATALINA_BASE=/opt/tomcat/latest"
Environment="CATALINA_HOME=/opt/tomcat/latest"
Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms1024M -Xmx4096M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/latest/bin/startup.sh
ExecStop=/opt/tomcat/latest/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
Note : -Doracle.jdbc.timezoneAsRegion=false is added for our oracle timezone issue
- Notify systemd that we created a new unit file
sudo systemctl daemon-reload
- start the Tomcat service
sudo systemctl start tomcat
- check the service status
sudo systemctl status tomcat
- if there are no errors, enable the service to be automatically started at boot time
sudo systemctl enable tomcat
- To allow port 8080
sudo ufw allow 8080/tcp
Configure Tomcat Web Management Interface
- Define Tomcat users and their roles in '/opt/tomcat/latest/conf/tomcat-users.xml'
<tomcat-users>
<!--
Comments
-->
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="admin" password="****" roles="admin-gui,manager-gui"/>
</tomcat-users>
Restart service
sudo systemctl restart tomcat
Test the Installation
http://<your_domain_or_IP_address>:8080
Sample TW specific
Copy 'ojdbc8.jar, HikariCP-3.3.1.jar, postgresql-9.3-1102.jdbc4.jar' to '/opt/tomcat/latest/lib'
give permission to following Catalina folder, so that files can be copied into sub directories
sudo chmod -R 775 /opt/tomcat/latest/conf/Catalina/
Copy ROOTAPP.xml to '/opt/tomcat/latest/conf/Catalina/localhost'
Copy projects like ROOTAPP, TESTPWD1.etc to '/opt/tomcat/latest/webapps'
/opt/tomcat/latest/conf/web.xml -> add tender.jsp to welcome-file-list tag
Specific database URL config must be changed