Compare commits

...

60 Commits
v1.0 ... v1.3.3

Author SHA1 Message Date
Alexander Overvoorde
ff8655701e Update instructions for flat node usage 2019-09-26 20:09:02 +02:00
Alexander Overvoorde
a2eceb6bb5 Merge pull request #66 from stevo01/master
pull request solves issues #63 #64 #65
2019-09-26 20:06:48 +02:00
Steffen Volkmann
bea77eb8bf Dockerfile: create directory for flatnodes
and change owner of directory to renderer
2019-09-24 11:36:13 +02:00
Steffen Volkmann
33cd142850 make option -C of command osm2psql adjustable 2019-09-24 11:36:13 +02:00
Steffen Volkmann
c5a6462263 add OSM2PGSQL_EXTRA_ARGS to arguments of osm2psql call insight openstreetmap-tiles-update-expire script 2019-09-24 11:36:13 +02:00
Alexander Overvoorde
80586aff5f Fix Postgres not being reachable from outside container 2019-09-22 16:39:56 +02:00
Alexander Overvoorde
b82e37b9b5 Improve compatibility of Apache logging locations 2019-09-17 22:03:03 +02:00
Alexander Overvoorde
451f335bc5 Add ALLOW_CORS parameter 2019-08-31 13:44:23 +02:00
Alexander Overvoorde
8744ab2792 Fix flat nodes explanation 2019-08-22 22:05:45 +02:00
Alexander Overvoorde
31bf2d718b Add a way to enable options like --flat-nodes (fixes #53) 2019-08-20 19:40:24 +02:00
Alexander Overvoorde
fcc6168253 Fix updating by moving to latest version of regional extract tool 2019-08-08 21:39:20 +02:00
Alexander Overvoorde
2313b00d1e Merge pull request #46 from Istador/patch-1
README.md use the named data volume everywhere
2019-07-12 23:28:12 +02:00
Robin C. Ladiges
6834a20707 README.md use the named data volume everywhere 2019-07-11 22:26:18 +02:00
Alexander Overvoorde
4953b4f0c5 Merge pull request #44 from Istador/master
README.md consistent indentation and error in docker run command
2019-07-10 20:52:59 +02:00
Robin C. Ladiges
ce15672ca1 README.md fix: line break after command 2019-07-10 14:09:12 +02:00
Robin C. Ladiges
a21931792a README.md fix: docker run options order
docker run options must be before the image declaration
2019-07-10 14:00:08 +02:00
Robin C. Ladiges
1cca710a02 README.md consistent indentation 2019-07-10 13:58:18 +02:00
Alexander Overvoorde
2be4107bb1 Merge pull request #41 from vpithart/fix-update-script
Fix openstreetmap-tiles-update-expire - libraries for trim_osc.py
2019-07-02 23:15:43 +02:00
Vojtech Pithart
1beb5fb1e8 Fix updater - libraries for trim_osc.py 2019-07-02 13:37:57 +02:00
Alexander Overvoorde
ef1660c22c Merge branch 'stevo01-issue2' 2019-06-19 21:43:26 +02:00
Alexander Overvoorde
f9611b4cd8 Improve clarity of the automatic updating process in the README 2019-06-19 21:40:52 +02:00
Alexander Overvoorde
77e7157807 Merge branch 'issue2' of https://github.com/stevo01/openstreetmap-tile-server into stevo01-issue2 2019-06-18 19:30:07 +02:00
Alexander Overvoorde
4b062b6ce2 Merge pull request #38 from vpithart/fix-container-restarts
Fix: proper startup after docker and/or container restarts
2019-06-18 18:34:41 +02:00
Vojtech Pithart
52d5f0b4b2 Fix: postgresql (not) starts after container restart 2019-06-18 12:55:51 +02:00
Vojtech Pithart
db5f6799f0 Fix: apache (not) starts after container restart 2019-06-18 12:26:15 +02:00
Steffen Volkmann
4e5828e749 error correction wrong usage of environment variable
inside script openstreetmap-tiles-update-expire
2019-06-16 08:34:04 +02:00
Steffen Volkmann
a9392359b9 integration of update and tile expire procedure
see https://ircama.github.io/osm-carto-tutorials/updating-data/

Implements https://github.com/Overv/openstreetmap-tile-server/issues/2
2019-06-16 07:55:13 +02:00
Alexander Overvoorde
9b2b67b076 Add recommended indexes for Carto style (thanks @souladm) 2019-06-14 23:24:11 +02:00
Alexander Overvoorde
d7c2817f9f Extend troubleshooting section 2019-04-26 21:43:07 +02:00
Alexander Overvoorde
554707fc46 Add reference to benchmark by @steveo01 2019-04-23 21:44:26 +02:00
Alexander Overvoorde
564c753011 Fix work_mem being duplicated 2019-04-23 21:40:49 +02:00
Alexander Overvoorde
174bbd5fa2 Update instructions based on new embedded demo map 2019-04-23 21:39:38 +02:00
Alexander Overvoorde
5805f89698 Merge pull request #28 from stevo01/stevo-autovacuum
stevo autovacuum
2019-04-23 21:37:14 +02:00
Alexander Overvoorde
095c3badc3 Merge branch 'master' into stevo-autovacuum 2019-04-23 21:37:06 +02:00
Alexander Overvoorde
2186981cba Merge pull request #25 from pot-gov-pl/master
A lot of changes, please review and choose
2019-04-23 21:36:13 +02:00
Steffen Volkmann
a02daac961 environment variable AUTOVACUUM added
The postgressql autovacuum feature is by default active. The environment variable AUTOVACUUM allows you to switch off this feature during start of docker container.
2019-04-16 07:45:10 +02:00
Grzegorz Adam Kowalski
c99368d160 Info about shared memory error
issue #3
2019-03-19 16:47:57 +01:00
Grzegorz Adam Kowalski
c8f8d0fd71 verify SSL 2019-03-17 20:33:06 +01:00
Grzegorz Adam Kowalski
42b5783486 revert changes 2019-03-17 01:01:52 +01:00
Grzegorz Adam Kowalski
662ce85cb8 turn off autovacuum; fix psql errors 2019-03-16 23:35:15 +01:00
Grzegorz Adam Kowalski
ca32b809ea fix for lost extension scripts 2019-03-16 22:14:41 +01:00
Grzegorz Adam Kowalski
87a5ba0672 Update postgresql.custom.conf 2019-03-15 19:34:38 +01:00
Grzegorz Adam Kowalski
6b1ef3fe22 Update postgresql.custom.conf 2019-03-15 19:29:40 +01:00
Grzegorz Adam Kowalski
ab0f62d08d Custom PostgreSQL conf with minimal settings 2019-03-15 19:20:59 +01:00
Grzegorz Adam Kowalski
ad366e7c87 Fix for wrong ownership of postgres data 2019-03-15 18:33:40 +01:00
Grzegorz Adam Kowalski
1681d33635 forgotten \ 2019-03-15 18:13:02 +01:00
Grzegorz Adam Kowalski
48d257763e redirect apache server logs to stdout & stderr 2019-03-15 17:33:07 +01:00
Grzegorz Adam Kowalski
16b85cb9e2 latest postgres 10; multithread make 2019-03-15 16:50:46 +01:00
Grzegorz Adam Kowalski
7e87c26e0e Removed munin from apt-get 2019-03-14 23:20:06 +01:00
Grzegorz Adam Kowalski
a0728026b2 Remove carto -v as not needed
npm install prints out version anyway
2019-03-14 16:17:49 +01:00
Grzegorz Adam Kowalski
7875c4492e Timezone setup before apt-get tzdata 2019-03-14 15:56:07 +01:00
Grzegorz Adam Kowalski
dbbe98aaed apt-get dependency cleanup 2019-03-14 15:45:25 +01:00
Grzegorz Adam Kowalski
95e5fa8a96 cache-busting
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#apt-get
2019-03-14 12:24:17 +01:00
Grzegorz Adam Kowalski
c8a5c771ac Expose webserver and DB ports 2019-03-14 11:52:16 +01:00
Grzegorz Adam Kowalski
e37c31d2f0 stop postgresql to prevent database corruption 2019-03-14 10:42:58 +01:00
Grzegorz Adam Kowalski
18066e910f Merge pull request #2 from weissdanny/patch-2
Update Dockerfile
2019-03-14 10:22:11 +01:00
Grzegorz Adam Kowalski
2c5368f9bf Merge pull request #1 from weissdanny/patch-1
Update leaflet-demo.html
2019-03-14 10:21:16 +01:00
hhansen06
6d57819daa Update Dockerfile 2019-01-11 20:37:31 +01:00
hhansen06
cefc97edd3 Update leaflet-demo.html 2019-01-11 20:36:30 +01:00
Alexander Overvoorde
67a1bf2ded Clarify that custom .OSM.PBF file path needs to be absolute 2018-05-23 22:29:15 +02:00
8 changed files with 637 additions and 53 deletions

View File

@@ -3,13 +3,76 @@ FROM ubuntu:18.04
# Based on
# https://switch2osm.org/manually-building-a-tile-server-18-04-lts/
# Install dependencies
RUN apt-get update
RUN apt-get install -y libboost-all-dev git-core tar unzip wget bzip2 build-essential autoconf libtool libxml2-dev libgeos-dev libgeos++-dev libpq-dev libbz2-dev libproj-dev munin-node munin libprotobuf-c0-dev protobuf-c-compiler libfreetype6-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
# Set up environment and renderer user
# Set up environment
ENV TZ=UTC
ENV AUTOVACUUM=on
ENV UPDATES=disabled
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# Install dependencies
RUN echo "deb [ allow-insecure=yes ] http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" >> /etc/apt/sources.list.d/pgdg.list \
&& apt-get update \
&& apt-get install -y apt-transport-https ca-certificates \
&& apt-get install -y --no-install-recommends --allow-unauthenticated \
apache2 \
apache2-dev \
autoconf \
build-essential \
bzip2 \
cmake \
fonts-noto-cjk \
fonts-noto-hinted \
fonts-noto-unhinted \
clang \
gdal-bin \
git-core \
libagg-dev \
libboost-all-dev \
libbz2-dev \
libcairo-dev \
libcairomm-1.0-dev \
libexpat1-dev \
libfreetype6-dev \
libgdal-dev \
libgeos++-dev \
libgeos-dev \
libgeotiff-epsg \
libicu-dev \
liblua5.3-dev \
libmapnik-dev \
libpq-dev \
libproj-dev \
libprotobuf-c0-dev \
libtiff5-dev \
libtool \
libxml2-dev \
lua5.3 \
make \
mapnik-utils \
nodejs \
npm \
postgis \
postgresql-10 \
postgresql-10-postgis-2.5 \
postgresql-10-postgis-2.5-scripts \
postgresql-contrib-10 \
protobuf-c-compiler \
python-mapnik \
sudo \
tar \
ttf-unifont \
unzip \
wget \
zlib1g-dev \
osmosis \
osmium-tool \
cron \
python3-psycopg2 python3-shapely python3-lxml \
&& apt-get clean autoclean \
&& apt-get autoremove --yes \
&& rm -rf /var/lib/{apt,dpkg,cache,log}/
# Set up renderer user
RUN adduser --disabled-password --gecos "" renderer
USER renderer
@@ -18,34 +81,30 @@ RUN mkdir /home/renderer/src
WORKDIR /home/renderer/src
RUN git clone https://github.com/openstreetmap/osm2pgsql.git
WORKDIR /home/renderer/src/osm2pgsql
USER root
RUN apt-get install -y 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
USER renderer
RUN mkdir build
WORKDIR /home/renderer/src/osm2pgsql/build
RUN cmake ..
RUN make
RUN cmake .. \
&& make -j $(nproc)
USER root
RUN make install
RUN mkdir /nodes \
&& chown renderer:renderer /nodes
USER renderer
# Install and test Mapnik
USER root
RUN apt-get -y install autoconf apache2-dev libtool libxml2-dev libbz2-dev libgeos-dev libgeos++-dev libproj-dev gdal-bin libmapnik-dev mapnik-utils python-mapnik
USER renderer
RUN python -c 'import mapnik'
# Install mod_tile and renderd
WORKDIR /home/renderer/src
RUN git clone -b switch2osm https://github.com/SomeoneElseOSM/mod_tile.git
WORKDIR /home/renderer/src/mod_tile
RUN ./autogen.sh
RUN ./configure
RUN make
RUN ./autogen.sh \
&& ./configure \
&& make -j $(nproc)
USER root
RUN make install
RUN make install-mod_tile
RUN ldconfig
RUN make -j $(nproc) install \
&& make -j $(nproc) install-mod_tile \
&& ldconfig
USER renderer
# Configure stylesheet
@@ -53,46 +112,63 @@ WORKDIR /home/renderer/src
RUN git clone https://github.com/gravitystorm/openstreetmap-carto.git
WORKDIR /home/renderer/src/openstreetmap-carto
USER root
RUN apt-get install -y npm nodejs
RUN npm install -g carto
USER renderer
RUN carto -v
RUN carto project.mml > mapnik.xml
# Load shapefiles
WORKDIR /home/renderer/src/openstreetmap-carto
RUN scripts/get-shapefiles.py
# Install fonts
USER root
RUN apt-get install -y fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted ttf-unifont
USER renderer
# Configure renderd
USER root
RUN sed -i 's/renderaccount/renderer/g' /usr/local/etc/renderd.conf
RUN sed -i 's/hot/tile/g' /usr/local/etc/renderd.conf
RUN sed -i 's/renderaccount/renderer/g' /usr/local/etc/renderd.conf \
&& sed -i 's/hot/tile/g' /usr/local/etc/renderd.conf
USER renderer
# Configure Apache
USER root
RUN mkdir /var/lib/mod_tile
RUN chown renderer /var/lib/mod_tile
RUN mkdir /var/run/renderd
RUN chown renderer /var/run/renderd
RUN echo "LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so" >> /etc/apache2/conf-available/mod_tile.conf
RUN a2enconf mod_tile
RUN mkdir /var/lib/mod_tile \
&& chown renderer /var/lib/mod_tile \
&& mkdir /var/run/renderd \
&& chown renderer /var/run/renderd
RUN echo "LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so" >> /etc/apache2/conf-available/mod_tile.conf \
&& echo "LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so" >> /etc/apache2/conf-available/mod_headers.conf \
&& a2enconf mod_tile && a2enconf mod_headers
COPY apache.conf /etc/apache2/sites-available/000-default.conf
USER renderer
COPY leaflet-demo.html /var/www/html/index.html
RUN ln -sf /dev/stdout /var/log/apache2/access.log \
&& ln -sf /dev/stderr /var/log/apache2/error.log
# Install PostgreSQL
USER root
RUN apt-get install -y postgresql postgresql-contrib postgis postgresql-10-postgis-2.4
# Configure PosgtreSQL
COPY postgresql.custom.conf.tmpl /etc/postgresql/10/main/
RUN chown -R postgres:postgres /var/lib/postgresql \
&& chown postgres:postgres /etc/postgresql/10/main/postgresql.custom.conf.tmpl \
&& echo "\ninclude 'postgresql.custom.conf'" >> /etc/postgresql/10/main/postgresql.conf
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/10/main/pg_hba.conf \
&& echo "host all all ::/0 md5" >> /etc/postgresql/10/main/pg_hba.conf
# copy update scripts
COPY openstreetmap-tiles-update-expire /usr/bin/
RUN chmod +x /usr/bin/openstreetmap-tiles-update-expire \
&& mkdir /var/log/tiles \
&& chmod a+rw /var/log/tiles \
&& ln -s /home/renderer/src/mod_tile/osmosis-db_replag /usr/bin/osmosis-db_replag \
&& echo "* * * * * renderer openstreetmap-tiles-update-expire\n" >> /etc/crontab
# install trim_osc.py helper script
USER renderer
RUN cd ~/src \
&& git clone https://github.com/zverik/regional \
&& cd regional \
&& git checkout 612fe3e040d8bb70d2ab3b133f3b2cfc6c940520 \
&& chmod u+x ~/src/regional/trim_osc.py
# Start running
USER root
RUN apt-get install -y sudo
COPY run.sh /
COPY indexes.sql /
ENTRYPOINT ["/run.sh"]
CMD []
CMD []
EXPOSE 80 5432

192
README.md
View File

@@ -10,35 +10,207 @@ First create a Docker volume to hold the PostgreSQL database that will contain t
Next, download an .osm.pbf extract from geofabrik.de for the region that you're interested in. You can then start importing it into PostgreSQL by running a container and mounting the file as `/data.osm.pbf`. For example:
docker run -v luxembourg.osm.pbf:/data.osm.pbf -v openstreetmap-data:/var/lib/postgresql/10/main overv/openstreetmap-tile-server import
```
docker run \
-v /absolute/path/to/luxembourg.osm.pbf:/data.osm.pbf \
-v openstreetmap-data:/var/lib/postgresql/10/main \
overv/openstreetmap-tile-server \
import
```
If the container exits without errors, then your data has been successfully imported and you are now ready to run the tile server.
### Automatic updates (optional)
If your import is an extract of the planet and has polygonal bounds associated with it, like those from geofabrik.de, then it is possible to set your server up for automatic updates. Make sure to reference both the OSM file and the polygon file during the import process to facilitate this:
```
docker run \
-v /absolute/path/to/luxembourg.osm.pbf:/data.osm.pbf \
-v /absolute/path/to/luxembourg.poly:/data.poly \
-v openstreetmap-data:/var/lib/postgresql/10/main \
overv/openstreetmap-tile-server \
import
```
Refer to the section *Automatic updating and tile expiry* to actually enable the updates.
## Running the server
Run the server like this:
docker run -p 80:80 -v openstreetmap-data:/var/lib/postgresql/10/main -d overv/openstreetmap-tile-server run
```
docker run \
-p 80:80 \
-v openstreetmap-data:/var/lib/postgresql/10/main \
-d overv/openstreetmap-tile-server \
run
```
Your tiles will now be available at http://localhost:80/tile/{z}/{x}/{y}.png. If you open `leaflet-demo.html` in your browser, you should be able to see the tiles served by your own machine. Note that it will initially quite a bit of time to render the larger tiles for the first time.
Your tiles will now be available at `http://localhost:80/tile/{z}/{x}/{y}.png`. The demo map in `leaflet-demo.html` will then be available on `http://localhost:80`. Note that it will initially take quite a bit of time to render the larger tiles for the first time.
## Preserving rendered tiles
### Preserving rendered tiles
Tiles that have already been rendered will be stored in `/var/lib/mod_tile`. To make sure that this data survives container restarts, you should create another volume for it:
docker volume create openstreetmap-rendered-tiles
docker run -p 80:80 -v openstreetmap-data:/var/lib/postgresql/10/main -v openstreetmap-rendered-tiles:/var/lib/mod_tile -d overv/openstreetmap-tile-server run
```
docker volume create openstreetmap-rendered-tiles
docker run \
-p 80:80 \
-v openstreetmap-data:/var/lib/postgresql/10/main \
-v openstreetmap-rendered-tiles:/var/lib/mod_tile \
-d overv/openstreetmap-tile-server \
run
```
## Performance tuning
### Enabling automatic updating (optional)
Given that you've specified both the OSM data and polygon as specified in the *Automatic updates* section during server setup, you can enable the updating process by setting the variable `UPDATES` to `enabled`:
```
docker run \
-p 80:80 \
-e UPDATES=enabled \
-v openstreetmap-data:/var/lib/postgresql/10/main \
-v openstreetmap-rendered-tiles:/var/lib/mod_tile \
-d overv/openstreetmap-tile-server \
run
```
This 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 `1`:
```
docker run \
-p 80:80 \
-v openstreetmap-data:/var/lib/postgresql/10/main \
-e ALLOW_CORS=1 \
-d overv/openstreetmap-tile-server \
run
```
### Connecting to Postgres
To connect to the PostgreSQL database inside the container, make sure to expose port 5432:
```
docker run \
-p 80:80 \
-p 5432:5432 \
-v openstreetmap-data:/var/lib/postgresql/10/main \
-d overv/openstreetmap-tile-server \
run
```
Use the user `renderer` and the database `gis` to connect.
```
psql -h localhost -U renderer gis
```
The default password is `renderer`, but it can be changed using the `PGPASSWORD` environment variable:
```
docker run \
-p 80:80 \
-p 5432:5432 \
-e PGPASSWORD=secret \
-v openstreetmap-data:/var/lib/postgresql/10/main \
-d overv/openstreetmap-tile-server \
run
```
## Performance tuning and tweaking
Details for update procedure and invoked scripts can be found here [link](https://ircama.github.io/osm-carto-tutorials/updating-data/).
### 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:
```
docker run \
-p 80:80 \
-e THREADS=24 \
-v openstreetmap-data:/var/lib/postgresql/10/main \
-d overv/openstreetmap-tile-server \
run
```
docker run -p 80:80 -e THREADS=24 -v openstreetmap-data:/var/lib/postgresql/10/main -d overv/openstreetmap-tile-server run
### CACHE
The import and tile serving processes use 800 MB RAM cache by default, but this number can be changed by option -C. For example:
```
docker run \
-p 80:80 \
-e "OSM2PGSQL_EXTRA_ARGS=-C 4096" \
-v openstreetmap-data:/var/lib/postgresql/10/main \
-d overv/openstreetmap-tile-server \
run
```
### AUTOVACUUM
The database use the autovacuum feature by default. This behavior can be changed with `AUTOVACUUM` environment variable. For example:
```
docker run \
-p 80:80 \
-e AUTOVACUUM=off \
-v openstreetmap-data:/var/lib/postgresql/10/main \
-d overv/openstreetmap-tile-server \
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:
```
docker run \
-v /absolute/path/to/luxembourg.osm.pbf:/data.osm.pbf \
-v openstreetmap-nodes:/nodes \
-v openstreetmap-data:/var/lib/postgresql/10/main \
-e "OSM2PGSQL_EXTRA_ARGS=--flat-nodes /nodes/flat_nodes.bin" \
overv/openstreetmap-tile-server \
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](https://wiki.openstreetmap.org/wiki/Osm2pgsql/benchmarks#debian_9_.2F_openstreetmap-tile-server).
## 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 ajt 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:
```
docker run \
-p 80:80 \
-v openstreetmap-data:/var/lib/postgresql/10/main \
--shm-size="192m" \
-d overv/openstreetmap-tile-server \
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 2018 Alexander Overvoorde
Copyright 2019 Alexander Overvoorde
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -51,4 +223,4 @@ 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.
```
```

View File

@@ -10,4 +10,8 @@
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfDefine ALLOW_CORS>
Header set Access-Control-Allow-Origin "*"
</IfDefine>
</VirtualHost>

48
indexes.sql Normal file
View File

@@ -0,0 +1,48 @@
-- Extracted from https://github.com/gravitystorm/openstreetmap-carto
-- Comes with a CC0 license
-- These are optional but suggested indexes for rendering OpenStreetMap Carto
-- with a full planet database.
-- This file is generated with scripts/indexes.py
CREATE INDEX planet_osm_roads_admin
ON planet_osm_roads USING GIST (way)
WHERE boundary = 'administrative';
CREATE INDEX planet_osm_roads_roads_ref
ON planet_osm_roads USING GIST (way)
WHERE highway IS NOT NULL AND ref IS NOT NULL;
CREATE INDEX planet_osm_roads_admin_low
ON planet_osm_roads USING GIST (way)
WHERE boundary = 'administrative' AND admin_level IN ('0', '1', '2', '3', '4');
CREATE INDEX planet_osm_line_ferry
ON planet_osm_line USING GIST (way)
WHERE route = 'ferry';
CREATE INDEX planet_osm_line_river
ON planet_osm_line USING GIST (way)
WHERE waterway = 'river';
CREATE INDEX planet_osm_line_name
ON planet_osm_line USING GIST (way)
WHERE name IS NOT NULL;
CREATE INDEX planet_osm_polygon_water
ON planet_osm_polygon USING GIST (way)
WHERE waterway IN ('dock', 'riverbank', 'canal')
OR landuse IN ('reservoir', 'basin')
OR "natural" IN ('water', 'glacier');
CREATE INDEX planet_osm_polygon_nobuilding
ON planet_osm_polygon USING GIST (way)
WHERE building IS NULL;
CREATE INDEX planet_osm_polygon_name
ON planet_osm_polygon USING GIST (way)
WHERE name IS NOT NULL;
CREATE INDEX planet_osm_polygon_way_area_z10
ON planet_osm_polygon USING GIST (way)
WHERE way_area > 23300;
CREATE INDEX planet_osm_polygon_military
ON planet_osm_polygon USING GIST (way)
WHERE (landuse = 'military' OR military = 'danger_area') AND building IS NULL;
CREATE INDEX planet_osm_polygon_way_area_z6
ON planet_osm_polygon USING GIST (way)
WHERE way_area > 5980000;
CREATE INDEX planet_osm_point_place
ON planet_osm_point USING GIST (way)
WHERE place IS NOT NULL AND name IS NOT NULL;

View File

@@ -25,7 +25,7 @@
<script>
var map = L.map('map').setView([0, 0], 3);
L.tileLayer('http://localhost/tile/{z}/{x}/{y}.png', {
L.tileLayer('/tile/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
id: 'base'

View File

@@ -0,0 +1,206 @@
#!/bin/sh
set -e
#------------------------------------------------------------------------------
# AJT - change directory to mod_tile directory so that we can run replag
# and other things directly from this script when run from cron.
# Change the actual location to wherever installed locally.
#------------------------------------------------------------------------------
export PATH=.:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ACCOUNT=renderer
cd /home/$ACCOUNT/src/mod_tile/
#------------------------------------------------------------------------------
# Extra OSM2PGSQL_OPTIONS may need setting if a tag transform script is
# in use. See https://github.com/SomeoneElseOSM/SomeoneElse-style and
# http://wiki.openstreetmap.org/wiki/User:SomeoneElse/Ubuntu_1404_tileserver_load
# The database name always needs setting.
#------------------------------------------------------------------------------
OSMOSIS_BIN=osmosis
OSM2PGSQL_BIN=osm2pgsql
TRIM_BIN=/home/$ACCOUNT/src/regional/trim_osc.py
DBNAME=gis
OSM2PGSQL_OPTIONS="-d $DBNAME -G --hstore ${OSM2PGSQL_EXTRA_ARGS} --tag-transform-script /home/renderer/src/openstreetmap-carto/openstreetmap-carto.lua --number-processes ${THREADS:-4} -S /home/renderer/src/openstreetmap-carto/openstreetmap-carto.style"
#------------------------------------------------------------------------------
# When using trim_osc.py we can define either a bounding box (such as this
# example for England and Wales) or a polygon.
# See https://github.com/zverik/regional .
# This area will usually correspond to the data originally loaded.
#------------------------------------------------------------------------------
TRIM_POLY_FILE="/var/lib/mod_tile/data.poly"
TRIM_OPTIONS="-d $DBNAME"
#TRIM_REGION_OPTIONS="-b -14.17 48.85 2.12 61.27"
TRIM_REGION_OPTIONS="-p $TRIM_POLY_FILE"
BASE_DIR=/var/lib/mod_tile
LOG_DIR=/var/log/tiles/
WORKOSM_DIR=$BASE_DIR/.osmosis
LOCK_FILE=/tmp/openstreetmap-update-expire-lock.txt
CHANGE_FILE=$BASE_DIR/changes.osc.gz
EXPIRY_FILE=$BASE_DIR/dirty_tiles
STOP_FILE=$BASE_DIR/stop.txt
OSMOSISLOG=$LOG_DIR/osmosis.log
PGSQLLOG=$LOG_DIR/osm2pgsql.log
EXPIRYLOG=$LOG_DIR/expiry.log
RUNLOG=$LOG_DIR/run.log
#------------------------------------------------------------------------------
# The tile expiry section below can re-render, delete or dirty expired tiles.
# By default, tiles between EXPIRY_MINZOOM and EXPIRY_MAXZOOM are rerendered.
# "render_expired" can optionally delete (and/or dirty) tiles above a certail
# threshold rather than rendering them.
# Here we expire (but don't immediately rerender) tiles between zoom levels
# 13 and 18 and delete between 19 and 20.
#------------------------------------------------------------------------------
EXPIRY_MINZOOM=13
EXPIRY_TOUCHFROM=13
EXPIRY_DELETEFROM=19
EXPIRY_MAXZOOM=20
#*************************************************************************
#*************************************************************************
m_info()
{
echo "[`date +"%Y-%m-%d %H:%M:%S"`] $$ $1" >> "$RUNLOG"
}
m_error()
{
echo "[`date +"%Y-%m-%d %H:%M:%S"`] $$ [error] $1" >> "$RUNLOG"
m_info "resetting state"
/bin/cp $WORKOSM_DIR/last.state.txt $WORKOSM_DIR/state.txt || true
rm "$CHANGE_FILE" || true
rm "$EXPIRY_FILE.$$" || true
rm "$LOCK_FILE"
exit
}
m_ok()
{
echo "[`date +"%Y-%m-%d %H:%M:%S"`] $$ $1" >> "$RUNLOG"
}
getlock()
{
if [ -s $1 ]; then
if [ "$(ps -p `cat $1` | wc -l)" -gt 1 ]; then
return 1 #false
fi
fi
echo $$ >"$1"
return 0 #true
}
freelock()
{
rm "$1"
rm "$CHANGE_FILE"
}
if [ $# -eq 1 ] ; then
m_info "Initialising Osmosis replication system to $1"
mkdir $WORKOSM_DIR
$OSMOSIS_BIN --read-replication-interval-init workingDirectory=$WORKOSM_DIR 1>&2 2> "$OSMOSISLOG"
wget "http://replicate-sequences.osm.mazdermind.de/?"$1"T00:00:00Z" -O $WORKOSM_DIR/state.txt
mv $WORKOSM_DIR/configuration.txt $WORKOSM_DIR/configuration_orig.txt
sed "s!baseUrl=http://planet.openstreetmap.org/replication/minute!baseUrl=https://planet.openstreetmap.org/replication/minute!" $WORKOSM_DIR/configuration_orig.txt > $WORKOSM_DIR/configuration.txt
else
# make sure the lockfile is removed when we exit and then claim it
if ! getlock "$LOCK_FILE"; then
m_info "pid `cat $LOCK_FILE` still running"
exit 3
fi
if [ -e $STOP_FILE ]; then
m_info "stopped"
exit 2
fi
# -----------------------------------------------------------------------------
# Add disk space check from https://github.com/zverik/regional
# -----------------------------------------------------------------------------
MIN_DISK_SPACE_MB=500
if `python -c "import os, sys; st=os.statvfs('$BASE_DIR'); sys.exit(1 if st.f_bavail*st.f_frsize/1024/1024 > $MIN_DISK_SPACE_MB else 0)"`; then
m_info "there is less than $MIN_DISK_SPACE_MB MB left"
exit 4
fi
seq=`cat $WORKOSM_DIR/state.txt | grep sequenceNumber | cut -d= -f2`
m_ok "start import from seq-nr $seq, replag is `osmosis-db_replag -h`"
/bin/cp $WORKOSM_DIR/state.txt $WORKOSM_DIR/last.state.txt
m_ok "downloading diff"
if ! $OSMOSIS_BIN --read-replication-interval workingDirectory=$WORKOSM_DIR --simplify-change --write-xml-change $CHANGE_FILE 1>&2 2> "$OSMOSISLOG"; then
m_error "Osmosis error"
fi
if [ -f $TRIM_POLY_FILE ] ; then
m_ok "filtering diff"
if ! $TRIM_BIN $TRIM_OPTIONS $TRIM_REGION_OPTIONS -z $CHANGE_FILE $CHANGE_FILE 1>&2 2>> "$RUNLOG"; then
m_error "Trim_osc error"
fi
else
m_ok "filtering diff skipped"
fi
m_ok "importing diff"
#------------------------------------------------------------------------------
# Previously openstreetmap-tiles-update-expire tried to dirty layer
# "$EXPIRY_MAXZOOM - 3" (which was 15) only. Instead we write all expired
# tiles in range to the list (note the "-" rather than ":" in the "-e"
# parameter).
#------------------------------------------------------------------------------
if ! $OSM2PGSQL_BIN -a --slim -e$EXPIRY_MINZOOM-$EXPIRY_MAXZOOM $OSM2PGSQL_OPTIONS -o "$EXPIRY_FILE.$$" $CHANGE_FILE 1>&2 2> "$PGSQLLOG"; then
m_error "osm2pgsql error"
fi
#------------------------------------------------------------------------------
# The lockfile is normally removed before we expire tiles because that is
# something thatcan be done in parallel with further processing. In order to
# avoid rework, if actually rerendering is done rather than just deleting or
# dirtying, it makes sense to move it lower down.
#------------------------------------------------------------------------------
# m_ok "Import complete; removing lock file"
# freelock "$LOCK_FILE"
m_ok "expiring tiles"
#------------------------------------------------------------------------------
# When expiring tiles we need to define the style sheet if it's not "default".
# In this case it's "ajt".
# Previously all tiles on the "dirty" list between $EXPIRY_MINZOOM and
# $EXPIRY_MAXZOOM were dirtied. We currently re-render
# tiles >= $EXPIRY_MINZOOM and < $EXPIRY_DELETEFROM, expiry from 14 and
# delete >= $EXPIRY_DELETEFROM and <= $EXPIRY_MAXZOOM.
# The default path to renderd.sock is fixed.
#------------------------------------------------------------------------------
if ! render_expired --map=ajt --min-zoom=$EXPIRY_MINZOOM --touch-from=$EXPIRY_TOUCHFROM --delete-from=$EXPIRY_DELETEFROM --max-zoom=$EXPIRY_MAXZOOM -s /var/run/renderd/renderd.sock < "$EXPIRY_FILE.$$" 2>&1 | tail -8 >> "$EXPIRYLOG"; then
m_info "Expiry failed"
fi
rm "$EXPIRY_FILE.$$"
#------------------------------------------------------------------------------
# Only remove the lock file after expiry (if system is slow we want to delay
# the next import, not have multiple render_expired processes running)
#------------------------------------------------------------------------------
freelock "$LOCK_FILE"
m_ok "Done with import"
fi

View File

@@ -0,0 +1,25 @@
# Suggested minimal settings from
# https://ircama.github.io/osm-carto-tutorials/tile-server-ubuntu/
shared_buffers = 128MB
min_wal_size = 1GB
max_wal_size = 2GB
maintenance_work_mem = 256MB
# Suggested settings from
# https://github.com/openstreetmap/chef/blob/master/roles/tile.rb#L38-L45
max_connections = 250
temp_buffers = 32MB
work_mem = 128MB
wal_buffers = 1024kB
wal_writer_delay = 500ms
commit_delay = 10000
# checkpoint_segments = 60 # unrecognized in psql 10.7.1
max_wal_size = 2880MB
random_page_cost = 1.1
track_activity_query_size = 16384
autovacuum_vacuum_scale_factor = 0.05
autovacuum_analyze_scale_factor = 0.02
listen_addresses = '*'

57
run.sh
View File

@@ -1,5 +1,17 @@
#!/bin/bash
set -x
function createPostgresConfig() {
cp /etc/postgresql/10/main/postgresql.custom.conf.tmpl /etc/postgresql/10/main/postgresql.custom.conf
sudo -u postgres echo "autovacuum = $AUTOVACUUM" >> /etc/postgresql/10/main/postgresql.custom.conf
cat /etc/postgresql/10/main/postgresql.custom.conf
}
function setPostgresPassword() {
sudo -u postgres psql -c "ALTER USER renderer PASSWORD '${PGPASSWORD:-renderer}'"
}
if [ "$#" -ne 1 ]; then
echo "usage: <import|run>"
echo "commands:"
@@ -7,11 +19,13 @@ if [ "$#" -ne 1 ]; then
echo " run: Runs Apache and renderd to serve tiles at /tile/{z}/{x}/{y}.png"
echo "environment variables:"
echo " THREADS: defines number of threads used for importing / tile rendering"
echo " UPDATES: consecutive updates (enabled/disabled)"
exit 1
fi
if [ "$1" = "import" ]; then
# Initialize PostgreSQL
createPostgresConfig
service postgresql start
sudo -u postgres createuser renderer
sudo -u postgres createdb -E UTF8 -O renderer gis
@@ -19,32 +33,71 @@ if [ "$1" = "import" ]; then
sudo -u postgres psql -d gis -c "CREATE EXTENSION hstore;"
sudo -u postgres psql -d gis -c "ALTER TABLE geometry_columns OWNER TO renderer;"
sudo -u postgres psql -d gis -c "ALTER TABLE spatial_ref_sys OWNER TO renderer;"
setPostgresPassword
# Download Luxembourg as sample if no data is provided
if [ ! -f /data.osm.pbf ]; then
echo "WARNING: No import file at /data.osm.pbf, so importing Luxembourg as example..."
wget -nv http://download.geofabrik.de/europe/luxembourg-latest.osm.pbf -O /data.osm.pbf
wget -nv http://download.geofabrik.de/europe/luxembourg.poly -O /data.poly
fi
# determine and set osmosis_replication_timestamp (for consecutive updates)
osmium fileinfo /data.osm.pbf > /var/lib/mod_tile/data.osm.pbf.info
osmium fileinfo /data.osm.pbf | grep 'osmosis_replication_timestamp=' | cut -b35-44 > /var/lib/mod_tile/replication_timestamp.txt
REPLICATION_TIMESTAMP=$(cat /var/lib/mod_tile/replication_timestamp.txt)
# initial setup of osmosis workspace (for consecutive updates)
sudo -u renderer openstreetmap-tiles-update-expire $REPLICATION_TIMESTAMP
# copy polygon file if available
if [ -f /data.poly ]; then
sudo -u renderer cp /data.poly /var/lib/mod_tile/data.poly
fi
# Import data
sudo -u renderer osm2pgsql -d gis --create --slim -G --hstore --tag-transform-script /home/renderer/src/openstreetmap-carto/openstreetmap-carto.lua -C 2048 --number-processes ${THREADS:-4} -S /home/renderer/src/openstreetmap-carto/openstreetmap-carto.style /data.osm.pbf
sudo -u renderer osm2pgsql -d gis --create --slim -G --hstore --tag-transform-script /home/renderer/src/openstreetmap-carto/openstreetmap-carto.lua --number-processes ${THREADS:-4} ${OSM2PGSQL_EXTRA_ARGS} -S /home/renderer/src/openstreetmap-carto/openstreetmap-carto.style /data.osm.pbf
# Create indexes
sudo -u postgres psql -d gis -f indexes.sql
service postgresql stop
exit 0
fi
if [ "$1" = "run" ]; then
# Clean /tmp
rm -rf /tmp/*
# Fix postgres data privileges
chown postgres:postgres /var/lib/postgresql -R
# Configure Apache CORS
if [ "$ALLOW_CORS" == "1" ]; then
echo "export APACHE_ARGUMENTS='-D ALLOW_CORS'" >> /etc/apache2/envvars
fi
# Initialize PostgreSQL and Apache
createPostgresConfig
service postgresql start
service apache2 restart
setPostgresPassword
# Configure renderd threads
sed -i -E "s/num_threads=[0-9]+/num_threads=${THREADS:-4}/g" /usr/local/etc/renderd.conf
# start cron job to trigger consecutive updates
if [ "$UPDATES" = "enabled" ]; then
/etc/init.d/cron start
fi
# Run
sudo -u renderer renderd -f -c /usr/local/etc/renderd.conf
service postgresql stop
exit 0
fi
echo "invalid command"
exit 1
exit 1