OSM tile server

Host your own OpenStreet Map server.

Via docker-compose

Vedi anche

  • GitHub - Overv/openstreetmap-tile-server: Docker file for a minimal effort OpenStreetMap tile server 1

  1. follow the Docker instructions

  2. create the jobs directories

    mkdir -p /home/jobs/scripts/by-user/root/docker/osm-tile-server
    mkdir -p /home/jobs/services/by-user/root
    
  3. create the directories for the volumes

    mkdir -p /data/DOCKER_VOLUMES/openstreetmap-tile-server/db
    mkdir -p /data/DOCKER_VOLUMES/openstreetmap-tile-server/openstreetmap-rendered-tiles
    
  4. database must be at least on SSDs to have decent performance, even better if they are on RAID 0. The faster the better: multiple fast NVME drives on RAID 0 with a fast filesystem for flash memory, such as F2FS, would be the best option.

    If a disk breaks you can swap it and re-import the maps since it’s not vital data.

    Mount the filesystems on the SSDs on /data/DOCKER_VOLUMES/openstreetmap-tile-server/db.

    I didn’t see any performace hit in putting the cache on normal HDDs. Put the cache in /data/DOCKER_VOLUMES/openstreetmap-tile-server/openstreetmap-rendered-tiles.

    Nota

    Importing Italy, for example, takes aroung 50GB of space for the database

  5. download the pbf and poly files from geofabrik.de

    cd /data/DOCKER_VOLUMES/openstreetmap-tile-server
    wget https://download.geofabrik.de/europe/italy-latest.osm.pbf
    wget https://download.geofabrik.de/europe/italy.poly
    https://download.geofabrik.de/europe/italy-latest.osm.pbf.md5
    md5sum --check
    
  6. change permissions on the cache directory so that Docker can mount it in the container

    chown 1000:1000 /data/DOCKER_VOLUMES/openstreetmap-tile-server/openstreetmap-rendered-tiles
    
  7. create a Docker compose file

    /home/jobs/scripts/by-user/root/docker/openstreetmap-tile-server/docker-compose.yml
     1version: '3.7'
     2
     3services:
     4  map:
     5    image: overv/openstreetmap-tile-server:v1.8.2
     6    restart: always
     7    shm_size: '8192m'
     8    ports:
     9      - "127.0.0.1:4006:80"
    10    volumes:
    11      - /data/media/DOCKER_VOLUMES/openstreetmap-tile-server/db:/var/lib/postgresql/12/main
    12
    13      # See
    14      # https://github.com/Overv/openstreetmap-tile-server/issues/186
    15      # chown -R 1000:1000 openstreetmap-rendered-tiles
    16      - /data/media/DOCKER_VOLUMES/openstreetmap-tile-server/openstreetmap-rendered-tiles:/var/lib/mod_tile
    17    environment:
    18      - UPDATES=enabled
    19      - THREADS=12
    20      - OSM2PGSQL_EXTRA_ARGS=-C 8192
    21    command: "run"
    22
    23  import:
    24    image: overv/openstreetmap-tile-server:v1.8.2
    25    # Do not start when using "docker-compose up".
    26    # Profiles are compatible with at least docker-compose 1.28
    27    # profiles:
    28    #  - import
    29    restart: 'no'
    30    shm_size: '8192m'
    31    environment:
    32      - UPDATES=enabled
    33    volumes:
    34      - /data/media/DOCKER_VOLUMES/openstreetmap-tile-server/db:/var/lib/postgresql/12/main
    35
    36      # See
    37      # https://github.com/Overv/openstreetmap-tile-server/issues/186
    38      # chown -R 1000:1000 openstreetmap-rendered-tiles
    39      - /data/media/DOCKER_VOLUMES/openstreetmap-tile-server/italy-latest.osm.pbf:/data.osm.pbf
    40      - /data/media/DOCKER_VOLUMES/openstreetmap-tile-server/italy.poly:/data.poly
    41    command: "import"
    
  8. import the data in the database. This operation takes a long time

    cd /home/jobs/scripts/by-user/root/docker/osm-tile-server
    docker-compose up import
    
  9. create a Systemd unit file. See also the Docker compose services section

    /home/jobs/services/by-user/root/docker-compose.openstreetmap-tile-server.service
     1[Unit]
     2Requires=docker.service
     3Requires=network-online.target
     4After=docker.service
     5After=network-online.target
     6
     7[Service]
     8Type=simple
     9WorkingDirectory=/home/jobs/scripts/by-user/root/docker/openstreetmap-tile-server
    10
    11ExecStart=/usr/bin/docker-compose up --remove-orphans map
    12ExecStop=/usr/bin/docker-compose down --remove-orphans
    13
    14Restart=always
    15
    16[Install]
    17WantedBy=multi-user.target
    
  10. fix the permissions

    chmod 700 /home/jobs/scripts/by-user/root/docker/osm-tile-server
    chmod 700 -R /home/jobs/services/by-user/root
    
  11. run the deploy script

  12. connect to http://127.0.0.1:4006 with a JavaScript supported browser. You should see a full screen planet map.

    Rendering is very slow the first time.

    Try zooming into a zone and wait until it’s fully rendered. Reload the browser page with CTRL+shift+R and go to the same zone. This time the rendering should be istantaneous

  13. Add a virtual host in your webserver configuration using port 4006 as reverse proxy

Footnotes

1

https://github.com/Overv/openstreetmap-tile-server.git Apache License, Copyright 2019 Alexander Overvoorde