Difference between revisions of "How to Setup an Open Street Map Tile Server under Ubuntu 18.04 in a Proxmox Container"

From steamWiki
Jump to: navigation, search
 
Line 2: Line 2:
  
 
=Install Prerequisites=
 
=Install Prerequisites=
#Run ''sudo apt update''
+
#Log into your machine as a ''sudo'' capable user
#Run ''sudo apt upgrade''
+
#Make sure your system is up to date by running <pre>sudo apt update&#10;sudo apt upgrade</pre>
#Run ''sudo dpkg-reconfigure locales''
+
#Ensure your locale is set to UTF-8 by running <pre>sudo dpkg-reconfigure locales</pre> and selecting '''en_US.UTF-8 UTF-8''' on both screens
#*select "en_US.UTF-8 UTF-8" on both screens
+
#Install the Open Street Map repository by running <pre>sudo apt install software-properties-common&#10;sudo add-apt-repository ppa:osmadmins/ppa</pre>
#Run ''sudo apt install software-properties-common''
+
#Install the packages we'll need by running <pre>sudo apt install postgresql postgresql-contrib postgis postgresql-10-postgis-2.4 osm2pgsql libapache2-mod-tile renderd curl unzip gdal-bin mapnik-utils libmapnik-dev nodejs npm ttf-dejavu fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted ttf-unifont</pre>
#*hit '''Enter''' to continue
+
#*When prompted, choose '''Yes''' to "enable mod_tile in the apache config"
#Run ''sudo add-apt-repository ppa:osmadmins/ppa''
+
#Install the node.js Mapnik Stylesheet Compiler by running <pre>sudo npm install -g carto</pre>
#Run ''sudo apt install postgresql postgresql-contrib postgis postgresql-10-postgis-2.4 osm2pgsql libapache2-mod-tile renderd curl unzip gdal-bin mapnik-utils libmapnik-dev nodejs npm ttf-dejavu fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted ttf-unifont''
+
#Setup our database by running <pre>sudo -u postgres -i</pre> and then from within the postgres prompt running <pre>createuser osm&#10;createdb -E UTF8 -O osm gis&#10;psql -c "CREATE EXTENSION postgis;" -d gis&#10;psql -c "CREATE EXTENSION hstore;" -d gis&#10;psql -c "ALTER TABLE spatial_ref_sys OWNER TO osm;" -d gis&#10;exit</pre>
#*choose '''Yes''' to "enable mod_tile in the apache config"
+
#Create our Tile Server user and get into his home directory by running <pre>sudo adduser osm&#10;su - osm</pre>
#Run ''sudo npm install -g carto''
+
##Download a generic OSM mapnik style by running <pre>wget https://github.com/gravitystorm/openstreetmap-carto/archive/v4.21.1.tar.gz</pre>
#Run ''sudo -u postgres -i''
+
##Uncompress the style by running <pre>tar xvf v*.tar.gz</pre>
##Run ''createuser osm''
+
##Download a PBF map file by running <pre>wget -c http://download.geofabrik.de/north-america/us/georgia-latest.osm.pbf</pre>
##Run ''createdb -E UTF8 -O osm gis''
 
##Run ''psql -c "CREATE EXTENSION postgis;" -d gis''
 
##Run ''psql -c "CREATE EXTENSION hstore;" -d gis''
 
##Run ''psql -c "ALTER TABLE spatial_ref_sys OWNER TO osm;" -d gis''
 
##Run ''exit''
 
#Run ''sudo adduser osm''
 
#Run ''su - osm''
 
##Run ''wget https://github.com/gravitystorm/openstreetmap-carto/archive/v4.21.1.tar.gz''
 
##Run ''tar xvf v*.tar.gz''
 
##Run ''wget -c http://download.geofabrik.de/north-america/us/georgia-latest.osm.pbf''
 
 
##*This tutorial is downloading only the state of Georgia in the US
 
##*This tutorial is downloading only the state of Georgia in the US
 
##*You can download the entire planet's PBF file [http://planet.openstreetmap.org/pbf/planet-latest.osm.pbf here] or select individual states and countries [http://download.geofabrik.de here].
 
##*You can download the entire planet's PBF file [http://planet.openstreetmap.org/pbf/planet-latest.osm.pbf here] or select individual states and countries [http://download.geofabrik.de here].
 
#*At this point the [https://www.linuxbabe.com/ubuntu/openstreetmap-tile-server-ubuntu-18-04-osm standard Ubuntu 18.04 setup guide] I followed had you configure your machine's swap.  Since Proxmox handles this we'll skip that step
 
#*At this point the [https://www.linuxbabe.com/ubuntu/openstreetmap-tile-server-ubuntu-18-04-osm standard Ubuntu 18.04 setup guide] I followed had you configure your machine's swap.  Since Proxmox handles this we'll skip that step
##Run ''osm2pgsql --slim -d gis --hstore --multi-geometry --number-processes 2 --tag-transform-script /home/osm/openstreetmap-carto-4.21.1/openstreetmap-carto.lua --style /home/osm/openstreetmap-carto-4.21.1/openstreetmap-carto.style -C 3072 /home/osm/georgia-latest.osm.pbf''
+
##Import your PBF file by running <pre>osm2pgsql --slim -d gis --hstore --multi-geometry --number-processes 2 --tag-transform-script /home/osm/openstreetmap-carto-4.21.1/openstreetmap-carto.lua --style /home/osm/openstreetmap-carto-4.21.1/openstreetmap-carto.style -C 3072 /home/osm/georgia-latest.osm.pbf</pre>
##Run ''cd /home/osm/openstreetmap-carto-4.21.1''
+
##Move into the carto directory by running <pre>cd /home/osm/openstreetmap-carto-4.21.1</pre>
##Run ''scripts/get-shapefiles.py''
+
##Get shapefiles by running <pre>scripts/get-shapefiles.py</pre>
##Run ''carto project.mml > style.xml''
+
##Build your Mapnik xml stylesheet by running <pre>carto project.mml > style.xml</pre>
 
#*You're going to see lots of Warnings.  [https://github.com/gravitystorm/openstreetmap-carto/issues/3183 this is ok].  Your tile server will work fine.
 
#*You're going to see lots of Warnings.  [https://github.com/gravitystorm/openstreetmap-carto/issues/3183 this is ok].  Your tile server will work fine.
##Run ''exit''
+
##Get back to your ''sudo'' user by running <pre>exit</pre>
#Run ''sudo nano /etc/renderd.conf'' and set the following
+
#Modify the renderd config file by running <pre>sudo nano /etc/renderd.conf</pre> and setting the following variables <pre>[renderd]&#10; set "num_threads=4" #set to the number of CPU Core's you have.  This can be found under the Resources section of your Promox Container on the Proxmox web GUI&#10;[mapnik]&#10; set "plugins_dir=/usr/lib/mapnik/3.0/input"&#10; set "font_dir=/usr/share/fonts/truetype"&#10; set "find_dir_recursive=true"&#10;[default]&#10; set "XML=/home/osm/openstreetmap-carto-4.21.1/style.xml"&#10; set "HOST=YOURSERVER.COM"</pre>
/nowiki>[renderd]
+
#Edit renderd's daemon script by running <pre>sudo nano /etc/init.d/renderd</pre> and setting the following <pre>set "RUNASUSER=osm"</pre>
set "num_threads=4" #set to the number of CPU Core's you have.  This can be found under the Resources section of your Promox Container on the Proxmox web GUI
+
#Make ''osm'' the owner of the ''mod_tile'' library by running <pre>sudo chown osm:osm /var/lib/mod_tile/ -R</pre>
[mapnik]
+
#Reload the daemon scripts by running <pre>sudo systemctl daemon-reload</pre>
set "plugins_dir=/usr/lib/mapnik/3.0/input"
+
#Restart renderd with the new ''osm'' user by running <pre>sudo systemctl restart renderd</pre>
set "font_dir=/usr/share/fonts/truetype"
+
#Edit Apache's tile server configuration by running <pre>sudo nano /etc/apache2/sites-available/tileserver_site.conf</pre> and setting the following variables <pre>set "ServeName YOURSERVER.COM"&#10;#ServerAlias a.tile.mytileserver.org b.tile.mytileserver.org c.tile.mytileserver.org</nowiki> #comment out this line</pre>
set "find_dir_recursive=true"
+
#Modify the slippymap.html page by running <pre>sudo nano /var/www/osm/slippymap.html</pre> and setting the following <pre><title>MY NEW COOL TITLE!</title>&#10;var lat=MY.START_LAT&#10;var long=MY.START_LONG&#10;var zoom=MY_PREFERRED_ZOOM_LEVEL</pre>
[default]
+
#Delete Apache's default landing page by running <pre>sudo rm /var/www/index.html</pre>
set "XML=/home/osm/openstreetmap-carto-4.21.1/style.xml"
+
#Create a new redirect page so that when people visit http://YOURSERVER.COM they get to the interactive slippymap page by running <pre>sudo nano /var/www/index.html</pre> and filling in the file with <pre><html>&#10; <head>&#10; <meta http-equiv="refresh" content="0; url=http://YOURSERVER.COM/osm/slippymap.html" />&#10; </head>&#10;</html></pre>
set "HOST=YOURSERVER.COM"</nowiki>
 
#Run ''sudo nano /etc/init.d/renderd'' and set the following
 
<nowiki>set "RUNASUSER=osm"</nowiki>
 
#Run ''sudo chown osm:osm /var/lib/mod_tile/ -R''
 
#Run ''sudo systemctl daemon-reload''
 
#Run ''sudo systemctl restart renderd''
 
#Run ''sudo nano /etc/apache2/sites-available/tileserver_site.conf'' and set the following
 
<nowiki>set "ServeName YOURSERVER.COM"
 
#ServerAlias a.tile.mytileserver.org b.tile.mytileserver.org c.tile.mytileserver.org</nowiki> #comment out this line</nowiki>
 
#Run ''sudo nano /var/www/osm/slippymap.html'' and set the following
 
<nowiki><title>MY NEW COOL TITLE!</title>
 
var lat=MY.START_LAT
 
var long=MY.START_LONG
 
var zoom=MY_PREFERRED_ZOOM_LEVEL</nowiki>
 
#Run ''sudo rm /var/www/index.html''
 
#Run ''sudo nano /var/www/index.html'' and fill with
 
<nowiki><html>
 
<head>
 
<meta http-equiv="refresh" content="0; url=http://YOURSERVER.COM/osm/slippymap.html" />
 
</head>
 
</html></nowiki>
 
 
 
 
*''Most of basis for this How To came from https://www.linuxbabe.com/ubuntu/openstreetmap-tile-server-ubuntu-18-04-osm''
 
*''Most of basis for this How To came from https://www.linuxbabe.com/ubuntu/openstreetmap-tile-server-ubuntu-18-04-osm''
  
 
[[Category: Linux]]
 
[[Category: Linux]]

Latest revision as of 11:59, 9 July 2019

Open Street Map is a well know, open source (and crown sourced) alternative to the likes of Google Maps and Bing Maps. Open Street Maps content (ie: maps) are provided to users and applications by what are known as Tile Servers. This tutorial will show you how to setup an Open Street Map Tile Server of your own in a Linux Container running Ubuntu 18.04 under Proxmox. Furthermore we'll use the built in and simple Map Viewer. This means that this container can provide map tiles to other applications (such as an ADS-B Virtual Radar Server) as well as providing its own native Google Maps -like capability all while being totally disconnected from the internet.

Install Prerequisites

  1. Log into your machine as a sudo capable user
  2. Make sure your system is up to date by running
    sudo apt update
    sudo apt upgrade
  3. Ensure your locale is set to UTF-8 by running
    sudo dpkg-reconfigure locales
    and selecting en_US.UTF-8 UTF-8 on both screens
  4. Install the Open Street Map repository by running
    sudo apt install software-properties-common
    sudo add-apt-repository ppa:osmadmins/ppa
  5. Install the packages we'll need by running
    sudo apt install postgresql postgresql-contrib postgis postgresql-10-postgis-2.4 osm2pgsql libapache2-mod-tile renderd curl unzip gdal-bin mapnik-utils libmapnik-dev nodejs npm ttf-dejavu fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted ttf-unifont
    • When prompted, choose Yes to "enable mod_tile in the apache config"
  6. Install the node.js Mapnik Stylesheet Compiler by running
    sudo npm install -g carto
  7. Setup our database by running
    sudo -u postgres -i
    and then from within the postgres prompt running
    createuser osm
    createdb -E UTF8 -O osm gis
    psql -c "CREATE EXTENSION postgis;" -d gis
    psql -c "CREATE EXTENSION hstore;" -d gis
    psql -c "ALTER TABLE spatial_ref_sys OWNER TO osm;" -d gis
    exit
  8. Create our Tile Server user and get into his home directory by running
    sudo adduser osm
    su - osm
    1. Download a generic OSM mapnik style by running
      wget https://github.com/gravitystorm/openstreetmap-carto/archive/v4.21.1.tar.gz
    2. Uncompress the style by running
      tar xvf v*.tar.gz
    3. Download a PBF map file by running
      wget -c http://download.geofabrik.de/north-america/us/georgia-latest.osm.pbf
      • This tutorial is downloading only the state of Georgia in the US
      • You can download the entire planet's PBF file here or select individual states and countries here.
    1. Import your PBF file by running
      osm2pgsql --slim -d gis --hstore --multi-geometry --number-processes 2 --tag-transform-script /home/osm/openstreetmap-carto-4.21.1/openstreetmap-carto.lua --style /home/osm/openstreetmap-carto-4.21.1/openstreetmap-carto.style -C 3072 /home/osm/georgia-latest.osm.pbf
    2. Move into the carto directory by running
      cd /home/osm/openstreetmap-carto-4.21.1
    3. Get shapefiles by running
      scripts/get-shapefiles.py
    4. Build your Mapnik xml stylesheet by running
      carto project.mml > style.xml
    • You're going to see lots of Warnings. this is ok. Your tile server will work fine.
    1. Get back to your sudo user by running
      exit
  9. Modify the renderd config file by running
    sudo nano /etc/renderd.conf
    and setting the following variables
    [renderd]
    	set "num_threads=4" #set to the number of CPU Core's you have.  This can be found under the Resources section of your Promox Container on the Proxmox web GUI
    [mapnik]
    	set "plugins_dir=/usr/lib/mapnik/3.0/input"
    	set "font_dir=/usr/share/fonts/truetype"
    	set "find_dir_recursive=true"
    [default]
    	set "XML=/home/osm/openstreetmap-carto-4.21.1/style.xml"
    	set "HOST=YOURSERVER.COM"
  10. Edit renderd's daemon script by running
    sudo nano /etc/init.d/renderd
    and setting the following
    set "RUNASUSER=osm"
  11. Make osm the owner of the mod_tile library by running
    sudo chown osm:osm /var/lib/mod_tile/ -R
  12. Reload the daemon scripts by running
    sudo systemctl daemon-reload
  13. Restart renderd with the new osm user by running
    sudo systemctl restart renderd
  14. Edit Apache's tile server configuration by running
    sudo nano /etc/apache2/sites-available/tileserver_site.conf
    and setting the following variables
    set "ServeName YOURSERVER.COM"
    #ServerAlias a.tile.mytileserver.org b.tile.mytileserver.org c.tile.mytileserver.org</nowiki> #comment out this line
  15. Modify the slippymap.html page by running
    sudo nano /var/www/osm/slippymap.html
    and setting the following
    <title>MY NEW COOL TITLE!</title>
    var lat=MY.START_LAT
    var long=MY.START_LONG
    var zoom=MY_PREFERRED_ZOOM_LEVEL
  16. Delete Apache's default landing page by running
    sudo rm /var/www/index.html
  17. Create a new redirect page so that when people visit http://YOURSERVER.COM they get to the interactive slippymap page by running
    sudo nano /var/www/index.html
    and filling in the file with
    <html>
    	<head>
    		<meta http-equiv="refresh" content="0; url=http://YOURSERVER.COM/osm/slippymap.html" />
    	</head>
    </html>