Skip to content

Instantly share code, notes, and snippets.

@coder4web
Last active June 7, 2021 08:58
Show Gist options
  • Save coder4web/39e981adbc859db62576dc6840a4023b to your computer and use it in GitHub Desktop.
Save coder4web/39e981adbc859db62576dc6840a4023b to your computer and use it in GitHub Desktop.
CentOS 7 Open Street Map Tile Server
# Based on next manuals:
# CentOS 7 - https://www.keisan.io/en/knowledgebase/centos-7-open-street-map-tile-server
# CentOS 6 - http://gis-lab.info/qa/mod_tile.html#.D0.9D.D0.B0.D1.81.D1.82.D1.80.D0.BE.D0.B9.D0.BA.D0.B0_renderd (on Russian)
# Updated to latest CentOS / deps packages
# WORK IN PROGRESS! INCOMPLETE FOR NOW!
# Dependencies
sudo yum install git libpng libtiff libjpeg freetype gdal cairo cairo-devel pycairo sqlite geos boost curl libcurl libicu bzip2-devel libpng-devel libtiff-devel zlib-devel libjpeg-devel libxml2-devel python-setuptools proj-devel proj proj-epsg proj-nad freetype-devel libicu-devel gdal-devel sqlite-devel libcurl-devel cairo-devel pycairo-devel geos-devel protobuf-devel protobuf-c-devel lua-devel cmake proj boost-thread proj-devel autoconf automake libtool pkgconfig ragel gtk-doc glib2 glib2-devel libpng libpng-devel libwebp libtool-ltdl-devel python-devel harfbuzz harfbuzz-devel harfbuzz-icu boost-devel cabextract xorg-x11-font-utils fontconfig perl-DBD-Pg mesa-libGLU-devel
sudo mkdir -p /usr/local/src/osm_tile_server
cd /usr/local/src/osm_tile_server # custom source dir with user's RW access rights
# Mapnik and mod_tile now requires C++14 compliant compiler (-std=c++14)
sudo yum install centos-release-scl
sudo yum install devtoolset-7 llvm-toolset-7
scl enable devtoolset-7 bash
gcc --version #7.x.x
scl enable llvm-toolset-7 bash
clang --version #5.x.x
# Postgres Pro
# @see https://gist.github.com/coder4web/c6d7c3810518063f80ed145e1ed0e562
createuser osm -W
createdb -E UTF8 -O osm gis
#CREATE DATABASE gis WITH ENCODING = 'UTF8';
psql gis -c 'CREATE EXTENSION postgis; CREATE EXTENSION hstore;'
psql gis < /usr/pgsql-11/share/contrib/postgis-2.5/postgis.sql
psql gis < /usr/pgsql-11/share/contrib/postgis-2.5/spatial_ref_sys.sql
psql -h 127.0.0.1 -d gis -U osm
SELECT pg_size_pretty(pg_database_size('gis'));
createuser apache -W
#echo "grant all on geometry_columns to apache;" | psql gis
#echo "grant all on spatial_ref_sys to apache;" | psql gis
psql -h 127.0.0.1 -d gis -U postgres
\c gis
GRANT ALL ON schema public TO apache;
GRANT ALL ON ALL TABLES IN SCHEMA public TO apache;
GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO apache;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO apache;
# mapnik
# https://mapnik.org/
sudo nano /etc/profile.d/pgsql.sh
export PATH=$PATH:/usr/pgsql-11/bin:/usr/pgsql-11/lib:/usr/local/lib
source /etc/profile.d/pgsql.sh
git clone git://github.com/mapnik/mapnik
cd mapnik
./bootstrap.sh
./configure
git submodule sync
git submodule update --init deps/mapbox/variant
git submodule update --init deps/mapbox/geometry
git submodule update --init deps/mapbox/polylabel
git submodule update --init deps/mapbox/protozero
make
sudo make install
sudo ldconfig
cd ..
# carto AKA CartoCSS - is a language for map design, allowing you to edit the style of maps including shapes, polygons, fonts and colours
# https://github.com/mapbox/carto/
sudo yum install nodejs #Carto can be installed via NodeJS
npm -v #3.10.10
sudo npm install -g carto
# OpenStreetMap Carto - stylesheet for the standard map layer for Open Street Map-based maps
# https://github.com/gravitystorm/openstreetmap-carto
git clone git://github.com/gravitystorm/openstreetmap-carto.git
cd openstreetmap-carto
# Compile and download shape files
carto project.mml > mapnik.xml
scripts/get-shapefiles.py
# osm2pgsql - converts OpenStreetMap data to postGIS-enabled PostgreSQL databases.
# https://wiki.openstreetmap.org/wiki/Osm2pgsql
git clone git://github.com/openstreetmap/osm2pgsql.git
cd osm2pgsql
mkdir build && cd build && cmake ..
make
sudo make install
cd ..
# Import Map Data into PostgreSQL
export PATH=$PATH:/usr/pgsql-11/bin
mkdir ~/osm_data
cd ~/osm_data
wget -c https://download.bbbike.org/osm/bbbike/Moscow/Moscow.osm.pbf
osm2pgsql -d gis -U osm --create --slim -G --hstore-all --tag-transform-script ~/osm_tile_server/openstreetmap-carto/openstreetmap-carto.lua -C 2500 --number-processes 1 -S ~/osm_tile_server/openstreetmap-carto/openstreetmap-carto.style ~/osm_data/Moscow.osm.pbf
#psql -h 127.0.0.1 -d gis -U osm
#osm2pgsql -H 127.0.0.1 -d gis -U osm --slim -C 1600 --number-process 1 -S /usr/local/share/osm2pgsql/default.style Moscow.osm.pbf
# mod_tile - renders and serves map tiles using Apache and mapnik
# https://github.com/openstreetmap/mod_tile
sudo yum install httpd-devel # fix for: configure: error: Could not find apxs on the path.
git clone git://github.com/openstreetmap/mod_tile.git
cd mod_tile
./autogen.sh
./configure
# From where you cloned the mapnik source (see above) copy mapnik libraries to /usr/include/mapnik
sudo mkdir -p /usr/include/mapnik
sudo cp -rf ../mapnik/include/mapnik/* /usr/include/mapnik
sudo cp ../mapnik/include/mapnik/geometry/box2d.hpp /usr/include/mapnik
make
sudo make install
sudo make install-mod_tile
sudo ldconfig
cd ..
# --------------------
# Renderd and mod_tile
# --------------------
nano /usr/local/etc/renderd.conf
...
nano /etc/httpd/conf.d/mod_tile.conf
...
# Start Renderd
sudo mkdir /var/run/renderd
sudo mkdir /var/lib/mod_tile
sudo chown apache /var/lib/mod_tile
sudo chown apache /var/run/renderd
# test foreground launch
sudo su -l apache -s /usr/local/bin/renderd -f -c /usr/local/etc/renderd.conf
@coder4web
Copy link
Author

coder4web commented Jul 2, 2020

Hello!
Something with include files path, sorry, can't say in detail.
Script is complete and tested but results may vary.
CentOS 7/8 in not very friendly for OSM, so after spent time in struggle with compiling, I've switched to Docker and stay with it now: https://github.com/Overv/openstreetmap-tile-server.
Or try Ubuntu there are tutorilas for it: https://switch2osm.org/serving-tiles/

@casaulenbo
Copy link

casaulenbo commented Jul 2, 2020

hi Aleksey Deryagin

Thanks for your sharing, i follow your instruction, everything work fine until i try to compile mapnik with make . It's said:

In file included from benchmark/include/bench_framework.hpp:9:
deps/../test/cleanup.hpp:14:10: fatal error: 'cairo.h' file not found
#include <cairo.h>
         ^~~~~~~~~
1 error generated.
scons: *** [benchmark/src/normalize_angle.o] Error 1
scons: building terminated because of errors.
make: *** [Makefile:48: mapnik] Error 2

Have you got any idea about it?
Thanks!

After research for a couple days, i figure out that, somehow compile path does not correct, so and execute the following command before exec make: export CPATH=/root/osm_tile_server/mapnik/mason_packages/.link/include/cairo/:/root/osm_tile_server/mapnik/mason_packages/.link/include/freetype2/
Note: Please correct path with your enviroment.

But, it go to another issuse ;(

CentOS 7/8 in not very friendly for OSM, so after spent time in struggle with compiling, I've switched to Docker and stay with it now: https://github.com/Overv/openstreetmap-tile-server.
Or try Ubuntu there are tutorilas for it: https://switch2osm.org/serving-tiles/

You right. It's really hard to make it worked with CentOS.
Thanks for your help and have a nice day!

@azaadshatru
Copy link

Hi Aleksey,

Thanks for providing the steps for configuring the OSM on CentOS. While following the steps, I am getting error on running make command for mod_tile

[root@mumcnsmapsina2 mod_tile]# make
/bin/sh ./libtool --tag=CXX --mode=link g++ -I/usr/local/include -I/usr/local/include/mapnik/agg -I/usr/local/include/mapnik/deps -I/usr/local/include -I/usr/include -I/usr/include/freetype2 -I/usr/include/libpng15 -I/usr/include/gdal -I/usr/pgsql-9.5/include -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/libdrm -DMAPNIK_MEMORY_MAPPED_FILE -DMAPNIK_HAS_DLCFN -DBIGINT -DBOOST_REGEX_HAS_ICU -DHAVE_JPEG -DMAPNIK_USE_PROJ4 -DHAVE_PNG -DHAVE_TIFF -DLINUX -DMAPNIK_THREADSAFE -DBOOST_SPIRIT_NO_PREDEFINED_TERMINALS=1 -DBOOST_PHOENIX_NO_PREDEFINED_TERMINALS=1 -DBOOST_SPIRIT_USE_PHOENIX_V3=1 -DNDEBUG -DHAVE_CAIRO -DGRID_RENDERER -std=c++14 -DU_USING_ICU_NAMESPACE=0 -fvisibility=hidden -fvisibility-inlines-hidden -pthread -ftemplate-depth-300 -O3 -g -O2 -o renderd src/daemon.o src/daemon_compat.o src/renderd-gen_tile.o src/sys_utils.o src/request_queue.o src/cache_expire.o src/renderd-metatile.o src/renderd-parameterize_style.o src/protocol_helper.o src/store.o src/store_file.o src/store_file_utils.o src/store_memcached.o src/store_rados.o src/store_ro_http_proxy.o src/store_ro_composite.o src/store_null.o -pthread -L/usr/local/lib -lmapnik -L/opt/packages/mapnik/freetype -L/usr/local/lib -L/usr/lib -L/usr/lib64 -L/usr/pgsql-9.5/lib -pthread -lboost_filesystem -lboost_regex -lcairo -lpng -lproj -ltiff -licui18n -lboost_system -lharfbuzz -ljpeg -licuuc -lfreetype -lz -ldl -lcurl -liniparser -lm
libtool: link: g++ -I/usr/local/include -I/usr/local/include/mapnik/agg -I/usr/local/include/mapnik/deps -I/usr/local/include -I/usr/include -I/usr/include/freetype2 -I/usr/include/libpng15 -I/usr/include/gdal -I/usr/pgsql-9.5/include -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/libdrm -DMAPNIK_MEMORY_MAPPED_FILE -DMAPNIK_HAS_DLCFN -DBIGINT -DBOOST_REGEX_HAS_ICU -DHAVE_JPEG -DMAPNIK_USE_PROJ4 -DHAVE_PNG -DHAVE_TIFF -DLINUX -DMAPNIK_THREADSAFE -DBOOST_SPIRIT_NO_PREDEFINED_TERMINALS=1 -DBOOST_PHOENIX_NO_PREDEFINED_TERMINALS=1 -DBOOST_SPIRIT_USE_PHOENIX_V3=1 -DNDEBUG -DHAVE_CAIRO -DGRID_RENDERER -std=c++14 -DU_USING_ICU_NAMESPACE=0 -fvisibility=hidden -fvisibility-inlines-hidden -pthread -ftemplate-depth-300 -O3 -g -O2 -o renderd src/daemon.o src/daemon_compat.o src/renderd-gen_tile.o src/sys_utils.o src/request_queue.o src/cache_expire.o src/renderd-metatile.o src/renderd-parameterize_style.o src/protocol_helper.o src/store.o src/store_file.o src/store_file_utils.o src/store_memcached.o src/store_rados.o src/store_ro_http_proxy.o src/store_ro_composite.o src/store_null.o -pthread -pthread -L/usr/local/lib -lmapnik -L/opt/packages/mapnik/freetype -L/usr/lib -L/usr/lib64 -L/usr/pgsql-9.5/lib -lboost_filesystem -lboost_regex -lcairo -lpng -lproj -ltiff -licui18n -lboost_system -lharfbuzz -ljpeg -licuuc -lfreetype -lz -ldl -lcurl -liniparser -lm -pthread
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: cannot find -liniparser
collect2: error: ld returned 1 exit status
make: *** [Makefile:758: renderd] Error 1

I am not able to search for this error and cannot proceed further. Can you please help if you know something about this error and how to deal with it?

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment