User:Zverik/Tile Server on Fedora 20

From OpenStreetMap Wiki
Jump to navigation Jump to search

See this page for most recent instructions for Ubuntu 14.04, by Paul Norman.

Initialize database

yum install postgresql postgresql-contrib postgresql-server postgis

Default DB location

If your /usr partition is low on space, follow the next chapter instructions. Otherwise run this command and skip to "Start PostgreSQL...":

su postgres -c "initdb -E UTF8"

Moving DB to home

We'll be moving PostgreSQL data directory to /home/pgdata, as described here.

mkdir /home/pgdata
chown postgres:postgres /home/pgdata
su postgres -c "initdb -E UTF8 -D /home/pgdata"

# change PGDATA in systemd config
sed "s#^Environment=PGDATA=.*#Environment=PGDATA=/home/pgdata#" /usr/lib/systemd/system/postgresql.service > /etc/systemd/system/postgresql.service

# change PGHOME selinux context
chcon -R --reference=/var/lib/pgsql/data /home/pgdata

# allow postgres to search /home
cd /root
mkdir selinux.local
cd selinux.local
chcon -R -t usr_t .
ln -s /usr/share/selinux/devel/Makefile .
touch postgresqlhome.fc
touch postgresqlhome.if

cat > postgresqlhome.te <<EOF
module postgresqlhome 0.1;

require {
        class dir search; 
        class lnk_file read;

        type home_root_t;
        type postgresql_t;
        type var_lib_t;

# Allow postgresql to search directory /home
allow postgresql_t home_root_t:dir search; 

semodule -i postgresqlhome.pp

Start PostgreSQL and create database

systemctl enable postgresql
systemctl start postgresql
su postgres -c "createdb gis"
psql -d gis -c "create extension postgis;"

Populate the database

It is recommended to set overcommit kernel flag, so osm2pgsql multiprocessing works (not tested on Fedora yet):

echo "vm.overcommit_memory=1" > /etc/sysctl.d/60-overcommit.conf
sysctl -p /etc/sysctl.d/60-overcommit.conf

Now download some data, cut it if needed (see below) and load to a database:

yum install osm2pgsql

# Download data
# wget

osm2pgsql -d gis --slim -C 8000 --number-processes 3 local.osm.pbf

Cutting a region

If you need to cut source file, install Osmosis:

mkdir osmosis
cd osmosis
wget -O - | tar -xz
ln -r -s bin/osmosis /usr/bin/
cd ..

# Cut local.osm.pbf with a polygon region.poly
osmosis --read-pbf local.osm.pbf --bounding-polygon file=region.poly --write-pbf local-cut.osm.pbf

# ...or with a bounding box
osmosis --read-pbf local.osm.pbf --bounding-box top=46.6 bottom=44 left=32 right=37 --write-pbf local-cut.osm.pbf

Prepare mapnik style

yum install mapnik mapnik-utils carto gdal unifont-fonts
git clone carto
cd carto
carto project.mml | grep -v 'Arundina\|Khmer\|Padauk' | sed 's/unifont/Unifont/' >osm.xml

Rendering tiles from command line

yum install python-shapely
git clone
polytiles/ -p region.poly -z 6 8

For rendering images, see Nik4.

Side note - installing TileMill

You would probably want it to edit mapnik style. Current instructions are too verbose: everything is packaged in Fedora except tilemill itself.

yum install nodejs-mapnik protobuf-devel protobuf-lite
git clone
cd tilemill
grep -v topcube package.json > ptmp; mv ptmp package.json
npm install

Now open localhost:20009 in any browser.