-
Notifications
You must be signed in to change notification settings - Fork 120
/
HOWTO_Ubuntu_16.04
208 lines (143 loc) · 6.69 KB
/
HOWTO_Ubuntu_16.04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
###############################################
# OpenTopoMap
# (c) 2012-2018 Stefan Erhardt
# https://github.com/der-stefan/OpenTopoMap
#
# opentopomap.org
#
###############################################
HOWTO install OpenTopoMap on Ubuntu (verified on 16.04 LTS)
===========================================================
This guide is quite complete, but you should always think about before blindly copying the commands.
# Recommendation for file systems:
# /mnt/database on SSD
# /mnt/tiles on HDD
# Update your freshly installed Ubuntu 16.04:
sudo apt update && sudo apt upgrade
# Install some useful packages:
sudo apt install vim git screen htop iftop
# Install the apache web server:
sudo apt install apache2
# Install Postgresql database:
sudo apt install postgresql-9.5 postgresql-9.5-postgis-2.2
# change default path via symlink (works better than changing postgres config):
sudo chown postgres /mnt/database
sudo chgrp postgres /mnt/database
sudo service postgresql stop
sudo cp -a /var/lib/postgresql/9.5/main /mnt/database
sudo rm -r /var/lib/postgresql/9.5
sudo ln -s /mnt/database /var/lib/postgresql/9.5
sudo service postgresql start
# Tweaks:
Edit the file /etc/postgresql/9.5/main/postgresql.conf and make the following changes:
shared_buffers = 128MB
work_mem = 256MB
maintenance_work_mem = 256MB
autovacuum = off
As root, edit /etc/sysctl.conf and add these lines near the top after the other “kernel” definitions:
# Increase kernel shared memory segments - needed for large databases
kernel.shmmax=268435456
# Install Mapnik renderer:
sudo apt install libmapnik3.0 libmapnik-dev mapnik-utils python-mapnik unifont
# Install tirex from source
sudo apt install devscripts libjson-perl libipc-sharelite-perl libgd-perl debhelper
mkdir ~/src && cd ~/src
git clone https://github.com/geofabrik/tirex
cd tirex
make deb
cd ~/src
sudo dpkg -i tirex-core_0.5.2_amd64.deb
sudo dpkg -i tirex-backend-mapnik_0.5.2_amd64.deb
# Install mod_tile from source
sudo apt install autoconf apache2-dev
cd ~/src
git clone git://github.com/openstreetmap/mod_tile.git
cd mod_tile
echo '/etc/renderd.conf' > debian/renderd.conffiles
debuild -i -b -us -uc
cd ~/src
sudo dpkg -i libapache2-mod-tile_0.4-12~precise2_amd64.deb
sudo a2enmod tile
# copy conf/tile.conf into /etc/apache2/mods-available/tile.conf
# in /etc/tirex/renderer/mapnik.conf:
# plugindir=/usr/lib/mapnik/3.0/input
# fontdir=/usr/share/fonts/truetype
# fontdir_recurse=1
# in /etc/apache2/sites-available/tileserver_site.conf change:
# comment out "LoadTileConfigFile /etc/renderd.conf"
# change "ModTileRenderdSocketName /var/lib/tirex/modtile.sock"
sudo rm -rf /var/lib/mod_tile
sudo ln -s /var/lib/tirex/tiles /var/lib/mod_tile
# fix "error" of mod-tile installation (in fact there is no error, apache just can't load the default configs):
sudo apt install -f
# Tweak Apache for huge tile delivery speed-up
# edit /etc/apache2/mods-available/mpm_prefork.conf:
<IfModule mpm_prefork_module>
ServerLimit 5000
StartServers 500
MinSpareServers 20
MaxSpareServers 5000
MaxRequestWorkers 5000
MaxConnectionsPerChild 1000
</IfModule>
a2dismod mpm_event
a2enmod mpm_prefork
# Install osm2pgsql from source
sudo apt install cmake libbz2-dev libgeos-dev libgeos++-dev libproj-dev lua5.3 liblua5.3-dev
cd ~/src
git clone git://github.com/openstreetmap/osm2pgsql.git
cd osm2pgsql
mkdir build && cd build
cmake ..
make
sudo make install
# Create user and database
sudo -u postgres -i
createuser --createdb osmuser // superuser!?
createuser tirex // read only!?
exit
createdb gis
psql -d gis -c 'CREATE EXTENSION postgis;'
# Download OpenTopoMap files
cd ~
git clone https://github.com/der-stefan/OpenTopoMap.git
cd ~/OpenTopoMap/mapnik
# get the generalized water polygons from http://openstreetmapdata.com/
mkdir data && cd data
wget http://data.openstreetmapdata.com/water-polygons-generalized-3857.zip
wget http://data.openstreetmapdata.com/water-polygons-split-3857.zip
unzip water-polygons*
# Now you need to create the hillshade and contours. We can't provide the data, since it consumes ~500 GB.
# But there is a long howto in HOWTO_DEM
# Load data into database
mkdir ~/data && cd ~/data
wget http://download.geofabrik.de/europe-latest.osm.pbf
cd ~/data/updates
wget http://download.geofabrik.de/europe-updates/state.txt
screen osm2pgsql --slim -d gis -C 12000 --number-processes 10 --flat-nodes /mnt/database/flat-nodes/gis-flat-nodes.bin --style ~/OpenTopoMap/mapnik/osm2pgsql/opentopomap.style ~/data/planet-latest.osm.pbf
screen osm2pgsql --slim -d gis -C 12000 --tablespace-slim-data hdd --tablespace-slim-index hdd --number-processes 10 --flat-nodes /mnt/database/flat-nodes/gis-flat-nodes.bin --style ~/OpenTopoMap/mapnik/osm2pgsql/opentopomap.style ~/data/planet-latest.osm.pbf
# Now do the preprocessing of the OSM data for low zoom levels
# A complete copy-paste guide is HOWTO_Preprocessing
# Find out the sizes of the databases:
psql -d gis -c "SELECT pg_database.datname, pg_size_pretty(pg_database_size(pg_database.datname)) AS size FROM pg_database;"
# Optional: Install awstats, munin and letsencrypt
sudo apt install awstats libgeo-ip-perl libgeo-ipfree-perl
sudo apt install munin
======== below not verified yet ==========================================================================
# Install osmosis (for diff updates)
sudo apt install osmosis
# Set up osmosis working dir for daily updates
osmosis --rrii workingDirectory=~/data/updates
# edit configuration.txt to baseUrl=http://download.geofabrik.de/europe/germany/bayern/mittelfranken-updates/
# Update data
# Get state.txt file e.g. from http://osm.personalwerk.de/replicate-sequences/
osmosis --rri workingDirectory=~/data/updates --simplify-change --write-xml-change ~/data/updates/changes.osc.gz
osm2pgsql --append --slim -d gis -C 12000 --number-processes 5 --flat-nodes /mnt/database/flat-nodes/gis-flat-nodes.bin --style ~/OpenTopoMap/mapnik/osm2pgsql/opentopomap.style ~/data/updates/changes.osc.gz
# now we need to touch the outdated metatiles. Perhaps we need to write a script for this???
# touch -d "$(date -R -r 0.meta) - 10 years" 0.meta
rm ~/data/updates/changes.osc.gz
# Install cronjob:
crontab -e
*/5 * * * * update.sh > output
# perhaps we need to source out the index planet_osm_ways_nodes to the HDD in order to save space on the SSD:
CREATE TABLESPACE anderertablespace LOCATION '/home/irgendwas'; ALTER INDEX planet_osm_ways_nodes SET TABLESPACE anderertablespace;