GeoServer: Difference between revisions
Brian Wilson (talk | contribs) |
Brian Wilson (talk | contribs) mNo edit summary |
||
Line 18: | Line 18: | ||
* 2009 Feb 06 -- I decided to take a crack at installing GeoServer 1.7.2 today. | * 2009 Feb 06 -- I decided to take a crack at installing GeoServer 1.7.2 today. | ||
== | == Example GeoServer site == | ||
The [http://ride.trimet.org/ Portland TriMet system map] is on GeoServer via the [[OpenGeo]] stack. | The [http://ride.trimet.org/ Portland TriMet system map] is on GeoServer via the [[OpenGeo]] stack. | ||
Line 25: | Line 25: | ||
GeoServer, [[OpenLayers]], TileCache, PostgreSQL, PostGIS, GDAL, Extjs, Freemarker, Solr, Antlr, Balance Ant, Http Client, Tomcat, Apache, and CentOS are the underlying technologies used on this application. We're indebted to the contributors of these (and many other: eclipse, firefox and firebug to name a few) open source projects for sharing their efforts and expertise. | GeoServer, [[OpenLayers]], TileCache, PostgreSQL, PostGIS, GDAL, Extjs, Freemarker, Solr, Antlr, Balance Ant, Http Client, Tomcat, Apache, and CentOS are the underlying technologies used on this application. We're indebted to the contributors of these (and many other: eclipse, firefox and firebug to name a few) open source projects for sharing their efforts and expertise. | ||
== GeoServer Capabilities == | == Some GeoServer Capabilities == | ||
* WCS = Web Coverage Service = queryable feature data (OGC) | * WCS = Web Coverage Service = queryable feature data (OGC) | ||
Line 59: | Line 59: | ||
== Status == | == Status == | ||
I have gotten data loaded into PostGIS and published it in GeoServer. | I have gotten data loaded into PostGIS and published it in GeoServer. | ||
Then I need to add the new layer into the map. | Then I need to add the new layer into the map. | ||
== Setting up GeoServer == | == Setting up GeoServer == | ||
The downloadable binary for Linux includes jetty; this precludes the need for Tomcat. | |||
Indeed this is great for testing on a desktop but for any server application, I find that | |||
geoserver/java will eat ram and crash after a few days. | |||
So I install Tomcat and expand the settings to give it lots of space. | |||
=== Tomcat === | |||
I used to install Oracle manually (direct tarball download) and then was forced to install Tomcat | |||
from source, too. Otherwise doing "apt-get install tomcat7" got me an apt packaged outdated java. | |||
Now I first set up the Oracle repo for Java and install it first so that everything can load from apt. | |||
Fix for Debian 8.5, to get the add-apt-repository command (which is an Ubuntu thing) | |||
cd /tmp | cd /tmp | ||
wget http:// | wget http://blog.anantshri.info/content/uploads/2010/09/add-apt-repository.sh.txt | ||
mv add-apt-repository.sh.txt /usr/local/sbin | |||
chmod 755 /usr/local/sbin/add-apt-repository | |||
Now I can install Oracle version 8 JDK as an apt package. | |||
cd | |||
apt-get install python-software-properties | |||
add-apt-repository ppa:webupd8team/java | |||
apt-get update | |||
apt-get install oracle-java8-installer | |||
Now since I have Oracle java installed as a package, I can install the tomcat8 package | |||
and it won't try to install whatever open sourced java it ordinarily installs. It will | |||
be happy to use Oracle's version. | |||
At this point there should be a servlet container running at http://dart.wildsong.biz:8080/ | |||
=== Geoserver === | |||
Download stable release of the WAR file. | |||
. Unpack in /usr/local/geoserver (they suggest /usr/share/geoserver, but that won't get backed up on my server). | |||
Test Geoserver running as yourself | |||
export GEOSERVER_HOME=/usr/local/geoserver | |||
cd $GEOSERVER_HOME | |||
bin/startup.sh | |||
If it works you get tons of logging to your screen and then you can try connecting: | |||
http://dart.wildsong.biz:8080/geoserver/web/ | |||
Assuming you see the generic welcome page you can proceed to make it into a service, I do this with systemd. | |||
I create a file /lib/systemd/system/geoserver.service like this: | |||
I create an environment settings file in /etc/systemd/geoserver.service like this: | |||
[Service] | |||
Environment="JAVA_HOME=/opt/oracle/jdk1.8.0_101" | |||
Environment="RUNJAVA=$JAVA_HOME/bin/java" | |||
Environment="JAVA_OPTS=" | |||
Environment="GEOSERVER_HOME=/usr/local/geoserver" | |||
Environment="GEOSERVER_DATA_DIR=/usr/local/geoserver/data_dir" | |||
''' | ''' | ||
How big is my heap?''' I can see on Hupi it's not enough for Geoserver! | How big is my heap?''' I can see on Hupi it's not enough for Geoserver! |
Revision as of 17:00, 11 September 2016
Overview
GeoServer is the Java based GIS web server that I am using with PostgreSQL and PostGIS for the Mapping Vietnam project
Home page: http://geoserver.org/
"GeoServer is a Java-based software server that allows users to view and edit geospatial data. Using open standards set forth by the Open Geospatial Consortium (OGC), GeoServer allows for great flexibility in map creation and data sharing."
The crucial feature is that it allows edits via WFS-T. Mapserver does not.
WFS-T comments: http://weblogs.java.net/blog/2006/01/09/geoserver-wfs-t
History
- 2016 Sep -- updated Dart with 2.9.1 (latest stable release)
- 2012 Sep -- 2.2 installed on Kilchis and Dart.
- 2011 Oct -- I am working with 2.1.2 now on HuPI
- 2009 Feb 06 -- I decided to take a crack at installing GeoServer 1.7.2 today.
Example GeoServer site
The Portland TriMet system map is on GeoServer via the OpenGeo stack.
This is from the Portland Trimet site... GeoServer, OpenLayers, TileCache, PostgreSQL, PostGIS, GDAL, Extjs, Freemarker, Solr, Antlr, Balance Ant, Http Client, Tomcat, Apache, and CentOS are the underlying technologies used on this application. We're indebted to the contributors of these (and many other: eclipse, firefox and firebug to name a few) open source projects for sharing their efforts and expertise.
Some GeoServer Capabilities
- WCS = Web Coverage Service = queryable feature data (OGC)
- WFS = Web Feature Service = vector data (OGC)
- WMS = Web Map Service = delivers rasters (not tiles) (OGC)
- TMS = Tile map service = delivers raster tiles (OSGEO)
- WMS-C = Web Map Service - Cached = WMS with tile caching (OSGEO draft)
- WMTS = Web Map Tile service (OGC)
I think WCS can return features that are related from several feature classes whereas WFS returns features from one class only??
Map vs feature services
What if you want features to overlay a map but want symbology defined by the server? You define styles and then pick the correct encoding.
With WFS there are several GML flavours, GeoJSON, shapefiles and CSV. None of these work for me because they only encode the geography and not the visual properties. I probably want to use a WMS encoded with KML.
Lew's approach is to convert the KML into a custom JSON format on the server for transfer. There must be a better way than that. But it has to be compatible with the Google Maps Android API too.
The official way to put markers and shapes onto a Google map is via their API. I don't want to go the route of putting shapes onto the screen ignoring the API because I hate having to do all the projection and transformation stuff on my own.
Being able to directly read GPX files would be a good thing.
Tiles
If you are implementing a tile-based client you should probably use TMS or maybe WMTS. WMS-C was a OSGEO draft. WMTS is more complex so use TMS unless you really need WMTS features.
On the server side for performance and the best cartography you'd probably be better off pre-rendering and caching all the tiles. What's the best way to do that? Tilemill or gdal2tiles ? What's the best way to serve the prerendered tiles? TileCache? Or just use a web server (Apache)?
TMS reference implementation: see http://TileCache.org/
Status
I have gotten data loaded into PostGIS and published it in GeoServer.
Then I need to add the new layer into the map.
Setting up GeoServer
The downloadable binary for Linux includes jetty; this precludes the need for Tomcat. Indeed this is great for testing on a desktop but for any server application, I find that geoserver/java will eat ram and crash after a few days.
So I install Tomcat and expand the settings to give it lots of space.
Tomcat
I used to install Oracle manually (direct tarball download) and then was forced to install Tomcat from source, too. Otherwise doing "apt-get install tomcat7" got me an apt packaged outdated java.
Now I first set up the Oracle repo for Java and install it first so that everything can load from apt.
Fix for Debian 8.5, to get the add-apt-repository command (which is an Ubuntu thing)
cd /tmp wget http://blog.anantshri.info/content/uploads/2010/09/add-apt-repository.sh.txt mv add-apt-repository.sh.txt /usr/local/sbin chmod 755 /usr/local/sbin/add-apt-repository
Now I can install Oracle version 8 JDK as an apt package.
apt-get install python-software-properties add-apt-repository ppa:webupd8team/java apt-get update apt-get install oracle-java8-installer
Now since I have Oracle java installed as a package, I can install the tomcat8 package and it won't try to install whatever open sourced java it ordinarily installs. It will be happy to use Oracle's version.
At this point there should be a servlet container running at http://dart.wildsong.biz:8080/
Geoserver
Download stable release of the WAR file. . Unpack in /usr/local/geoserver (they suggest /usr/share/geoserver, but that won't get backed up on my server). Test Geoserver running as yourself
export GEOSERVER_HOME=/usr/local/geoserver cd $GEOSERVER_HOME bin/startup.sh
If it works you get tons of logging to your screen and then you can try connecting:
http://dart.wildsong.biz:8080/geoserver/web/
Assuming you see the generic welcome page you can proceed to make it into a service, I do this with systemd. I create a file /lib/systemd/system/geoserver.service like this:
I create an environment settings file in /etc/systemd/geoserver.service like this:
[Service] Environment="JAVA_HOME=/opt/oracle/jdk1.8.0_101" Environment="RUNJAVA=$JAVA_HOME/bin/java" Environment="JAVA_OPTS=" Environment="GEOSERVER_HOME=/usr/local/geoserver" Environment="GEOSERVER_DATA_DIR=/usr/local/geoserver/data_dir"
How big is my heap? I can see on Hupi it's not enough for Geoserver!
java -XX:+PrintFlagsFinal -version 2>&1 | grep -i MaxHeapSize
This shows 256M, but in the tomcat startup file it's set to 128M.
I create a /etc/default/tomcat file containing
# Brian cooked up this file from the original written for tomcat6 TOMCAT_GROUP=tomcat TOMCAT_USER=tomcat # 2011-Nov-01 bwilson --Geoserver is hungry for more RAM!!! JAVA_OPTS="-Djava.awt.headless=true -Xmx512m -XX:+UseConcMarkSweepGC" JAVA_HOME="/usr/local/java/jre1.6.0_29" JVM_TMP=/tmp/tomcat7-temp
I make a startup file in /etc/init.d based on an existing one.
#!/bin/sh # # /etc/init.d/tomcat7 -- startup script for the Tomcat servlet engine # # Brian hacked this version to run Tomcat 7 # # Written by Miquel van Smoorenburg <[email protected]>. # Modified for Debian GNU/Linux by Ian Murdock <[email protected]>. # Modified for Tomcat by Stefan Gybas <[email protected]>. # Modified for Tomcat6 by Thierry Carrez <[email protected]>. # Additional improvements by Jason Brittain <[email protected]>. # ### BEGIN INIT INFO # Provides: tomcat7 # Required-Start: $local_fs $remote_fs $network # Required-Stop: $local_fs $remote_fs $network # Should-Start: $named # Should-Stop: $named # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start Tomcat. # Description: Start the Tomcat servlet engine. ### END INIT INFO set -e PATH=/bin:/usr/bin:/sbin:/usr/sbin NAME=tomcat DESC="Tomcat servlet engine" DEFAULT=/etc/default/$NAME JVM_TMP=/tmp/tomcat-temp if [ `id -u` -ne 0 ]; then echo "You need root privileges to run this script" exit 1 fi # Make sure tomcat is started with system locale if [ -r /etc/default/locale ]; then . /etc/default/locale export LANG fi . /lib/lsb/init-functions if [ -r /etc/default/rcS ]; then . /etc/default/rcS fi # The following variables can be overwritten in $DEFAULT # Run Tomcat as this user ID and group ID TOMCAT_USER=tomcat TOMCAT_GROUP=tomcat # The first existing directory is used for JAVA_HOME (if JAVA_HOME is not # defined in $DEFAULT or in the environment) #JDK_DIRS="/usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm" # Look for the right JVM to use #for jdir in $JDK_DIRS; do # if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then # JAVA_HOME="$jdir" # fi #done # Directory where the Tomcat binary distribution resides CATALINA_HOME=/usr/local/$NAME # Directory for per-instance configuration files and webapps # This would be in /var/lib/tomcat6 if this were a Debian package CATALINA_BASE=/usr/local/$NAME # Use the Java security manager? (yes/no) TOMCAT_SECURITY=no # Default Java options # Set java.awt.headless=true if JAVA_OPTS is not set so the # Xalan XSL transformer can work without X11 display on JDK 1.4+ # It also looks like the default heap size of 64M is not enough for most cases # so the maximum heap size is set to 128M if [ -z "$JAVA_OPTS" ]; then JAVA_OPTS="-Djava.awt.headless=true -Xmx128M" fi # End of variables that can be overwritten in $DEFAULT # overwrite settings from default file if [ -f "$DEFAULT" ]; then . "$DEFAULT" fi export JAVA_HOME if [ ! -f "$CATALINA_HOME/bin/bootstrap.jar" ]; then log_failure_msg "$NAME is not installed" exit 1 fi POLICY_CACHE="$CATALINA_BASE/work/catalina.policy" if [ -z "$CATALINA_TMPDIR" ]; then CATALINA_TMPDIR="$JVM_TMP" fi # Set the JSP compiler if set in the tomcat6.default file if [ -n "$JSP_COMPILER" ]; then JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=\"$JSP_COMPILER\"" fi SECURITY="" if [ "$TOMCAT_SECURITY" = "yes" ]; then SECURITY="-security" fi # Define other required variables CATALINA_PID="/var/run/$NAME.pid" CATALINA_SH="$CATALINA_HOME/bin/catalina.sh" # Look for Java Secure Sockets Extension (JSSE) JARs if [ -z "${JSSE_HOME}" -a -r "${JAVA_HOME}/jre/lib/jsse.jar" ]; then JSSE_HOME="${JAVA_HOME}/jre/" fi catalina_sh() { # Escape any double quotes in the value of JAVA_OPTS JAVA_OPTS="$(echo $JAVA_OPTS | sed 's/\"/\\\"/g')" AUTHBIND_COMMAND="" if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true" AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c " fi # Define the command to run Tomcat's catalina.sh as a daemon # set -a tells sh to export assigned variables to spawned shells. TOMCAT_SH="set -a; JAVA_HOME=\"$JAVA_HOME\"; source \"$DEFAULT\"; \ CATALINA_HOME=\"$CATALINA_HOME\"; \ CATALINA_BASE=\"$CATALINA_BASE\"; \ JAVA_OPTS=\"$JAVA_OPTS\"; \ CATALINA_PID=\"$CATALINA_PID\"; \ CATALINA_TMPDIR=\"$CATALINA_TMPDIR\"; \ LANG=\"$LANG\"; JSSE_HOME=\"$JSSE_HOME\"; \ cd \"$CATALINA_BASE\"; \ \"$CATALINA_SH\" $@" if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then TOMCAT_SH="'$TOMCAT_SH'" fi # Run the catalina.sh script as a daemon set +e touch "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out chown $TOMCAT_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out start-stop-daemon --start -b -u "$TOMCAT_USER" -g "$TOMCAT_GROUP" \ -c "$TOMCAT_USER" -d "$CATALINA_TMPDIR" -p "$CATALINA_PID" \ -x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH" status="$?" set +a -e return $status } case "$1" in start) if [ -z "$JAVA_HOME" ]; then log_failure_msg "no JDK found - please set JAVA_HOME" exit 1 fi if [ ! -d "$CATALINA_BASE/conf" ]; then log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE" exit 1 fi log_daemon_msg "Starting $DESC" "$NAME" if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ --user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \ >/dev/null; then # Regenerate POLICY_CACHE file umask 022 echo "// AUTO-GENERATED FILE from $CATALINA_BASE/conf/policy.d/" > "$POLICY_CACHE" echo "" >> "$POLICY_CACHE" cat $CATALINA_BASE/conf/policy.d/*.policy \ >> "$POLICY_CACHE" # Remove / recreate JVM_TMP directory rm -rf "$JVM_TMP" mkdir -p "$JVM_TMP" || { log_failure_msg "could not create JVM temporary directory" exit 1 } chown $TOMCAT_USER "$JVM_TMP" catalina_sh start $SECURITY sleep 5 if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ --user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \ >/dev/null; then if [ -f "$CATALINA_PID" ]; then rm -f "$CATALINA_PID" fi log_end_msg 1 else log_end_msg 0 fi else log_progress_msg "(already running)" log_end_msg 0 fi ;; stop) log_daemon_msg "Stopping $DESC" "$NAME" set +e if [ -f "$CATALINA_PID" ]; then start-stop-daemon --stop --pidfile "$CATALINA_PID" \ --user "$TOMCAT_USER" \ --retry=TERM/20/KILL/5 >/dev/null if [ $? -eq 1 ]; then log_progress_msg "$DESC is not running but pid file exists, cleaning up" elif [ $? -eq 3 ]; then PID="`cat $CATALINA_PID`" log_failure_msg "Failed to stop $NAME (pid $PID)" exit 1 fi rm -f "$CATALINA_PID" rm -rf "$JVM_TMP" else log_progress_msg "(not running)" fi log_end_msg 0 set -e ;; status) set +e start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ --user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \ >/dev/null 2>&1 if [ "$?" = "0" ]; then if [ -f "$CATALINA_PID" ]; then log_success_msg "$DESC is not running, but pid file exists." exit 1 else log_success_msg "$DESC is not running." exit 3 fi else log_success_msg "$DESC is running with pid `cat $CATALINA_PID`" fi set -e ;; restart|force-reload) if [ -f "$CATALINA_PID" ]; then $0 stop sleep 1 fi $0 start ;; try-restart) if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \ --user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \ >/dev/null; then $0 start fi ;; *) log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}" exit 1 ;; esac exit 0
Once you have Tomcat running you can move on to getting Geoserver set up.
Geoserver 2.2
Setting up Geoserver is very easy, download the files and put them in the webapps directory. Use the Tomcat manager page to start it.
cd /usr/local/java/tomcat/webapps wget http://downloads.sourceforge.net/geoserver/geoserver-2.2-war.zip unzip geoserver-2.2-war.zip
Once it is there, Tomcat will notice it and start it up. Once started you can access it here
http://bellman:8080/geoserver/
Change admin password now.
You have to look up the one that was created for you when geoserver.war ran the first time. It is in geoserver/data/security/masterpw.info Login as root in the browser and change it now.
This is new in 2.2, in 2.1 there was a default password and you had to edit a file to change it.
Next I have to set up my own workspace to serve my PostGIS data.
Need to fix
/opt/apache/tomcat/webapps/geoserver/data/gwc-layers
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Connecting GeoServer to PostGIS
Some notes on using WFS-T http://blogs.law.harvard.edu/jreyes/2007/08/03/geotools-wfs-t-update-request/
GeoServer has
- workspaces aka namespaces
- stores aka datastores
- layers
These are about organizing the data accessible to GeoServer.
You store data in stores and a store has to be in a workspace. A PostGIS store connects to a database, and the tables therein become accessible as layers (once you publish them)
So you can create a workspace for Oregon and then put all your state-level data into stores that are in the Oregon workspace.
To create a connection to data in your PostGIS server you have to know what's in there. You can poke around with psql if you are text kind of guy or you can use pgAdmin III, like so: