wiki:GIS/InstallationGuidelines/Linux

Version 234 (modified by Fran Boon, 3 years ago) ( diff )

--

Installation of GIS Tools on Linux

Suggest these CLI tools for data manipulation:

GDAL

Simple functionality can be got from the Debian package:

apt-get install gdal-bin

Advanced functionality requires the latest version (install into /usr/local):

apt-get install -y g++ libproj-dev
cd /tmp
wget http://download.osgeo.org/gdal/1.11.4/gdal-1.11.4.tar.gz
tar zxvf gdal-1.11.4.tar.gz
cd gdal-1.11.4
./configure --with-python CPPFLAGS="-fPIC"
make
make install
cd ..
ldconfig

Python bindings (e.g. needed for Shapefile Layers and GADM importer) included in above version.

e.g. If you are serving GeoTIFFs larger than 2Gb, you should create an Image Pyramid:

mkdir pyramid
~/gdal-1.11.2/swig/python/scripts/gdal_retile.py -v -s_srs EPSG:4326 -r bilinear -levels 4 -ps 2048 2048 -co "TILED=YES" -co "COMPRESS=JPEG" -targetDir pyramid mygeotiff.tif

PostGIS

PostGIS adds Spatial storage to PostgreSQL (visit this page to configure PostgreSQL before returning here to continue with the GIS parts)

NB PostGIS in Debian Lenny or Squeeze is rather old - recommend using the version in Wheezy, ideally the upgraded from external packages (native version shown commented):

Wheezy users:

apt-get install -y postgis
su postgres
createuser -s -P gis

createdb -O gis -E UTF8 gis -T template0
#psql -d gis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql
#psql -d gis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql
psql -d gis -f /usr/share/postgresql/9.3/extension/postgis--2.1.7.sql

Squeeze users:

apt-get install -y postgresql-8.4-postgis
su postgres
createuser -s -P gis

createdb -O gis gis
createlang plpgsql -d gis
psql -d gis -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql
psql -d gis -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql

Ubuntu users (Lucid/PostgreSQL 8.4/Post-GIS 1.4) - the paths are slightly different

psql -d gis -f /usr/share/postgresql/8.4/contrib/postgis.sql
psql -d gis -f /usr/share/postgresql/8.4/contrib/spatial_ref_sys.sql

Add Spherical Mercator projection (900913. See http://www.cadmaps.com/gisblog/?p=81 for 54004):

  • Not needed with PostGIS-1.5 :)
    psql gis
    INSERT into spatial_ref_sys (srid, auth_name, auth_srid, srtext, proj4text) values (900913 ,'EPSG',900913,'GEOGCS["WGS 84", DATUM["World Geodetic System 1984", SPHEROID["WGS 84", 6378137.0, 298.257223563,AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], NIT["degree",0.017453292519943295], AXIS["Longitude", EAST], AXIS["Latitude", NORTH],AUTHORITY["EPSG","4326"]], PROJECTION["Mercator_1SP"],PARAMETER["semi_minor", 6378137.0], PARAMETER["latitude_of_origin",0.0], PARAMETER["central_meridian", 0.0], PARAMETER["scale_factor",1.0], PARAMETER["false_easting", 0.0], PARAMETER["false_northing", 0.0],UNIT["m", 1.0], AXIS["x", EAST], AXIS["y", NORTH],AUTHORITY["EPSG","900913"]] |','+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs');
    

Using PostGIS in Sahana

Java

Update: As of version 2.0, a Java Runtime Environment (JRE) is sufficient to run GeoServer. GeoServer no longer requires a Java Development Kit (JDK). Also note, OpenJDK does not work optimally with GeoServer. As of version 2.9, Jave 8 is required.

Install the JAI extensions (improves performance for GeoServer WMS), the downloads available are listed here

64-bit:

cd /usr/lib/jvm/java-sun
wget https://download.java.net/media/jai/builds/release/1_1_3/jai-1_1_3-lib-linux-amd64-jdk.bin
wget https://download.java.net/media/jai-imageio/builds/release/1.1/jai_imageio-1_1-lib-linux-amd64-jdk.bin
sh jai-1_1_3-lib-linux-amd64-jdk.bin
# accept license
export _POSIX2_VERSION=199209
sh jai_imageio-1_1-lib-linux-amd64-jdk.bin
# accept license
rm jai-1_1_3-lib-linux-amd64-jdk.bin
rm jai_imageio-1_1-lib-linux-amd64-jdk.bin

If you installed JRE (sudo sh on Ubuntu)

cd /usr/lib/jvm/java-sun/jre
wget https://download.java.net/media/jai/builds/release/1_1_3/jai-1_1_3-lib-linux-amd64-jre.bin
sh jai-1_1_3-lib-linux-amd64-jre.bin 
#accept licence and replace [yes]
rm jai-1_1_3-lib-linux-amd64-jre.bin

32-bit:

cd /usr/lib/jvm/java-sun
wget https://download.java.net/media/jai/builds/release/1_1_3/jai-1_1_3-lib-linux-i586-jdk.bin
wget https://download.java.net/media/jai-imageio/builds/release/1.1/jai_imageio-1_1-lib-linux-i586-jdk.bin
sh jai-1_1_3-lib-linux-i586-jdk.bin
# accept license
export _POSIX2_VERSION=199209
sh jai_imageio-1_1-lib-linux-i586-jdk.bin
# accept license
rm jai-1_1_3-lib-linux-i586-jdk.bin
rm jai_imageio-1_1-lib-linux-i586-jdk.bin

Apache Tomcat

Tomcat is the recommended way to deploy Java applications. As of GeoServer 2.9, Tomcat 7.0.65 or later is required. We suggest using Tomcat 8.0.x:

apt-get install -y tomcat8 libtcnative-1

# http://docs.geoserver.org/latest/en/user/production/container.html#optimize-your-jvm
# Select appropriate value based on your available RAM
vim /etc/default/tomcat8
JAVA_HOME=/usr/lib/jvm/java-8-oracle
JAVA_OPTS="-Djava.awt.headless=true -Xmx256m -Xms48m -XX:MaxPermSize=128m -XX:SoftRefLRUPolicyMSPerMB=36000 -XX:+UseConcMarkSweepGC"
JAVA_OPTS="-Djava.awt.headless=true -Xmx2g -Xms64m -XX:MaxPermSize=128m -XX:SoftRefLRUPolicyMSPerMB=36000 -XX:+UseConcMarkSweepGC"

# Should be set already:
#vim /etc/init.d/tomcat8
#TOMCAT8_SECURITY=no

# Modify logging
vim /etc/tomcat8/server.xml
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               ...
               ...
               rotatable="false" />

vim /etc/logrotate.d/tomcat8
/var/log/tomcat8/catalina.out /var/log/tomcat8/localhost_access_log..txt {
  copytruncate
  daily
  rotate 7
  compress
  missingok
  create 640 tomcat8 adm
}

/etc/init.d/tomcat8 restart
  • Ubuntu 10.x:
    sudo apt-get install unzip lynx tomcat6 tomcat6-admin libapache2-mod-jk
    vim /etc/libapache2-mod-jk/workers.properties
    workers.java_home=/usr/lib/jvm/java-6-sun
    
    /etc/init.d/tomcat6 restart
    # should see stopping [OK] and starting [OK]
    
    # change some permissions
    cd /var/lib/tomcat6/
    sudo chown -R tomcat6:tomcat6 logs work
    sudo chown tomcat6:tomcat6 /usr/share/tomcat6
    
    # check/change service port - default 8080
    /etc/tomcat6/server.xml
    

Enable access to GeoServer on Port 80 (assuming not using Cherokee):

# if using multiple Tomcats behind a single apache load-balancer
apt-get install apache2-mpm-worker
a2enmod proxy_ajp
a2dissite default

vim /etc/tomcat7/server.xml
# Uncomment these lines (& add the extra options)
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="off" />
# maxThreads here should match the Apache MPM's MaxClients
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" emptySessionPath="true" enableLookups="false" maxThreads="256" connectionTimeout="45000" />

/etc/init.d/tomcat7 restart

vim /etc/apache2/ports.conf
NameVirtualHost *:80
Listen 80

vim /etc/apache2/sites-available/geo
<VirtualHost *:80>
  ServerName geo.eden.sahanafoundation.org
  ServerAdmin webmaster@sahanafoundation.org
  DocumentRoot /var/www

  ProxyPreserveHost on
  # These 2 lines should be disabled in Production
  ProxyPass /geoserver/ ajp://localhost:8009/geoserver/
  ProxyPassReverse /geoserver ajp://localhost:8009/geoserver/
  # These lines should be enabled in Production
  ProxyPass /geoserver/ ajp://localhost:8009/geoserver/gwc
  ProxyPassReverse /geoserver/gwc ajp://localhost:8009/geoserver/gwc
  ProxyPass /geoserver/ ajp://localhost:8009/geoserver/wfs
  ProxyPassReverse /geoserver/wfs ajp://localhost:8009/geoserver/wfs
  ProxyPass /geoserver/ ajp://localhost:8009/geoserver/wms
  ProxyPassReverse /geoserver/wms ajp://localhost:8009/geoserver/wms/

  ErrorLog /var/log/apache2/geo_error.log
  LogLevel warn
  CustomLog /var/log/apache2/geo_access.log combined
</VirtualHost>

a2ensite geo
/etc/init.d/apache2 restart

WMS/WFS

GeoServer

(recommended)

apt-get install -y unzip
cd
wget http://kent.dl.sourceforge.net/project/geoserver/GeoServer/2.9.0/geoserver-2.9.0-war.zip

cd /var/lib/tomcat8/webapps
unzip ~/geoserver-2.9.0-war.zip

/etc/init.d/tomcat8 restart

# Allow time to decompress the .war
/etc/init.d/tomcat8 stop
# Move the data directory somewhere to allow upgrades to happen easily
mkdir /var/gis
mv /var/lib/tomcat8/webapps/geoserver/data /var/gis/geoserver_data
vim /var/lib/tomcat8/webapps/geoserver/WEB-INF/web.xml
<!-- Uncomment -->
<param-name>GEOSERVER_DATA_DIR</param-name>
<param-value>/var/gis/geoserver_data</param-value>

/etc/init.d/tomcat8 restart

vim /etc/iptables.rules
-A INPUT -p tcp --dport 8080 -j ACCEPT

reboot

CSS module:

cd /tmp
wget http://kent.dl.sourceforge.net/project/geoserver/GeoServer%20Extensions/2.9.0/geoserver-2.9.0-css-plugin.zip
cd /var/lib/tomcat8/webapps/geoserver/WEB-INF/lib/
unzip /tmp/geoserver-2.9.0-css-plugin.zip
/etc/init.d/tomcat8 restart

Add fonts:

cp *.ttf /usr/lib/jvm/java-6-sun/jre/lib/fonts
/etc/init.d/tomcat8 restart

GDAL Image Formats (although generally are better off using GDAL to convert to GeoTIFF for serving, if possible):

  • http://docs.geoserver.org/latest/en/user/services/wcs/basics.html
    cd /tmp
    wget https://java.net/downloads/imageio-ext/Releases/1.0.5/native-libraries/linux64/imageio-ext-1.0.5-linux64-base-lib.tar.gz
    mkdir -p /usr/local/lib/imageio-ext
    cd /usr/local/lib/imageio-ext
    tar zxvf /tmp/imageio-ext-1.0.5-linux64-base-lib.tar.gz
    vim /etc/default/tomcat8
    LD_LIBRARY_PATH=/usr/local/lib/imageio-ext
    
    cd /tmp
    wget http://kent.dl.sourceforge.net/project/geoserver/GeoServer%20Extensions/2.9.0/geoserver-2.9.0-gdal-plugin.zip
    cd /var/lib/tomcat8/webapps/geoserver/WEB-INF/lib/
    unzip /tmp/geoserver-2.9.0-gdal-plugin.zip
    /etc/init.d/tomcat8 restart
    

Cache of downloadable (if main site has issues):

http://geo.host.domain:8080/geoserver

Configure:

Upgrades:

/etc/init.d/tomcat8 stop

mv /var/lib/tomcat8/webapps/geoserver ~/geoserver-2.5.1_backup

cd /var/lib/tomcat8/webapps
unzip ~/geoserver-2.9.0-war.zip

/etc/init.d/tomcat8 restart

# Allow time to decompress the .war
/etc/init.d/tomcat8 stop
vim /var/lib/tomcat8/webapps/geoserver/WEB-INF/web.xml
<!-- Uncomment -->
<param-name>GEOSERVER_DATA_DIR</param-name>
<param-value>/var/gis/geoserver_data</param-value>

/etc/init.d/tomcat8 restart

MapServer

OpenStreetMap

Printing

PhantomJS

InstallationGuidelines/PhantomJS

MapFish

For Printing TMS layers, need to compile the Trunk version of the MapFish Print Module & then serve the resultant .war with Tomcat:

  1. Ensure that JAVA_HOME points to a JDK.
  2. Download & build source:
    svn checkout http://www.mapfish.org/svn/mapfish/print/trunk/
    cd trunk
    ./gradlew build
    
  3. Configure Tomcat
    vim /etc/tomcat6/policy.d/04webapps.policy
    permission java.io.FilePermission "/var/lib/tomcat6/webapps/print-servlet-1.2-SNAPSHOT/WEB-INF/classes/logging.properties", "read";
    
    /etc/init.d/tomcat6 restart
    
    vim /etc/apache2/sites-available/print
    
    
    ln -s /etc/apache2/sites-available/print /etc/apache2/sites-enabled/print
    /etc/init.d/apache2 restart
    
  4. Copy the WAR file to your %WEBAPPS% directory:
    cp trunk/build/libs/print-servlet-1.2-SNAPSHOT.war /var/lib/tomcat6/webapps
    
  5. (re)Start Tomcat
  6. Configure the Map URL for Eden to:
  7. Configure %WEBAPPS%\print-servlet-1.2-SNAPSHOT\config.yaml: http://www.mapfish.org/doc/print/configuration.html

Printing can also be done within GeoServer:

The 2.0.x versiondidn't support TMS layers, like OpenStreetMap. @ToDo: Test this latest version.

wget http://gridlock.opengeo.org/geoserver/2.1.x/community-latest/geoserver-2.1-SNAPSHOT-printing-plugin.zip
cd /var/lib/tomcat6/webapps/geoserver/WEB-INF/lib
unzip ~/geoserver-2.1-SNAPSHOT-printing-plugin.zip
/etc/init.d/tomcat6 restart
#wget http://geoserver.org/download/attachments/20938936/printing-data-2.0.x.zip
#cd /usr/local/geoserver-2.0.2/data_dir
#unzip ~/printing-data-2.0.x.zip
#/usr/local/geoserver/bin/shutdown.sh
#/usr/local/geoserver/bin/startup.sh &
  • Configure by editing /var/gis/geoserver_data_dir/printing/config.yaml according to Documentation

Print to Image

Proxy / Cache

A Proxy can cache remote servers &/or do Reprojection or Combination of Layers

If just wanting to cache the WMS served by GeoServer, then it's probably best to use the integrated GeoWebCache:

Alternatives:

NB This can reveal issues such as the max-width limitation on ArcGIS when converting 4326 to 900913:

Apache

vim /etc/apache2/sites-available/proxy
<VirtualHost *:80>
  ServerName proxy.sahanafoundation.org
  ServerAdmin webmaster@sahanafoundation.org
  
  WSGIScriptAlias / /home/mapproxy/etc/config.wsgi
  WSGIDaemonProcess mapproxy user=www-data group=www-data home=/home/mapproxy processes=2 maximum-requests=100
  
  <Location "/">
    Order deny,allow
    Allow from all
    WSGIProcessGroup mapproxy
  </Location>

  ErrorLog /var/log/apache2/proxy_error.log
  LogLevel warn
  CustomLog /var/log/apache2/proxy_access.log combined
</VirtualHost>

mkdir -p /home/mapproxy/var
chown www-data /home/mapproxy/var
a2ensite proxy
/etc/init.d/apache2 force-reload

Cherokee/uWSGI

vim /home/mapproxy/uwsgi.xml
<uwsgi>
    <pythonpath>/home/mapproxy/</pythonpath>
    <app mountpoint="/">
        <script>config</script>
    </app>
    <workers>4</workers>
</uwsgi>

vim /usr/local/etc/cherokee/cherokee.conf
vserver!30!rule!300!encoder!deflate = allow
vserver!30!rule!300!encoder!gzip = allow
vserver!30!rule!300!handler = uwsgi
vserver!30!rule!300!handler!balancer = round_robin
vserver!30!rule!300!handler!balancer!source!10 = 2
vserver!30!rule!300!handler!check_file = 0
vserver!30!rule!300!handler!error_handler = 1
vserver!30!rule!300!handler!pass_req_headers = 1
vserver!30!rule!300!handler!xsendfile = 0
vserver!30!rule!300!match = directory
vserver!30!rule!300!match!directory = /proxy
source!2!env_inherited = 1
source!2!group = mapproxy
source!2!host = 127.0.0.1:59026
source!2!interpreter = /usr/local/bin/uwsgi -s 127.0.0.1:59026 -x /home/mapproxy/uwsgi.xml
source!2!nick = uWSGI 2
source!2!timeout = 300
source!2!type = interpreter
source!2!user = mapproxy

Configuration for TRMM

TRMM Rainfall Monitoring

  • http://mapproxy.org/docs/1.4.0/configuration_examples.html
    vim /home/mapproxy/etc/mapproxy.yaml
    layers:
      - name: TRMM_3B42_V6_DAILY
        title: Rainfall (1 day)
        sources: [TRMM_3B42_V6_DAILY_cache, TRMM_3B42_V6_DAILY]
      - name: TRMM_3B42_V6_10_DAY
        title: Rainfall (10 days)
        sources: [TRMM_3B42_V6_10_DAY_cache, TRMM_3B42_V6_10_DAY]
    caches:
      TRMM_3B42_V6_DAILY_cache:
        grids: [GLOBAL_MERCATOR, global_geodetic_sqrt2]
        sources: [TRMM_3B42_V6_DAILY]
      TRMM_3B42_V6_10_DAY_cache:
        grids: [GLOBAL_MERCATOR, global_geodetic_sqrt2]
        sources: [TRMM_3B42_V6_10_DAY]
    sources:
      TRMM_3B42_V6_DAILY:
        type: wms
        supported_srs: ['EPSG:4326']
        req:
          url: http://gdata2.sci.gsfc.nasa.gov/daac-bin/wms_trmm?
          layers: TRMM_3B42_V6_DAILY
          transparent: true
      TRMM_3B42_V6_10_DAY:
        type: wms
        supported_srs: ['EPSG:4326']
        req:
          url: http://gdata2.sci.gsfc.nasa.gov/daac-bin/wms_trmm?
          layers: TRMM_3B42_V6_10_DAY
          transparent: true
    

UserGuidelines/GIS/Data

Attachments (2)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.