GeoServer Install
In this section, we are going to install the Apache Tomcat 9
Servlet Java container, which, by default, will be started on the internal port 8080
.
We will also perform several optimizations to:
Correctly set up the Java VM Options, like the available heap memory and the garbage collector options.
Externalize the
GeoServer
andGeoWebcache
catalogs in order to allow for further updates without the risk of deleting our datasets.
Note
This is still a basic setup of these components. More details will be provided in sections of the documentation concerning the hardening of the system in a production environment. Nevertheless, you will need to tweak those settings, a bit, in accordance with your current system. For instance, if your machine does not have enough memory, you will need to lower the initial amount of available heap memory. Warnings and notes will be placed below the statements that will require your attention.
Install Apache Tomcat 9 (ref. https://yallalabs.com/linux/ubuntu/how-to-install-apache-tomcat-9-ubuntu-20-04/)
Warning
Apache Tomcat 9 requires Java 8, or newer, to be installed on the server. Check the previous steps, in order to be sure you have OpenJDK 8 correctly installed on your system.
Let’s install Tomcat and edit the default startup script.
sudo apt install tomcat9 -y
sudo vim /etc/systemd/system/tomcat9.service
Edit the startup script with the following content:
[Unit]
Description=Tomcat 9 servlet container
After=network.target
RequiresMountsFor=/var/log/geoserver /opt/data/geoserver_data /opt/data/geoserver_cache
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"
Environment="CATALINA_BASE=/var/lib/tomcat9"
Environment="CATALINA_HOME=/usr/share/tomcat9"
Environment="CATALINA_PID=/var/lib/tomcat9/temp/tomcat.pid"
# Security
ReadWritePaths=/opt/data/geoserver_data
ReadWritePaths=/var/log/geoserver
ReadWritePaths=/opt/data/geoserver_cache
ExecStart=/usr/share/tomcat9/bin/startup.sh
ExecStop=/usr/share/tomcat9/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
Create the Directory Structure and Install Required Packages
## stop running tomcat for GeoServer provisioning
sudo systemctl daemon-reload
sudo systemctl stop tomcat9
## prepare the environment
sudo sed -i -e 's/xom-\*\.jar/xom-\*\.jar,bcprov\*\.jar/g' /var/lib/tomcat9/conf/catalina.properties
sudo touch /usr/share/tomcat9/bin/setenv.sh
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
echo 'JAVA_HOME='$JAVA_HOME | sudo tee --append /usr/share/tomcat9/bin/setenv.sh
sudo sed -i -e "s/JAVA_OPTS=/#JAVA_OPTS=/g" /usr/share/tomcat9/bin/setenv.sh
echo 'GEOSERVER_DATA_DIR="/opt/data/geoserver_data"' | sudo tee --append /usr/share/tomcat9/bin/setenv.sh
echo 'GEOSERVER_LOG_LOCATION="/opt/data/geoserver_logs/geoserver.log"' | sudo tee --append /usr/share/tomcat9/bin/setenv.sh
echo 'GEOWEBCACHE_CACHE_DIR="/opt/data/geoserver_cache"' | sudo tee --append /usr/share/tomcat9/bin/setenv.sh
echo 'GEOFENCE_DIR="$GEOSERVER_DATA_DIR/geofence"' | sudo tee --append /usr/share/tomcat9/bin/setenv.sh
echo 'PRINT_BASE_URL="http://localhost/geoserver/pdf"' | sudo tee --append /usr/share/tomcat9/bin/setenv.sh
echo 'TIMEZONE="UTC"' | sudo tee --append /usr/share/tomcat9/bin/setenv.sh
echo 'JAVA_OPTS="-server -Djava.awt.headless=true -Xms512m -Xmx2048m -Dgwc.context.suffix=gwc -XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=/var/log/jvm.log -Dfile.encoding=UTF8 -Duser.timezone=$TIMEZONE -Djavax.servlet.request.encoding=UTF-8 -Djavax.servlet.response.encoding=UTF-8 -Duser.timezone=GMT -Dorg.geotools.shapefile.datetime=false -DGS-SHAPEFILE-CHARSET=UTF-8 -DGEOSERVER_CSRF_DISABLED=true -DALLOW_ENV_PARAMETRIZATION=true -DGEOSERVER_CSRF_DISABLED=true -DPRINT_BASE_URL=$PRINT_BASE_URL -DGEOSERVER_DATA_DIR=$GEOSERVER_DATA_DIR -Dgeofence.dir=$GEOFENCE_DIR -DGEOSERVER_LOG_LOCATION=$GEOSERVER_LOG_LOCATION -DGEOWEBCACHE_CACHE_DIR=$GEOWEBCACHE_CACHE_DIR"' | sudo tee --append /usr/share/tomcat9/bin/setenv.sh
sudo chown -Rf tomcat:www-data /var/lib/tomcat9/
sudo chown -Rf tomcat:www-data /var/lib/tomcat9/logs/
sudo chown -Rf tomcat:www-data /var/lib/tomcat9/temp/
sudo chown -Rf tomcat:www-data /usr/share/tomcat9/bin/setenv.sh
sudo chmod +x /usr/share/tomcat9/bin/setenv.sh
## make the geoserver directories
sudo mkdir -p /opt/data/geoserver_data
sudo mkdir -p /var/log/geoserver
sudo mkdir -p /opt/data/geoserver_cache
sudo mkdir -p /opt/data/geoserver_logs
## set the directory permissions
sudo chmod 0755 /opt/data/geoserver_data
sudo chmod 2750 /var/log/geoserver
sudo chmod 0750 /opt/data/geoserver_cache
sudo chmod 0750 /opt/data/geoserver_logs
sudo touch /opt/data/geoserver_logs/geoserver.log
sudo touch /var/log/jvm.log
sudo chmod -Rf 777 /var/log/jvm.log
## install the data directory template
cd /opt/data/geoserver_data
sudo wget "https://artifacts.geonode.org/geoserver/2.23.0/geonode-geoserver-ext-web-app-data.zip"
sudo unzip geonode-geoserver-ext-web-app-data.zip
sudo mv data/* .
## set geoserver directory ownership
sudo chown -R tomcat:tomcat /opt/data/geoserver_data
sudo chown -R tomcat:adm /var/log/geoserver
sudo chown -R tomcat:tomcat /opt/data/geoserver_cache
sudo chown -R tomcat:tomcat /opt/data/geoserver_logs
sudo chown -Rf tomcat:tomcat /opt/data/geoserver_logs/geoserver.log
## temporary placeholder for download war file
cd /opt && sudo mkdir -p geoserver && cd geoserver
## install geoserver war
sudo wget "https://artifacts.geonode.org/geoserver/2.23.0/geoserver.war"
sudo mv geoserver.war /var/lib/tomcat9/webapps/geoserver.war
## start Tomcat9
sudo systemctl restart tomcat9
## Follow the startup logs
sudo tail -500f /var/log/tomcat9/catalina.out
sudo tail -500f /opt/data/geoserver_logs/geoserver.log