Skip to content

Instantly share code, notes, and snippets.

@karlaking
Last active June 27, 2022 04:56
Show Gist options
  • Save karlaking/6a58279652f6ea23fd085aa5d7822119 to your computer and use it in GitHub Desktop.
Save karlaking/6a58279652f6ea23fd085aa5d7822119 to your computer and use it in GitHub Desktop.

Guide for setting up an AWS linux ec2 instance with GeoServer & PostGIS using Tomcat & Apache.

Update the System

 $ sudo yum update

Install PostgreSQL

Install postgresql, postgresql-devel, and postgresql-libs, and configure data directory and start the service (as the postgres user).

$ sudo yum install postgresql postgresql-server postgresql-devel
$ sudo mkdir /usr/local/pgsql/
$ sudo mkdir /usr/local/pgsql/data
$ sudo chown postgres /usr/local/pgsql/data
$ sudo su postgres

Install GEOS, PROJ, and PostGIS

Install PostGIS. First we install some build tools and the GEOS and PROJ libraries. Then we install PostGIS. After all of them are installed, we update our libraries, so the server knows where to find them. Finally we create a template database for PostGIS.

$ mkdir postgis
$ cd postgis 

Install build tools

$ sudo yum install gcc make gcc-c++ libtool libxml2-devel

Install GEOS

$ wget http://download.osgeo.org/geos/geos-3.6.2.tar.bz2
$ tar xjvf geos-3.6.2.tar.bz2
$ cd geos-3.6.2  
$ ./configure
$ make
$ sudo make install

Install PROJ

$ wget http://download.osgeo.org/proj/proj-4.9.3.tar.gz
$ wget http://download.osgeo.org/proj/proj-datumgrid-1.6.zip
$ tar zxvf proj-4.9.3.tar.gz
$ cd proj-4.9.3/nad/
$ unzip ../../proj-datumgrid-1.6.zip
$ cd ..
$ ./configure
$ make
$ sudo make install

Install PostGIS

postgis-2.4.1 was throwing an error, but I cannot recall what. I reverted to a previous version. I specify the --without-raster tag here, because I do not have or need GDAL on this instance, elsewise the configure process will fail.

$ wget  http://download.osgeo.org/postgis/source/postgis-2.3.1.tar.gz
$ tar zxvf postgis-2.3.1.tar.gz
$ cd postgis-2.3.1
$ ./configure --with-geosconfig=/usr/local/bin/geos-config --without-raster
$ make
$ sudo make install

Update libraries

$ sudo su
$ sudo ldconfig
$ createdb -U postgres template_postgis

Create a template database

$ psql -U postgres -d template_postgis < /usr/share/pgsql92/contrib/postgis-2.3.1/postgis.sql
$ psql -U postgres -d template_postgis < /usr/share/pgsql92/contrib/postgis-2.3/postgis.sql
$ psql -U postgres -d template_postgis < /usr/share/pgsql92/contrib/postgis-2.3/spatial_ref_sys.sql

Update Java

GeoServer 2.12.0 + require Java 8, but current aws Linux boxes still come with Java 7, so we need to update to the latest version.

$ sudo yum install -y java-1.8.0-openjdk.x86_64
$ java -version
$ sudo /usr/sbin/alternatives --set java /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java
$ sudo /usr/sbin/alternatives --set javac /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/javac
$ sudo yum remove java-1.7
$ java -version

Install Apache HTTP Server and Apache Tomcat

Install Apache HTTP Server and Apache Tomcat is very simple. I used tomcat8, though I would have used tomcat9 if I were to do it again.

$ sudo yum install httpd httpd-devel tomcat8

Install GeoServer

Download the GeoServer web archive and move it to Tomcat’s webapps directory.

$ cd
$ mkdir geoserver
$ cd geoserver/
$ wget http://sourceforge.net/projects/geoserver/files/GeoServer/2.12.0/geoserver-2.12.0-war.zip
$ unzip geoserver-2.12.0-war.zip
$ sudo chown tomcat:tomcat geoserver.war
$ sudo mv geoserver.war /var/lib/tomcat8/webapps/

Install mod_jk

$ cd ..
$ mkdir modjk
$ cd modjk/
$ wget https://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.42-src.tar.gz
$ tar xzf tomcat-connectors-1.2.42-src.tar.gz
$ cd tomcat-connectors-1.2.42-src/native/
$ ./configure --with-apxs=/usr/sbin/apxs
$ make
$ sudo make install

Configure Apache HTTP Server

$ sudo vim /etc/httpd/conf/httpd.conf

In Vim, add the following to the bottom of the file:

Load mod_jk module

# Update this path to match your modules location
LoadModule    jk_module  /usr/lib64/httpd/modules/mod_jk.so
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/httpd/conf/workers.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile     /var/log/httpd/mod_jk.shm
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile     /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel    info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# Send everything for context /geoserver and /geoserver/* to worker named geoserver_worker (ajp13)
JkMount  /geoserver/* geoserver_worker
JkMount  /geoserver   geoserver_worker

Create workers.properties

$ sudo vim /etc/httpd/conf/workers.properties

In Vim, add following code:

 # Define the list of workers that will be used
 worker.list=geoserver_worker
 # Define geoserver_worker
 worker.geoserver_worker.port=8009
 worker.geoserver_worker.host=localhost
 worker.geoserver_worker.type=ajp13

Start Apache HTTP Server and Apache Tomcat

At this time, everything is installed and configured, and we are ready to start Apache HTTP Server and Apache Tomcat.

  $ sudo /sbin/service httpd start
  $ sudo /sbin/service tomcat8 start

Reference

This server setup is adapted from this most helpful post. The main differences are version upgrades and the quirks that come with them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment