dev-libre-is/docs/_source/tile-libre-is.rst
2024-09-16 15:24:27 -06:00

226 lines
4.5 KiB
ReStructuredText

=============
tile.libre.is
=============
Tile server for `<https://maps.libre.is/>`_.
switch2osm.org
==============
Self-hosting tiles for maps.
`<https://switch2osm.org/>`_
`<https://switch2osm.org/serving-tiles/manually-building-a-tile-server-debian-12/>`_
Debian
======
Install deps.
.. code-block:: sh
sudo apt install sudo screen locate libapache2-mod-tile renderd git tar \
unzip wget bzip2 apache2 lua5.1 mapnik-utils python3-mapnik \
python3-psycopg2 python3-yaml gdal-bin node-carto postgresql \
postgresql-contrib postgis postgresql-15-postgis-3 \
postgresql-15-postgis-3-scripts osm2pgsql net-tools curl
PostGIS
=======
Thusly.
Tune Postgres, ala:
`<https://osm2pgsql.org/doc/manual.html#tuning-the-postgresql-server>`_
.. code-block:: cfg
shared_buffers = 1GB
work_mem = 50MB
maintenance_work_mem = 10GB
autovacuum_work_mem = 2GB
wal_level = minimal
checkpoint_timeout = 60min
max_wal_size = 10GB
checkpoint_completion_target = 0.9
max_wal_senders = 0
random_page_cost = 1.0
.. code-block:: sh
sudo -u postgres -i
createuser _renderd
createdb -E UTF8 -O _renderd gis
psql
At the Postgres prompt:
.. code-block:: psql
\c gis
CREATE EXTENSION postgis;
CREATE EXTENSION hstore;
ALTER TABLE geometry_columns OWNER TO _renderd;
ALTER TABLE spatial_ref_sys OWNER TO _renderd;
\q
Carto
=====
Set up Openstreet map Carto:
.. code-block:: sh
mkdir ~/src
cd ~/src
git clone https://github.com/gravitystorm/openstreetmap-carto
cd openstreetmap-carto
carto project.mml > mapnik.xml
Map Data
========
Just using Azerbaijan for example, until more disk is available...
.. code-block:: sh
mkdir ~/data
cd ~/data
wget https://download.geofabrik.de/asia/azerbaijan-latest.osm.pbf
# meh, should have separate user...
chmod o+rx ~
sudo -u _renderd osm2pgsql -d gis --create --slim -G --hstore \
--tag-transform-script ~/src/openstreetmap-carto/openstreetmap-carto.lua \
-C 2500 --number-processes 1 \
-S ~/src/openstreetmap-carto/openstreetmap-carto.style \
~/data/azerbaijan-latest.osm.pbf
Or do the whole planet. If created above, maybe faster to drop
the old database first than do an update. XXX
.. code-block:: sh
mkdir ~/data
cd ~/data
# Find a mirror here:
# https://wiki.openstreetmap.org/wiki/Planet.osm
# planet-latest.osm.pbf is 77G
wget https://ftp.osuosl.org/pub/openstreetmap/pbf/planet-latest.osm.pbf
chmod o+rx ~
sudo -u _renderd osm2pgsql -d gis --create --slim -G --hstore \
--tag-transform-script ~/src/openstreetmap-carto/openstreetmap-carto.lua \
-C 98304 \
-S ~/src/openstreetmap-carto/openstreetmap-carto.style \
~/data/planet-latest.osm.pbf
Indexes
=======
Thusly.
.. code-block:: sh
cd ~/src/openstreetmap-carto/
sudo -u _renderd psql -d gis -f indexes.sql
Shapefiles
==========
Thusly.
.. code-block:: sh
cd ~/src/openstreetmap-carto/
mkdir data
sudo chown _renderd data
sudo -u _renderd scripts/get-external-data.py
Fonts
=====
Thusly.
.. code-block:: sh
cd ~/src/openstreetmap-carto/
scripts/get-fonts.sh
renderd
=======
Edit /etc/renderd.conf thusly, add to bottom,
changing "accountname" to the user used above:
.. code-block:: cfg
[s2o]
URI=/hot/
XML=/home/accountname/src/openstreetmap-carto/mapnik.xml
HOST=localhost
TILESIZE=256
MAXZOOM=20
Edit /usr/lib/systemd/system/renderd.service and add to
[Service] section:
.. code-block:: cfg
Environment=G_MESSAGES_DEBUG=all
Apache
======
Thusly...
.. code-block:: sh
cd /etc/apache2/conf-available/
sudo wget https://raw.githubusercontent.com/openstreetmap/mod_tile/python-implementation/etc/apache2/renderd.conf
sudo a2enconf renderd
sudo systemctl reload apache2
sudo systemctl daemon-reload
sudo systemctl restart renderd
sudo systemctl restart apache2
sudo mkdir /var/lib/mod_tile
sudo chown _renderd /var/lib/mod_tile
sudo /etc/init.d/renderd restart
sudo /etc/init.d/apache2 restart
Then go check it here:
`<http://tile.libre.is/hot/0/0/0.png>`_
View Tiles
==========
Thus.
.. code-block:: sh
cd /var/www/html
sudo wget https://raw.githubusercontent.com/SomeoneElseOSM/mod_tile/switch2osm/extra/sample_leaflet.html
sudo mv sample_leaflet.html index.html
sudo sed -i -e 's/127.0.0.1/tile.libre.is/g' index.html
Using Tiles
===========
See:
`<https://switch2osm.org/using-tiles/>`_
Certbot
=======
Add certs.
.. code-block:: sh
sudo apt install python3-certbot-apache
sudo certbot -d tile.libre.is
sudo systemctl restart apache2
TODO
====
* Get more space.
* Add more tiles...