For example environment, we will use an Ubuntu 24.04 LTS, OpenJDK 21, Tomcat 10, Nginx.
1. Update
Update all Ubuntu packages.
$ sudo apt update
$ sudo apt list --upgradable
$ sudo apt upgrade
$ sudo apt autoremove
2. Setup swap
Create swap and make it permanent.
$ sudo fallocate -l 4G /swapfile
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
$ sudo swapon /swapfile
$ sudo swapon --show
$ echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Change swapiness.
$ sudo cat /proc/sys/vm/swappiness
$ sudo echo "vm.swappiness = 10" | sudo tee -a /etc/sysctl.d/99-swappiness.conf
$ sudo sysctl -p
$ sudo sysctl vm.swappiness=10
3. Java Installation
The application requires JDK 21 to be installed.
$ sudo apt install openjdk-21-jdk
4. Installation and configuration of Tomcat
We need a separate user to run Tomcat service and base directory to deploy the application.
$ sudo groupadd timvero
$ sudo useradd -s /bin/false -g timvero -d /opt/pumpkin pumpkin
Now we can install Tomcat and apply base directory.
$ sudo apt install tomcat10-user
$ sudo tomcat10-instance-create -p 8080 -c 8005 /opt/pumpkin
Add Valve to /opt/pumpkin/conf/server.xml
.
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="x-forwarded-for"
protocolHeader="x-forwarded-proto" />
5. Redis sessions
Copy this libraries to /opt/pumpkin/lib/
Add Redisson configuraton file /opt/pumpkin/conf/redisson.yaml
singleServerConfig:
address: "redis://127.0.0.1:6379"
database: 1
password: ___REDIS_PASSWORD___
connectionMinimumIdleSize: 10
threads: 0
nettyThreads: 0
And add to /opt/pumpkin/conf/context.xml
<Manager className="org.redisson.tomcat.RedissonSessionManager"
configPath="${catalina.base}/conf/redisson.yaml"
readMode="REDIS" updateMode="DEFAULT" broadcastSessionEvents="false"
keyPrefix=""/>
6. Basic application settings
Create the application configuration file /opt/pumpkin/conf/application.properties
#host, port, and database name
dataSource.url=jdbc:postgresql://<host>:<port>/<database>#database username
dataSource.username=
dataSource.password=
application.serverMode=true
application.home=/opt/timvero
7. Application home
Create the application home folder for work and temporary files.
$ sudo mkdir /opt/timvero
$ sudo mkdir /opt/timvero/hbm2ddl/
$ sudo chmod -R 660 /opt/timvero
$ sudo chown -R pumpkin:timvero /opt/timvero
$ sudo chmod -R 774 /opt/pumpkin
$ sudo chown -R pumpkin:timvero /opt/pumpkin
8. Service
Create system service configuration file /etc/systemd/system/pumpkin.service
.
[Unit]
Description=Main Timvero Application
After=network.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64"
Environment="CATALINA_BASE=/opt/pumpkin"
Environment="CATALINA_HOME=/opt/pumpkin"
Environment="CATALINA_PID=/opt/pumpkin/temp/tomcat.pid"
Environment="CATALINA_OPTS=-server"
Environment="JAVA_OPTS=-Xms512M -Xmx1G -Dspring.config.additional-location=/opt/pumpkin/conf/application.properties"
ExecStart=/opt/pumpkin/bin/startup.sh
ExecStop=/opt/pumpkin/bin/shutdown.sh
User=pumpkin
Group=timvero
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
And apply it.
$ sudo systemctl daemon-reload
$ sudo systemctl enable pumpkin.service
9. Database
Create database, user and grant permissions.
CREATE DATABASE pumpkin;
CREATE USER pumpkin WITH ENCRYPTED PASSWORD '******';
ALTER DATABASE pumpkin OWNER TO pumpkin;
10. Proxy configuration
In case of reverse proxy presents the application requires correct headers forwarding. Here is example location for Nginx server.
# Example proxy configuration
location / {
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header x-forwarded-for $remote_addr;
proxy_set_header x-forwarded-host $host;
proxy_set_header x-forwarded-proto "https";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Origin $http_origin;
# Tomcat host and port
proxy_pass http://127.0.0.1:8080;
}
11. User for deployment
Create user.
$ sudo adduser --disabled-password deploy
$ sudo usermod -g timvero deploy
Generate new private and public key pair. Save public key to user home ~/.ssh/authorized_keys
.
To add service permissions edit /etc/sudoers.d/deploy
.
deploy ALL=(ALL) NOPASSWD:/usr/sbin/service pumpkin *
12. Start application
Upload WAR file to folder /opt/pumpkin/webapps
and start pumpkin
service.