System Requirements
Hardware
A minimum of 1GB of RAM is required or installation will fail. For a full planet import 32GB or more are recommended.
For a full planet install you will need about 500GB of hard disk space (as of May 2015, take into account that the OSM database is growing fast). SSD disks will help considerably to speed up import and queries.
On pummelzacken the complete initial import requires around 2 days. On a 12-core machine with 32GB RAM and standard SATA disks, the initial import (osm2pgsql) takes around 20 hours and the indexing process another 250 hours. Only 8 parallel threads were used for this setup because I/O speed was the limiting factor. The same machine is able to import the Germany extract in around 4 hours.
Pre-Installments
sudo apt-get install libboost-all-dev subversion 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 libpng12-dev libtiff4-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 node-carto sudo apt-get install geotiff-bin sudo apt-get install libgeotiff-dev sudo apt-get install postgresql postgresql-contrib postgis postgresql-9.3-postgis-2.1
Adding a New Postgre User
sudo -u postgres -i createuser username # answer yes for superuser (although this isn't strictly necessary) createdb -E UTF8 -O username gis exit
Be careful with what you type in username. It will need later.
Postgres Tables
sudo -u postgres psql \c gis CREATE EXTENSION postgis; ALTER TABLE geometry_columns OWNER TO username; ALTER TABLE spatial_ref_sys OWNER TO username; \q exit
Installation of OSM2PGSQL
mkdir ~/src cd ~/src git clone git://github.com/openstreetmap/osm2pgsql.git cd osm2pgsql mkdir build && cd build cmake .. make sudo make install
Installation of Mapnik
sudo apt-get install -y python-software-properties sudo add-apt-repository ppa:mapnik/nightly-2.3 sudo apt-get update sudo apt-get install libmapnik libmapnik-dev mapnik-utils python-mapnik # also install datasource plugins if you need them sudo apt-get install mapnik-input-plugin-gdal mapnik-input-plugin-ogr mapnik-input-plugin-postgis mapnik-input-plugin-sqlite mapnik-input-plugin-osm
Checking Mapnik Installation in Python
python >>> import mapnik >>> quit()
Installation of mod_tile and Renderd
Install mod_tile and renderd: cd ~/src git clone git://github.com/openstreetmap/mod_tile.git cd mod_tile ./autogen.sh ./configure make sudo make install sudo make install-mod_tile sudo ldconfig
Installation of Stylesheet (OSMBright)
Also available other themes are TileMill , Kosmtik , Sputnik
mkdir -p /usr/local/share/maps/style cd /usr/local/share/maps/style wget https://github.com/mapbox/osm-bright/archive/master.zip wget http://data.openstreetmapdata.com/simplified-land-polygons-complete-3857.zip wget http://data.openstreetmapdata.com/land-polygons-split-3857.zip wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places_simple.zip
Downloading Shapes
unzip '*.zip' mkdir osm-bright-master/shp mv land-polygons-split-3857 osm-bright-master/shp/ mv simplified-land-polygons-complete-3857 osm-bright-master/shp/ mv ne_10m_populated_places_simple osm-bright-master/shp/
Indexing to Improve Performances
cd osm-bright-master/shp/land-polygons-split-3857 shapeindex land_polygons.shp cd ../simplified-land-polygons-complete-3857/ shapeindex simplified_land_polygons.shp cd ../
Location of local data files
nano osm-bright/osm-bright.osm2pgsql.mml
Replace all values start with ‘http://’
"file": "/usr/local/share/maps/style/osm-bright-master/shp/land-polygons-split-3857/land_polygons.shp", "type": "shape" "file": "/usr/local/share/maps/style/osm-bright-master/shp/simplified-land-polygons-complete-3857/simplified_land_polygons.shp", "type": "shape", "file": "/usr/local/share/maps/style/osm-bright-master/shp/ne_10m_populated_places_simple/ne_10m_populated_places_simple.shp", "type": "shape"
Finally, replace sections that are ‘srs’ and ‘srs_name’ with
"srs": "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
Run in /osm-bright-master/
cp configure.py.sample configure.py nano configure.py
Replace “~/Documents/Mapbox/project” line with “/usr/local/share/maps/style” and change database name ‘osm’ to ‘gis’.
Editing /usr/local/etc/renderd.conf
socketname=/var/run/renderd/renderd.sock plugins_dir=/usr/lib/mapnik/input font_dir=/usr/share/fonts/truetype/ttf-dejavu XML=/usr/local/share/maps/style/OSMBright/OSMBright.xml HOST=localhost
Configuring mod_tile
sudo mkdir /var/run/renderd sudo chown username /var/run/renderd sudo mkdir /var/lib/mod_tile sudo chown username /var/lib/mod_tile
username must be same as before
Adding Apache Module
Open /etc/apache2/conf-available/mod_tile.conf as sudo and adding this line
LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so
Editing Apache Configuration
Open /etc/apache2/sites-available/000-default.conf as sudo and adding these lines after admin email address
LoadTileConfigFile /usr/local/etc/renderd.conf ModTileRenderdSocketName /var/run/renderd/renderd.sock # Timeout before giving up for a tile to be rendered ModTileRequestTimeout 0 # Timeout before giving up for a tile to be rendered that is otherwise missing ModTileMissingRequestTimeout 30
Apply the changes
sudo a2enconf mod_tile sudo service apache2 reload
Tuning the system
sudo nano /etc/postgresql/9.3/main/postgresql.conf
shared_buffers = 128MB checkpoint_segments = 20 maintenance_work_mem = 256MB autovacuum = off
sudo nano /etc/sysctl.conf
# Increase kernel shared memory segments - needed for large databases kernel.shmmax=268435456
After reboot your system, you can check to kernel definition
sudo sysctl kernel.shmmax 268435456
Downloading Maps
From http://planet.openstreetmap.org/ or http://download.geofabrik.de/
mkdir /usr/local/share/maps/planet cd /usr/local/share/maps/planet wget http://download.geofabrik.de/europe/turkey-latest.osm.pbf
Loading data to database
osm2pgsql --slim -d gis -C 256 -S /home/ubuntu/src/osm2pgsql/default.style --number-processes 3 ~/planet/planet-latest.osm.pbf
Change planet-lastest.som.pdf file with whatever your file is downloaded.
After passed without error, screen would show
Completed planet_osm_point Completed planet_osm_roads Completed planet_osm_polygon Completed planet_osm_line Stopped table: planet_osm_ways Osm2pgsql took 86400s overall
Running Server
sudo mkdir /var/run/renderd sudo chown username /var/run/renderd
sudo -u username renderd -f -c /usr/local/etc/renderd.conf service apache2 reload
If everthing is fine, a small png picture will be appear after browsing ‘http://yourserveraddress/osm_tiles/0/0/0.png’.
Setting to startup scripts
sudo cp ~/src/mod_tile/debian/renderd.init /etc/init.d/renderd sudo chmod u+x /etc/init.d/renderd sudo nano /etc/init.d/renderd"
DAEMON=/usr/local/bin/$NAME DAEMON_ARGS="-c /usr/local/etc/renderd.conf"
Replace ‘www-data’ username with whatever you defined before.
sudo /etc/init.d/renderd start
sudo ln -s /etc/init.d/renderd /etc/rc2.d/S20renderd
Now we can reboot the system then good luck with that new tile server 🙂
Source: https://switch2osm.org/why-switch/