Skip to content

Installation (Ubuntu 16.04) [ARCHIVED]

Jonathan Beliën edited this page Apr 17, 2018 · 1 revision

Install a tileserver on Ubuntu 16.04

Warning: These instructions were written for version 3 of "openstreetmap-carto".
Please check instructions for version 4 with Ubuntu 17.04

Requirements

  • Server with at least 4Go RAM
  • Ubuntu 16.04 (obviously)

Just to be sure everything is up to date :

sudo apt update
sudo apt upgrade

And restart your server :

sudo shutdown -r now

Installation

Install required softwares

sudo apt install libboost-all-dev git-core tar unzip wget bzip2 build-essential autoconf libtool \
  libgeos-dev libgeos++-dev libpq-dev libbz2-dev libproj-dev munin-node munin libprotobuf-c0-dev libxml2-dev \
  protobuf-c-compiler libfreetype6-dev libpng12-dev libtiff5-dev libicu-dev libgdal-dev libcairo-dev \
  libcairomm-1.0-dev apache2 apache2-dev libagg-dev liblua5.2-dev ttf-unifont lua5.1 liblua5.1-dev libgeotiff-epsg

sudo apt install postgresql postgresql-contrib postgis postgresql-9.5-postgis-2.2

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt install nodejs
sudo npm install -g carto

sudo apt-get install python-yaml

sudo apt-get install fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted ttf-unifont

Create and set up a database

Warning: Replace <username> by your username in the following command lines.

sudo -u postgres -i

createuser <username>
createdb -E UTF8 -O <username> gis

psql gis
CREATE EXTENSION postgis;
ALTER TABLE geometry_columns OWNER TO <username>;
ALTER TABLE spatial_ref_sys OWNER TO <username>;
\q

exit

Install osm2pgsql

mkdir ~/src && cd ~/src
git clone git://github.com/openstreetmap/osm2pgsql.git
cd osm2pgsql

sudo apt install make cmake g++ libboost-dev libboost-system-dev libboost-filesystem-dev libexpat1-dev \
  zlib1g-dev libbz2-dev libpq-dev libgeos-dev libgeos++-dev libproj-dev lua5.2 liblua5.2-dev

mkdir build && cd build
cmake ..

make

sudo make install

Install Mapnik

sudo apt-get install autoconf apache2-dev libtool libxml2-dev libbz2-dev libgeos-dev libgeos++-dev \
  libproj-dev gdal-bin libgdal1-dev libmapnik-dev mapnik-utils python-mapnik

To check if Mapnik is correctly installed :

python

It'll reply with >>>.

import mapnik

If it replies again with just >>> - that's good \o/.
Press control-d to exit the "python" prompt.

Install mod_tile and renderd

@SomeoneElseOSM made a fork of https://github.com/openstreetmap/mod_tile so it supports Ubuntu 16.04 ; that's that fork we'll use instead of OpenStreetMap original repository.

cd ~/src
git clone git://github.com/SomeoneElseOSM/mod_tile.git
cd mod_tile

./autogen.sh

./configure

make

sudo make install

sudo make install-mod_tile

sudo ldconfig

Loading data

Belgium

mkdir ~/data && cd ~/data
wget http://download.geofabrik.de/europe/belgium-latest.osm.pbf

osm2pgsql --create --slim -C 2500 --number-processes 2 -S ~/src/openstreetmap-carto-be/openstreetmap-carto.style --multi-geometry ~/data/belgium-latest.osm.pbf

Natural Earth

cd ~/src/openstreetmap-carto-be
./scripts/get-shapefiles.py

Setting up the stylesheet

Convert YAML to JSON :

python -c 'import sys, yaml, json; json.dump(yaml.safe_load(sys.stdin), sys.stdout, indent=4, separators=(",", ": "))' < project.mml > project.json.mml
python -c 'import sys, yaml, json; json.dump(yaml.safe_load(sys.stdin), sys.stdout, indent=4, separators=(",", ": "))' < project-fr.mml > project-fr.json.mml
python -c 'import sys, yaml, json; json.dump(yaml.safe_load(sys.stdin), sys.stdout, indent=4, separators=(",", ": "))' < project-nl.mml > project-nl.json.mml
python -c 'import sys, yaml, json; json.dump(yaml.safe_load(sys.stdin), sys.stdout, indent=4, separators=(",", ": "))' < project-de.mml > project-de.json.mml

Compile JSON to Mapnik XML :

carto -a "3.0.0" project.json.mml > mapnik.xml
carto -a "3.0.0" project-fr.json.mml > mapnik-fr.xml
carto -a "3.0.0" project-nl.json.mml > mapnik-nl.xml
carto -a "3.0.0" project-de.json.mml > mapnik-de.xml

Configuration

Apache

Create needed directories :
Warning: Replace <username> by your username in the following command lines.

sudo mkdir /var/lib/mod_tile
sudo chown <username> /var/lib/mod_tile

sudo mkdir /var/run/renderd
sudo chown <username> /var/run/renderd

Create a new mod file :

sudo nano /etc/apache2/mods-available/tile.load

Add this line to tile.load :

LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so

Create a new mod configuration file :

sudo nano /etc/apache2/mods-available/tile.conf

Add these lines to tile.conf :

<IfModule tile_module>
    LoadTileConfigFile /usr/local/etc/renderd.conf
    ModTileRenderdSocketName /var/run/renderd/renderd.sock
    # Timeout before giving up for a tile to be rendered
    ModTileRequestTimeout 0
    # Timeout before giving up for a tile to be rendered that is otherwise missing
    ModTileMissingRequestTimeout 30
</IfModule>

Enable mod_tile and restart Apache :

sudo a2enmod tile
sudo service apache2 restart

renderd

sudo nano /usr/local/etc/renderd.conf

Set the correct number of threads : num_threads=2

Add the following lines :
Set the correct URI and XML path for each one.

[osmbe]
URI=/osmbe/
TILEDIR=/var/lib/mod_tile
XML=/home/ubuntu/src/openstreetmap-carto-be/mapnik.xml
HOST=localhost
TILESIZE=256
MAXZOOM=20
CORS=*

[osmbe-fr]
URI=/osmbe-fr/
TILEDIR=/var/lib/mod_tile
XML=/home/ubuntu/src/openstreetmap-carto-be/mapnik-fr.xml
HOST=localhost
TILESIZE=256
MAXZOOM=20
CORS=*

[osmbe-nl]
URI=/osmbe-nl/
TILEDIR=/var/lib/mod_tile
XML=/home/ubuntu/src/openstreetmap-carto-be/mapnik-nl.xml
HOST=localhost
TILESIZE=256
MAXZOOM=20
CORS=*

[osmbe-de]
URI=/osmbe-de/
TILEDIR=/var/lib/mod_tile
XML=/home/ubuntu/src/openstreetmap-carto-be/mapnik-de.xml
HOST=localhost
TILESIZE=256
MAXZOOM=20
CORS=*

Remove the following lines :

[ajt]
URI=/hot/
TILEDIR=/var/lib/mod_tile
XML=/home/ajtown/src/openstreetmap-carto-AJT/mapnik.xml
HOST=localhost
TILESIZE=256
MAXZOOM=20

Running

Running renderd for the first time (test)

Run renderd in the foreground so you can check everything is running as planned :

renderd -f -c /usr/local/etc/renderd.conf

Go to http://yourserveripaddress/osmbe/0/0/0.png and if you see a map of the world everything is working great !

Press CTRL+C to stop the foreground rendering process.

Running renderd in the background

sudo cp ~/src/mod_tile/debian/renderd.init /etc/init.d/renderd
sudo chmod u+x /etc/init.d/renderd
sudo cp ~/src/mod_tile/debian/renderd.service /lib/systemd/system/

You'll need to edit renderd to set your username in the RUNASUSER parameter :

sudo nano /etc/init.d/renderd

Now you can start the new renderd service :

sudo /etc/init.d/renderd start

To make it start automatically every time:

sudo systemctl enable renderd

Viewing tiles

Pre-Renderings tiles

See Pre Rendering (render_list)


This page is based on http://wiki.openstreetmap.org/wiki/User:SomeoneElse/Ubuntu_1604_tileserver_load by @SomeoneElseOSM.