Forked overv/openstreetmap-tile-server with external database support
 
 
 
 
Go to file
Vitaliy Filippov 28e4e6fda5 Fix updates: Add env var support to tiles-update-expire, remove pam_loginuid, install db_replag 2021-09-06 12:04:00 +03:00
.travis.yml Fix Docker badge URL and update ports in test code 2019-12-27 15:04:21 +01:00
Dockerfile Fix updates: Add env var support to tiles-update-expire, remove pam_loginuid, install db_replag 2021-09-06 12:04:00 +03:00
Makefile Fix Docker badge URL and update ports in test code 2019-12-27 15:04:21 +01:00
README.md Fix updates: Add env var support to tiles-update-expire, remove pam_loginuid, install db_replag 2021-09-06 12:04:00 +03:00
apache.conf Add ALLOW_CORS parameter 2019-08-31 13:44:23 +02:00
docker-compose.yml Change example server port to 8080 and include Docker Compose example 2019-12-22 13:53:12 +01:00
external-data.yml.diff Connect to external postgresql, add retina tiles, change mod_tile to standard 2021-09-04 10:30:33 +03:00
leaflet-demo.html Use osm-retina in public demo 2021-09-04 21:07:15 +03:00
openstreetmap-tiles-update-expire Fix updates: Add env var support to tiles-update-expire, remove pam_loginuid, install db_replag 2021-09-06 12:04:00 +03:00
osm_carto_bright.jpg Example of the included style patch 2021-09-04 21:07:15 +03:00
postgresql.custom.conf.tmpl Fix Postgres not being reachable from outside container 2019-09-22 16:39:56 +02:00
roads.diff Patch osm-carto styles to be brighter and less RED 2021-09-04 21:07:15 +03:00
run.sh Fix updates: Add env var support to tiles-update-expire, remove pam_loginuid, install db_replag 2021-09-06 12:04:00 +03:00
style.diff Patch osm-carto styles to be brighter and less RED 2021-09-04 21:07:15 +03:00

README.md

openstreetmap-tile-server

This container allows you to easily set up an OpenStreetMap PNG tile server given a .osm.pbf file. It is based on the latest Ubuntu 18.04 LTS guide from switch2osm.org and therefore uses the default OpenStreetMap style.

Set up PostgreSQL

  • Create a database
  • Create extensions postgis and hstore within it
  • Create a user and grant him access to the created database
CREATE DATABASE osm;
CREATE USER renderd WITH PASSWORD '<YOUR_PASSWORD>';
GRANT ALL PRIVILEGES ON DATABASE osm TO renderd;
CREATE EXTENSION postgis;
CREATE EXTENSION hstore;

Running the initial import

podman run \
    -it \
    -e PGPASSWORD=<YOUR_PASSWORD> \
    -e PGHOST= \
    -e PGUSER=renderd \
    -e PGPORT=5432 \
    -e PGDB=osm \
    -e DOWNLOAD_PBF=https://download.geofabrik.de/russia-latest.osm.pbf \
    [-e DOWNLOAD_POLY=https://download.geofabrik.de/russia.poly \]
    -e UPDATES=enabled \
    -v /run/postgresql:/run/postgresql \
    -v /home/osm/download:/data \
    -v /home/osm/mod_tile:/var/lib/mod_tile \
    --rm \
    osm \
    import

Running the server

Run the server like this:

podman run \
    -d \
    -e PGPASSWORD=<YOUR_PASSWORD> \
    -e PGHOST= \
    -e PGUSER=renderd \
    -e PGPORT=5432 \
    -e PGDB=osm \
    -e UPDATES=enabled \
    -v /run/postgresql:/run/postgresql \
    -v /home/osm/download:/data \
    -v /home/osm/mod_tile:/var/lib/mod_tile \
    -v /home/osm/logs:/var/log/tiles \
    -v /dev/log:/dev/log \
    -p 8080:80 \
    osm \
    run

Your tiles will now be available at http://localhost:8080/osm/{z}/{x}/{y}.png. The demo map in leaflet-demo.html will then be available on http://localhost:8080. Note that it will initially take quite a bit of time to render the larger tiles for the first time.

UPDATES=enabled will enable a background process that automatically downloads changes from the OpenStreetMap server, filters them for the relevant region polygon you specified, updates the database and finally marks the affected tiles for rerendering.

Cross-origin resource sharing

To enable the Access-Control-Allow-Origin header to be able to retrieve tiles from other domains, simply set the ALLOW_CORS variable to enabled:

podman run \
    -p 8080:80 \
    -v openstreetmap-data:/var/lib/postgresql/12/main \
    -e ALLOW_CORS=enabled \
    -d osm \
    run

Performance tuning and tweaking

Details for update procedure and invoked scripts can be found here link.

POSTGRESQL

https://pgtune.leopard.in.ua

THREADS

The import and tile serving processes use 4 threads by default, but this number can be changed by setting the THREADS environment variable. For example:

podman run \
    -p 8080:80 \
    -e THREADS=24 \
    -v openstreetmap-data:/var/lib/postgresql/12/main \
    -d osm \
    run

CACHE

This image uses 4096 MB RAM cache by default for osm2pgsql, but this number can be changed by option -C. For example:

podman run \
    -p 8080:80 \
    -e "OSM2PGSQL_EXTRA_ARGS=-C 8192" \
    -v openstreetmap-data:/var/lib/postgresql/12/main \
    -d osm \
    run

Flat nodes

If you are planning to import the entire planet or you are running into memory errors then you may want to enable the --flat-nodes option for osm2pgsql. You can then use it during the import process as follows:

podman run \
    -v /absolute/path/to/luxembourg.osm.pbf:/data/data.osm.pbf \
    -v openstreetmap-nodes:/nodes \
    -v openstreetmap-data:/var/lib/postgresql/12/main \
    -e "OSM2PGSQL_EXTRA_ARGS=--flat-nodes /nodes/flat_nodes.bin" \
    osm \
    import

Note that if you use a folder other than /nodes then you must make sure that you manually set the owner to renderer!

Benchmarks

You can find an example of the import performance to expect with this image on the OpenStreetMap wiki.

Troubleshooting

ERROR: could not resize shared memory segment / No space left on device

If you encounter such entries in the log, it will mean that the default shared memory limit (64 MB) is too low for the container and it should be raised:

renderd[121]: ERROR: failed to render TILE osm_retina 2 0-3 0-3
renderd[121]: reason: Postgis Plugin: ERROR: could not resize shared memory segment "/PostgreSQL.790133961" to 12615680 bytes: ### No space left on device

To raise it use --shm-size parameter. For example:

podman run \
    -p 8080:80 \
    -v openstreetmap-data:/var/lib/postgresql/12/main \
    --shm-size="192m" \
    -d osm \
    run

For too high values you may notice excessive CPU load and memory usage. It might be that you will have to experimentally find the best values for yourself.

The import process unexpectedly exits

You may be running into problems with memory usage during the import. Have a look at the "Flat nodes" section in this README.

License

Copyright 2019 Alexander Overvoorde
Copyright 2021 Vitaliy Filippov

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.