Wednesday, August 24, 2011

Spatial Wiki 8 - Install GeoServer

This is part 8 on building a Spatial Wiki, we've setup and configured an Amazon EC2 server with MediaWiki, PostgreSQL, and PostGIS.  We've also setup a simple spatial database and connected to it via Quantum GIS.  Now it's time to install and do some initial testing of GeoServer which we'll use to serve our spatial data out to a webpage via OpenLayers.

If you search the web, and via the couple of installs I've done there are number of ways to install and configure GeoServer.  I'm also honestly not sure what is the best one, the but in general I think we want to be running with the official Oracle version of Java, and we want it running via Tomcat so we'll install and configure both of these before hitting GeoServer.

Installing Oracle Java

The official Oracle Java is in a partner repository so you have to add the repository and then install Java, like this:
sudo vi /etc/apt/sources.list

Add this line to the end:
deb http://archive.canonical.com/ lucid partner

Save the file and then update the list of packages and install Java with:
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts

Once Oracle Java is installed you can check the version with:
java -version

You should see something like:
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

If you system has different versions of Java installed (i.e. OpenJDK) you can set the "default" version that the system will use with:
sudo update-alternatives --config java

Installing Tomcat

I've just installed Tomcat using the Ubuntu server setup utility, run the following command and tick the option to install Tomcat:
sudo tasksel --section server

Once Tomcat is installed there are two configuration changes per recommendations in this article:

http://leighspersistentthoughts.wordpress.com/2010/06/17/installing-a-headless-geoserver-on-ubuntu-10-4-on-amazon-web-services/

The fist change I think is just formally enabling what are otherwise defaults:

Edit the follwing file:
sudo vi /etc/default/tomcat6

Uncomment the following lines and save the file.
JAVA_OPTS="-Djava.awt.headless=true -Xmx512m"
TOMCAT6_SECURITY=no

Edit this file:
sudo vi /var/lib/tomcat6/conf/tomcat-users.xml

So it looks like this:
<tomcat-users>
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
-->
  <role rolename="admin"/>
  <role rolename="manager"/>
  <role rolename="tomcat"/>
  <user username="tomcat6" password="secret" roles="admin,manager,tomcat"/>
</tomcat-users>

Restart the tomcat server:
sudo /etc/init.d/tomcat6 restart

Install GeoServer

Download the GeoServer Web Archive (.war) file from:

http://geoserver.org/display/GEOS/Stable

Once the file is downloaded launch the Tomcat manager which will be something like:

http://[your server]:8080/manager/html

Important note: Port 8080 needs to be allowed via the AWS security group for the server. Do this in the AWS Management Console.  See the Server Setup post for more information if needed.

Select the WAR file to upload (geoserver.war) and then click Deploy from the Tomcat Web Application Manager. When complete you will see GeoServer running in the Tomcat manager as shown below.



You will be able to launch the GeoServer web administration interface with an address like:

http://[your server]:8080/geoserver/web

The default admin login for GeoServer is username = admin and password = geoserver

To change the login see notes here:

http://docs.geoserver.org/stable/en/user/gettingstarted/web-admin-quickstart/index.html

The GeoServer web interface looks like the figure below.  You can do "Layer Preview" and preview the various default datasets that were installed with GeoServer.

Enabling Port 80 (optional)

Tomcat (and this GeoServer) by default operate over port 8080 which can sometimes be a problem with firewalls, and if nothing else make the URLs a bit messy.  You can get around this by enabling proxy support in Apache and setting up a proxy equating GeoServer on 8080 to a standard port 80 http request.  The first part is REALLY important, Apache2 needs to be configured to allow the proxies. I restarted after each one, but you can live dangerously and just restart after enabling both.
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo /etc/init.d/apache2 restart

Then edit the Apache configuration file:
sudo vi /etc/apache2/sites-enabled/000-default

And add the following lines to the end, but before the closing tag.
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /geoserver http://localhost:8080/geoserver
ProxyPassReverse /geoserver http://localhost:8080/geoserver

Finally restart Apache again and you will be able to Access GeoServer via a standard http address like:

http://[your server]/geoserver/web

See the next article on Adding a PostGIS Layer to GeoServer.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home