Hosting your own OSM tiles guarantees independence, performance, and GDPR compliance. This condensed guide goes beyond classic tutorials: it covers installation, performance tuning, security, real-time updates, monitoring, and introduces vector tiles.
Somaire
1. Prerequisites & hardware sizing
Why? Proper sizing avoids slowdowns during import and ensures smooth rendering.
- Ubuntu 24.04 LTS up to date (kernel 6.8).
- Minimum 16 GB RAM (France); 64 GB for Europe; 128 GB for the planet.
- NVMe SSD ≥ 1 TB for import + cache.
- CPU 8 threads+ (osm2pgsql multithread).
2. Step-by-step installation
2.1 Install packages
Why? These packages form the rendering stack (Apache, mod_tile, renderd) and the spatial database (PostgreSQL 16 + PostGIS 3.4).
sudo apt update && sudo apt upgrade -y
sudo apt install apache2 libapache2-mod-tile renderd git wget unzip bzip2
postgresql postgresql-16-postgis-3 postgresql-16-postgis-3-scripts
python3-mapnik mapnik-utils gdal-bin lua5.1 npm node-carto osm2pgsql
2.2 Create the PostGIS database
Why? The gis database stores OSM data and serves Mapnik.
sudo -u postgres createuser _renderd
sudo -u postgres createdb -E UTF8 -O _renderd gis
sudo -u postgres psql -d gis -c "CREATE EXTENSION postgis; CREATE EXTENSION hstore;"
2.3 Download the openstreetmap-carto style
Why? It is the OSM “standard” style, ready for all regions.
git clone https://github.com/gravitystorm/openstreetmap-carto ~/src/osm-carto
cd ~/src/osm-carto && npm install -g carto
carto project.mml > mapnik.xml
2.4 Import OSM data
Why? Populate the database with your regional data.
wget -P ~/data https://download.geofabrik.de/europe/france/alsace-latest.osm.pbf
sudo -u _renderd osm2pgsql -d gis --create --slim -G --hstore
--tag-transform-script ~/src/osm-carto/openstreetmap-carto.lua
-C 75% --number-processes $(nproc)
-S ~/src/osm-carto/openstreetmap-carto.style
~/data/alsace-latest.osm.pbf
2.5 Configure renderd & Apache
Why? Link the rendering engine to the HTTP server.
sudo tee /etc/renderd.conf >/dev/null <<EOF
[renderd]
num_threads=$(nproc) tile_dir=/var/lib/mod_tile stats_file=/run/renderd/stats
[default]
URI=/osm/ XML=/home/$USER/src/osm-carto/mapnik.xml HOST=localhost TILESIZE=256 EOF sudo systemctl enable –now renderd apache2
Test: http://IP/osm/0/0/0.png
3. Optimizations
Why? Reduce rendering time and increase throughput.
- PostgreSQL:
shared_buffers=RAM/4,work_mem=128MB. - Pre-render zooms 0-12:
render_list -a -z 0 -Z 12. - HTTP cache via
Cache-Control: max-age=31536000.
4. Security & Backups
Why? Protect your data and the service.
- UFW: only open 80/443, restrict 5432.
- fail2ban on Apache.
- TLS Let’s Encrypt:
sudo certbot --apache --hsts. - Backups:
pg_dump -Fc gis | rclone copy - s3://bucket/.
5. Automatic Updates
Why? Keep the database in sync with OSM.
sudo -u _renderd osm2pgsql-replication init -d gis
--osm-file ~/data/alsace-latest.osm.pbf
# systemd timer every 5 min
6. Monitoring
Why? Anticipate problems.
- Munin: renderd queue size plugin.
- Prometheus + Grafana for metrics and alerts.
7. Extensions: vector tiles, Docker, Ansible
- Tegola or TileServer-GL for vector tiles.
- Docker image
overv/openstreetmap-tile-serverready to use. - Ansible playbook for idempotent deployment.
Last update: July 2025.