User:Kodapan/Howto mod tile

From OpenStreetMap Wiki
Jump to navigation Jump to search

This is old stuff, kept for historic reasons. Since the switch2osm-packages it makes very little sense to attempt this installation.

This is a composite of several howtos I followed and things I had to do in order to setup a slippy map using OSM data served by mod_tile. I'm using specific revisions of everything for your convenience.

In my environment this is running on a VirtualBox with 2TB dynamically growing disk, 4096MB RAM and 12 CPUs.

Ubuntu

You need a 64 bit distro for this to work!

Download ubuntu-11.10-desktop-amd64.iso and install from scratch. My first user is called osm, you call it whatever you want but if you do you can't copy and paste from the texts below without encountering problems.

Prerequisites

sudo apt-get install git-core subversion

PostgreSQL


sudo apt-get install postgresql-9.1-postgis postgresql-contrib-9.1 postgresql-server-dev-9.1

sudo sysctl -w kernel.shmmax=268435456
cat > 30-postgresql-shm.conf.diff 
7,8c7
< #kernel.shmmax = 33554432
< 
---
> kernel.shmmax = 268435456  # Max shared memory 256MB
^C
sudo patch -p0 /etc/sysctl.d/30-postgresql-shm.conf < 30-postgresql-shm.conf.diff


cat > postgresql.conf.diff
109c109
< shared_buffers = 24MB			# min 128kB
---
> shared_buffers = 128MB			# min 128kB
119c119
< #maintenance_work_mem = 16MB		# min 1MB
---
> maintenance_work_mem = 256MB		# min 1MB
174c174
< #checkpoint_segments = 3		# in logfile segments, min 1, 16MB each
---
> checkpoint_segments = 20		# in logfile segments, min 1, 16MB each
431c431
< #autovacuum = on			# Enable autovacuum subprocess?  'on'
---
> autovacuum = off			# Enable autovacuum subprocess?  'on'
^C
sudo patch -p0 /etc/postgresql/9.1/main/postgresql.conf < postgresql.conf.diff

/etc/init.d/postgresql restart
sudo su postgres
createuser -s osm
createdb -O osm osm

echo "CREATE EXTENSION hstore;"  | psql -d osm
psql -d osm -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql 
echo "ALTER TABLE geometry_columns OWNER TO osm; ALTER TABLE spatial_ref_sys OWNER TO osm;"  | psql -d osm

wget http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/900913.sql
psql -f 900913.sql osm


Mapnik

This is Mapnik 2.n

sudo apt-get install -y g++ cpp \
  libicu-dev \
  libboost-filesystem-dev \
  libboost-program-options-dev \
  libboost-python-dev libboost-regex-dev \
  libboost-system-dev libboost-thread-dev \
  python-dev libxml2 libxml2-dev \
  libfreetype6 libfreetype6-dev \
  libjpeg-dev \
  libltdl7 libltdl-dev \
  libpng-dev \
  libgeotiff-dev libtiff-dev libtiffxx0c2 \
  libcairo2 libcairo2-dev python-cairo python-cairo-dev \
  libcairomm-1.0-1 libcairomm-1.0-dev \
  ttf-unifont ttf-dejavu ttf-dejavu-core ttf-dejavu-extra \
  git build-essential python-nose \
  libgdal1-dev python-gdal libsqlite3-dev

I used a revision from march 2012, a later one might work.

git clone https://github.com/mapnik/mapnik.git
cd mapnik
git checkout -b kodapan 926404d9aead # checkout version from 2012-03-12 
./configure
make # -j 12
sudo make install

No errors should be reported when importing mapnik from python!

Install file: "fonts/unifont-5.1.20080907.ttf" as "/usr/local/lib/mapnik/fonts/unifont-5.1.20080907.ttf"
scons: done building targets.

osm@osm:~/mapnik$ python
Python 2.7.2+ (default, Oct  4 2011, 20:06:09) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mapnik;
>>> 
osm@osm:~/mapnik$ 

osm2pgsql

sudo apt-get install build-essential libxml2-dev libgeos-dev libpq-dev libbz2-dev proj libtool automake libprotobuf-c0-dev

When documenting this I was at revision 28086.

svn co -r 28086 http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/
cd osm2pgsql
./autogen.sh
./configure

Optionally, you can configure the compiler to produce a faster binary that can only run on CPUs that have the same capabilities as yours.

sed -i 's/-g -O2/-O2 -march=native -fomit-frame-pointer/' Makefile

Finally make it.

make # -j 12 # CPUs


OSM data

svn co -r 28086 http://svn.openstreetmap.org/applications/rendering/mapnik osm-mapnik
cd osm-mapnik
./get-costlines.sh

Download the osm.bz2 data that you want to support from cloudmade or what not.

wget http://downloads.cloudmade.com/europe/northern_europe/sweden/sweden.osm.bz2

Finally import data to database. (This will bunzip file using one thread and import data using another.)

cd ~/osm2pgsql
bunzip2 -c ../osm-mapnik/sweden.osm.bz2 | ./osm2pgsql -U osm -d osm /dev/stdin

Reading in file: /dev/stdin
Processing: Node(10744k 124.9k/s) Way(887k 10.08k/s) Relation(10112 306.42/s)  parse time: 207s
All indexes on  planet_osm_line created  in 57s
Completed planet_osm_line

Osm2pgsql took 328s overall
sudo apt-get install python-lxml
./generate_xml.py --dbname osm --user osm --accept-none
upgrade_map_xml.py osm.xml osm-mapnik2.xml

Apache and mod_tile

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

sudo echo ServerName tile.domain.tld > /etc/apache2/http.conf

sudo apt-get install libagg-dev

svn co -r 28086 http://svn.openstreetmap.org/applications/utils/mod_tile
cd mod_tile
./autogen
./configure
cat > gen_tile.cpp.patch
0a1
> #include <mapnik/config_error.hpp>
^C

patch -p0 gen_title.cpp < gen_title.cpp.patch
make
sudo make install

For me "nothing happends" as I executed make install, however it produced file .libs/mod_tile.so which I copied to /usr/lib/apache2/modules

sudo cp .libs/mod_tile.so /usr/lib/apache2/modules

After successful make install of mod_tile:

sudo bash -c "echo 'LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so' > /etc/apache2/mods-available/tile.load"
sudo a2enmod tile
sudo /etc/init.d/apache2 restart

cat > default.patch
3a4,10
> 	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
> 
^C
sudo patch -p0 /etc/apache2/sites-available/default < default.patch


cat > /etc/renderd.conf 
[renderd]
num_threads=10
socketname=/tmp/osm-renderd
stats_file=/var/run/renderd/renderd.stats

[mapnik]
plugins_dir=/usr/local/lib/mapnik/input
font_dir=/usr/local/lib/mapnik/fonts
font_dir_recurse=1

[default]
URI=/osm_tiles2/
XML=/home/osm/osm-mapnik/osm-mapnik2.xml
HOST=tile.domain.tld
^C

sudo mkdir /var/run/renderd
sudo chown osm /var/run/renderd

sudo mkdir /var/lib/mod_tile
sudo chown osm /var/lib/mod_tile


./renderd -f
sudo cat > /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>
^C

Open a webbrowser to http://localhost/map.html

Sources

http://wiki.openstreetmap.org/wiki/HowTo_mod_tile

http://web.archive.org/web/20101029041824/http://weait.com/content/build-your-own-openstreetmap-server

https://github.com/mapnik/mapnik/wiki/UbuntuInstallation

And many more that I forgot... Will try to find them in my history.