HowTo mod tile

From OpenStreetMap Wiki
Jump to: navigation, search

This is concise setup guide for mod_tile. It is meant as follow-up to Richard Weait's guide for the setup of your own tile server. Not that a lot of this documentation was incorporated into switch2osm.org and improved there.

Prerequisities

  1. Follow http://weait.com/content/build-your-own-openstreetmap-server
  2. You should have already up and running mapnik with map data and tested osm.xml file
  3. The guide is based on Ubuntu 11.4, 64-bit, on an EC2 machine (m1.large). Differences on physical machine and other distros should be minimal.

HowTo

Install some tools

sudo aptitude install apache2 apache2-threaded-dev apache2-mpm-prefork apache2-utils
sudo apt-get install libagg-dev

Get and install mod_tile itself

cd ~/src
git clone https://github.com/openstreetmap/mod_tile.git
cd mod_tile
./autogen.sh
./configure
make
sudo make install
sudo make install-mod_tile # Only needed with recent mod_tile version

Configure mod_tile:

sudo nano /etc/renderd.conf

Edit following lines like this:

plugins_dir=/usr/local/lib/mapnik/input
font_dir=/usr/lib/mapnik/fonts
XML=/home/ubuntu/bin/mapnik/osm.xml
HOST=localhost
sudo mkdir /var/run/renderd
sudo chown ubuntu /var/run/renderd

Configure apache for mod_tile

sudo nano /etc/apache2/conf.d/mod_tile # new file

Add just one line here:

LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so
sudo nano /etc/apache2/sites-available/default

Add following lines to the virtual host (just after admin email line):

LoadTileConfigFile /etc/renderd.conf
ModTileRenderdSocketName /tmp/osm-renderd
# Timeout before giving up for a tile to be rendered
ModTileRequestTimeout 3
# Timeout before giving up for a tile to be rendered that is otherwise missing
ModTileMissingRequestTimeout 30

I would move tile folder from root partition to /mnt which has more space (that's optional)

sudo mkdir /mnt/tiles
sudo ln -s  /mnt/tiles/ /var/lib/mod_tile
sudo chown ubuntu /var/lib/mod_tile

Now start renderd

cd ~/src/mod_tile
./renderd

Note: it does not output anything, just stays to background

Note: *renderd -f* starts deamon in foreground mode, good for troubleshooting. Or you can check out logs like that:

tail -f /var/log/syslog |grep renderd

Probably you want to create basic map html

sudo nano /var/www/map.html
<html> 
  <head> 
    <title>OpenLayers Demo</title>
    <style type="text/css">
      html, body, #basicMap {
          width: 100%;
          height: 100%;
          margin: 0;
      }
    </style>
    <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
    <script>
      function init() {
           var options = {
                projection: new OpenLayers.Projection("EPSG:900913"),
                displayProjection: new OpenLayers.Projection("EPSG:4326"),
                units: "m",
                maxResolution: 156543.0339,
                maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
                                                 20037508.34, 20037508.34),
                numZoomLevels: 20,
                controls: [
                        new OpenLayers.Control.Navigation(),
                        new OpenLayers.Control.PanZoomBar(),
                        new OpenLayers.Control.Permalink(),
                        new OpenLayers.Control.ScaleLine(),
                        new OpenLayers.Control.MousePosition(),
                        new OpenLayers.Control.KeyboardDefaults()
 
                  ]
            };
        map = new OpenLayers.Map("basicMap",options);
        var newL = new OpenLayers.Layer.OSM("Default", "/osm_tiles2/${z}/${x}/${y}.png", {numZoomLevels: 19});
        map.addLayer(newL);
        map.zoomIn();
      }
    </script>
  </head>
  <body onload="init();">
    <div id="basicMap"></div>
  </body>
</html>

Now check out the map, open (fingers crossed!):

http://YOURSERVER/map.html

You should see the map now. If no, check out renderd logs (from the syslog)

Pre-render low zoom level tiles. It will take time - 10-20 hours for full planet

cd ~/src/mod_tile
time ./render_list -m default -a -z 0 -Z 10

Last TODO: create automatic start script for the renderd. This is distro specific.

Server monitoring

It is easiest to use Munin monitoring for your server See http://weait.com/content/monitor-postgresql-database-munin for Munin for Postgresql. Following does this + mod_tile/renderd monitoring.

1.Mod_tile monitoring

sudo ln -s /home/ubuntu/src/mod_tile/munin/* /etc/munin/plugins/
sudo chmod a+x /home/ubuntu/src/mod_tile/munin/*
     

2.Postgres monitoring

sudo aptitude install munin munin-node munin-plugins-extra libdbd-pg-perl
sudo munin-node-configure --shell | sudo sh
sudo service munin-node restart
   

3. Publishing munin via web

 sudo nano /etc/apache2/sites-available/default
               
 Alias /munin/ "/var/cache/munin/www/"
   <Directory "/var/cache/munin/www/">
       Options Indexes MultiViews FollowSymLinks
       AllowOverride None
       Order deny,allow
#        Deny from all
       Allow from 127.0.0.0/255.0.0.0 ::1/128
   </Directory>
                                                                            
sudo /etc/init.d/apache2 restart
sudo -u munin munin-cron

Go to http://YOURHOST/munin/

Note: the stats is public this way. You may want to protect it.

4. add munin-update to crontab

sudo -u munin crontab -e

Add this line:

*/5 * * * *     /usr/bin/munin-cron