×
Community Blog Deploy Geonode Project with Geoserver, Tomcat8, and PostgreSQL on ECS

Deploy Geonode Project with Geoserver, Tomcat8, and PostgreSQL on ECS

In this tutorial we are going to learn how to deploy a Geonode project on Alibaba Cloud Ubuntu 16.04 ECS instance.

By Grace Amondi, Alibaba Cloud Community Blog author

GeoNode is a web-based application and platform for developing geospatial information systems (GIS) and for deploying spatial data infrastructures (SDI). It is designed to be extended and modified, and can be integrated into existing platforms. It is Developed with Django framework and contains Twitter Bootstrap and jQuery client implementation.

In this tutorial we are going to learn how to deploy a geonode project on an Alibaba Cloud Ubuntu 16.04 Elastic Compute Service (ECS) instance.

Prerequisites

For you to successfully complete this tutorial. you will need to have:

  1. A valid Alibaba Cloud account. If you don't have one already, sign up to the Alibaba Cloud Free Trial.
  2. An ECS instance running Ubuntu 16.04. You can select your preferred region and configurations; this will not affect the outcome of the server setup.
  3. A root password for your server.
  4. Stable Internet connection

Software Package Installation

Assuming you are connected to your instance console, we are going to install all the software packages required in order to run Geonode. Run the following commands to install:

$ sudo apt-get update

$ sudo apt-get install python-virtualenv python-dev libxml2 libxml2-dev libxslt1-dev zlib1g-dev libjpeg-dev libpq-dev libgdal-dev git default-jdk
$ sudo apt-get install build-essential openssh-server gettext nano vim unzip zip patch git-core postfix

$ sudo apt-add-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer

$ sudo apt-add-repository ppa:ubuntugis && sudo apt-get update && sudo apt-get upgrade
$ sudo apt-add-repository ppa:ubuntugis/ppa && sudo apt-get update && sudo apt-get upgrade
$ sudo apt-get install gcc apache2 libapache2-mod-wsgi libgeos-dev libjpeg-dev libpng-dev libpq-dev libproj-dev libxml2-dev libxslt-dev
$ sudo apt-add-repository ppa:ubuntugis/ubuntugis-testing && sudo apt-get update && sudo apt-get upgrade
$ sudo apt-get install gdal-bin libgdal20 libgdal-dev
$ sudo apt-get install python-gdal python-pycurl python-imaging python-pastescript python-psycopg2 python-urlgrabber
$ sudo apt-get install postgresql postgis postgresql-9.5-postgis-scripts postgresql-contrib
$ sudo apt-get install tomcat8

$ sudo apt-get update && sudo apt-get upgrade && sudo apt-get autoremove && sudo apt-get autoclean && sudo apt-get purge && sudo apt-get clean

Installation process may take some time since the packages are being downloaded from the internet. If prompted, please enter the user's password.

Set Up Geonode

This will begin with installing pip, virtualenv and virtualenvwrapper. Run the following commands:

$ sudo apt install python-pip
$ pip install --upgrade pip
$ pip install --user virtualenv
$ pip install --user virtualenvwrapper

Next, we will configure a virtual user environment. Run the following commands:

$ export WORKON_HOME=~/Envs
$ mkdir -p $WORKON_HOME
$ source $HOME/.local/bin/virtualenvwrapper.sh
$ printf '\n%s\n%s\n%s' '# virtualenv' 'export WORKON_HOME=~/Envs' 'source $HOME/.local/bin/virtualenvwrapper.sh' >> ~/.bashrc
$ source ~/.bashrc

With everything in place its time to create a geonode virtual environment. Use the command below:

$ mkvirtualenv --no-site-packages geonode

To activate the new geonode Python Virtual Environment, run the following:

workon geonode

Time to clone geonode repository from github and install python requirements:

$ git clone https://github.com/GeoNode/geonode-project.git
$ pip install Django==1.11.24\
$ django-admin startproject --template=./geonode-project -e py,rst,json,yml,ini,env,sample -n Dockerfile my_geonode

$ cd my_geonode

Finally let's set up python dependencies:

$ pip install -r requirements.txt --upgrade
$ pip install -e . --upgrade

$ GDAL_VERSION=`gdal-config --version`
$ PYGDAL_VERSION="$(pip install pygdal==$GDAL_VERSION 2>&1 | grep -oP '(?<=: )(.*)(?=\))' | grep -oh $GDAL_VERSION\.[0-9])"
$  pip install pygdal==$PYGDAL_VERSION

View geonode on the browser at:

http://<your-ip-addess>:8000/

NB:The default username and password are both admin. Geonode seems to work fine. Let's try uploading a new layer. Notice that the system fails. This is because we have not setup Geoserver.

Set Up PostgreSQL and Geoserver

PostgreSQL

PostgreSQL is relational database management system. It is used to for storage, retrieval and management of the data that comes in through Geonode. To easily install postgresql, go through the following steps:

First create the geonode user. GeoNode is going to use this user to access the database

$ sudo -u postgres createuser -P geonode

You will be prompted asked to set a password for the user. Enter geonode as password. Create geonode database with owner geonode.

$ sudo -u postgres createdb -O geonode geonode

And database geonode_data with owner geonode

$ sudo -u postgres createdb -O geonode geonode_data

Switch to user postgres and create PostGIS extension

$ sudo -u postgres psql -d geonode_data -c 'CREATE EXTENSION postgis;'

Then adjust permissions

$ sudo -u postgres psql -d geonode_data -c 'GRANT ALL ON geometry_columns TO PUBLIC;'
$ sudo -u postgres psql -d geonode_data -c 'GRANT ALL ON spatial_ref_sys TO PUBLIC;'
$ sudo -u postgres psql -d geonode_data -c 'GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO geo

Make changes to the to file pg_hba.conf to change user access policy for local connections.

$ sudo vim /etc/postgresql/9.5/main/pg_hba.conf

Scroll down to the bottom of the document. We only need to edit one line. Change

# "local" is for Unix domain socket connections only
local   all             all                                     peer

Into

# "local" is for Unix domain socket connections only
local   all             all                                     trust

Now restart postgresql for the changes to take effect.

$ sudo service postgresql restart

Geoserver

Geoserver allows you to serve maps and data from a variety of formats to standard clients such as web browsers and desktop GIS programs. It is responsible for exposing data urls to Geonode as well as publishing the layers to Geonode. GeoServer will run inside Tomcat sevrlet container.

Assuming you installed tomcat8 in your system in step 1, stop the running tomcat instance.

$ sudo service tomcat8 stop

Let's now copy the downloaded GeoServer archive inside Tomcat’s webapps folder:

$ sudo cp -Rf /home/geonode/my_geonode/geoserver/geoserver/ /var/lib/tomcat8/webapps/

Transfer GEOSERVER_DATA_DIR on an external location:

$ sudo mkdir -p /data/geoserver-data
$ sudo mkdir -p /data/geoserver-logs
$ sudo mkdir -p /data/gwc_cache_dir
$ sudo cp -Rf /home/geonode/my_geonode/geoserver/data/* /data/geoserver-data/
$ sudo chown -Rf tomcat8: /data/geoserver-data/
$ sudo chown -Rf tomcat8: /data/geoserver-logs/
$ sudo chown -Rf tomcat8: /data/gwc_cache_dir/

Set Java default settings. We need to edit the /etc/default/tomcat8 file:

$ sudo vim /etc/default/tomcat8

Ensure that the file appears as follows:

#JAVA_OPTS="-Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC"
GEOSERVER_DATA_DIR="/data/geoserver-data"
GEOSERVER_LOG_LOCATION="/data/geoserver-logs/geoserver.log"
GEOWEBCACHE_CACHE_DIR="/data/gwc_cache_dir"
GEOFENCE_DIR="$GEOSERVER_DATA_DIR/geofence"

JAVA_OPTS="-Djava.awt.headless=true -XX:MaxPermSize=512m -XX:PermSize=128m -Xms512m -Xmx2048m -Duser.timezone=GMT -Dorg.geotools.shapefile.datetime=true -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ParallelGCThreads=4 -Dfile.encoding=UTF8 -Duser.timezone=GMT -Djavax.servlet.request.encoding=UTF-8 -Djavax.servlet.response.encoding=UTF-8 -DGEOSERVER_DATA_DIR=$GEOSERVER_DATA_DIR -Dgeofence.dir=$GEOFENCE_DIR -DGEOSERVER_LOG_LOCATION=$GEOSERVER_LOG_LOCATION -DGEOWEBCACHE_CACHE_DIR=$GEOWEBCACHE_CACHE_DIR"

NB:Ensure that -Xms512m -Xmx2048m are compatible with your RAM

Catalina Default Settings:

Edit /var/lib/tomcat8/conf/catalina.properties file:

$ sudo vim /var/lib/tomcat8/conf/catalina.properties

Set it up as follows to ensure bcprov*.jar is skipped at run-time:

tomcat.util.scan.StandardJarScanFilter.jarsToSkip=\
...
xom-*.jar,\
bcprov*.jar

Finally restart tomcat service and you should now have tomcat running at port 8080/geoserver

$ sudo service tomcat8 restart

To keep up with the start-up logs, use:

$ sudo tail -F -n 300 /var/lib/tomcat8/logs/catalina.out

Run Geonode

To finalize our setup, let's run geonode by restarting apache:

# IFUsing Default Settings
$ DJANGO_SETTINGS_MODULE=my_geonode.settings paver reset
$ DJANGO_SETTINGS_MODULE=my_geonode.settings paver setup
$ DJANGO_SETTINGS_MODULE=my_geonode.settings paver sync
$ DJANGO_SETTINGS_MODULE=my_geonode.settings paver start

# IF Using Custom Local Settings
$ cp my_geonode/local_settings.py.sample my_geonode/local_settings.py

$ vim my_geonode/wsgi.py
--> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_geonode.local_settings")

$ DJANGO_SETTINGS_MODULE=my_geonode.local_settings paver reset
$ DJANGO_SETTINGS_MODULE=my_geonode.local_settings paver setup
$ DJANGO_SETTINGS_MODULE=my_geonode.local_settings paver sync
$ DJANGO_SETTINGS_MODULE=my_geonode.local_settings paver start
$ sudo service apache2 restart

Now open your browser and go to

http://<your-ip-address>:8000

You should have something similar to this:

1

You can further customize Geonode in the admin panel at http://<your-ip-address>:8000/admin . Go ahead and give it a try.

0 0 0
Share on

Alibaba Clouder

2,599 posts | 762 followers

You may also like

Comments