See http://switch2osm.org/serving-tiles/building-a-tile-server-from-packages/
http://weait.com/content/build-your-own-openstreetmap-server
osm2pgsql
http://wiki.openstreetmap.org/wiki/Osm2pgsql#For_Debian_Lenny_.28stable.29_or_Sid_.28unstable.29_or_Ubuntu_.2810.04_LTS_or_later.29
add-apt-repository ppa:kakrueger/openstreetmap aptitude update sudo aptitude install osm2pgsql
Mapnik
Install Mapnik
aptitude install python-mapnik2
Confirm Mapnik Install
# python >>> import mapnik2 >>>
Openstreetsmap Mapnik (ref)
git clone git://github.com/openstreetmap/mapnik-stylesheets.git
Then…
cd mapnik-stylesheets
Download the mapping data for the country of your choice (or everything from planet.openstreetmap.org) (ref)
wget http://download.geofabrik.de/openstreetmap/australia-oceania/australia.osm.pbf wget http://download.geofabrik.de/openstreetmap/australia-oceania/new-zealand.osm.pbf
Download the additional data-files to be used when generating maps (ref):
wget http://tile.openstreetmap.org/world_boundaries-spherical.tgz # (50 MB)wget http://tile.openstreetmap.org/processed_p.tar.bz2 # (349 MB)
wget http://tile.openstreetmap.org/shoreline_300.tar.bz2 # (44 MB)
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places.zip
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_boundary_lines_land.zip # (39 KB)
Extract the files using the following commands;
cd ~/mapnik-stylesheets # or whatever directory you put the project in tar xzf world_boundaries-spherical.tgz tar xjf processed_p.tar.bz2 -C world_boundaries tar xjf shoreline_300.tar.bz2 -C world_boundaries unzip ne_110m_admin_0_boundary_lines_land.zip -d world_boundaries unzip ne_10m_populated_places.zip -d world_boundaries cd world_boundaries ln -s ne_110m_admin_0_boundary_lines_land.shp 110m_admin_0_boundary_lines_land.shp ln -s ne_110m_admin_0_boundary_lines_land.dbf 110m_admin_0_boundary_lines_land.dbf cd ../
Get the default style
wget http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/default.style
Postgres / PostGIS
Configure / finish setting up PostGIS DB (ref)
sudo apt-get install postgresql-9.1-postgis postgresql-contrib-9.1 sudo -u postgres -i -H createuser -SdR gisuser createdb -E UTF8 -O gisuser gis createlang plpgsql gis psql -d gis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql # to populate the table spatial_ref_sys (mandatory for use with osm2pgsql): psql -d gis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql # common for all three psql gis -c "ALTER TABLE geometry_columns OWNER TO gisuser" psql gis -c "ALTER TABLE spatial_ref_sys OWNER TO gisuser" exit
To enable easy database login by user gisuser you must change some lines in one of the database configuration files.
sudo pico /etc/postgresql/9.1/main/pg_hba.conf
Near to the bottom of the file you will find these lines:
local all all ident host all all 127.0.0.1/32 md5
Change the words ident and md5 each to trust and close the editor. Now reload the database configuration:
sudo /etc/init.d/postgresql reload
For a short test, login to the database by using the previously created database user gisuser:
psql gis gisuser
Type \d to see a list with the two tables which we have created some minutes ago (geometry_columns and spatial_ref_sys), then logout with: \q
Tuning the PostGIS database (ref)
edit /etc/postgresql/9.1/main/postgresql.conf in four places. These changes help with the large quantities of data that we are using.
shared_buffers = 128MB
checkpoint_segments = 20
maintenance_work_mem = 256MB # 256000 for 8.1 and earlier
autovacuum = off
Edit kernel parameter shmmax to increase maximum size of shared memory.
sudo sysctl -w kernel.shmmax=268435456
sudo sysctl -p /etc/sysctl.conf
Restart postgres to enable the changes
sudo /etc/init.d/postgresql restart
It should restart as above.
* Restarting PostgreSQL 8.4 database server ...done.
Import the OSM file for your country (this will take some time)
sudo -u postgres osm2pgsql -d gis -S default.style --slim -m australia.osm.pbf [file2 ...]
Configure Mapnik Style files
./generate_xml.py --host localhost --user gisuser --dbname gis --symbols ./symbols/ --world_boundaries ./world_boundaries/ --accept-none
mod_tile
See: http://switch2osm.org/serving-tiles/building-a-tile-server-from-packages/
http://www.kelvinism.com/howtos/revised-mod_tile-howto/
sudo apt-get install libagg-dev
svn co http://svn.openstreetmap.org/applications/utils/mod_tile
cd mod_tile
make make install
Errors about APXS2 can be cured by installing:
apt-get install apache2-threaded-dev
Then create a load file for the apache module
pico /etc/apache2/mods-available/tile.load
Insert the following:
LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so
Configure mod_tile / renderd
http://wiki.openstreetmap.org/wiki/HowTo_mod_tile
ln -s /home/victor/osm/renderd /var/lib/mod_tile
Download the fonts from http://dejavu.sourceforge.net/wiki/index.php/Download and extract the font files (*.ttf) to /usr/local/lib/mapnik/fonts dir
wget http://downloads.sourceforge.net/project/dejavu/dejavu/2.33/dejavu-fonts-ttf-2.33.tar.bz2?r=http%3A%2F%2Fdejavu-fonts.org%2Fwiki%2Findex.php%3Ftitle%3DDownload&ts=1322024644&use_mirror=internode mv dejavu-fonts-ttf-2.33.tar.bz2\?r\=http\:%2F%2Fdejavu-fonts.org%2Fwiki%2Findex.php\?title\=Download dejavu-fonts.tar.bz2 tar xvf dejavu-fonts.tar.bz2 mv dejavu-fonts-ttf-2.33 /usr/local/lib/mapnik/fonts
Edit /etc/renderd.conf
Create /etc/init.d/renderd with the following contents:
#!/bin/sh -e # Renderd startup script #chkconfig: 2345 80 05 #description: Renderd # Define some variables # Name of app ( abc / def / blah / etc ) APP=renderd # Name of the user to run as USER=www-data # Location of application's bin directory BIN_DIR=/home/www/gis/mod_tile PIDFILE=/var/run/renderd/$APP.pid case "$1" in # Start command start) echo "Starting $APP" /bin/su -m $USER -c "$BIN_DIR/renderd &> /dev/null" ;; # Stop command stop) # echo "Stopping $APP" # echo "$APP stopped successfully" ;; # Restart command restart) $0 stop sleep 5 $0 start ;; *) echo "Usage: /etc/init.d/$APP {start|restart|stop}" exit 1 ;; esac exit 0
Enable auto-updating of the map server