Wechseln zu:Navigation, Suche
Wiki

Vorlage:Languages

These instructions are for the installation of Nominatim V2, which can be found in http://github.com/twain47/Nominatim.git.

For instructions for the older Nominatim V1 that is part of osm2pgsql, see Nominatim/Installation_V1.

Prerequisites

Software

Ubuntu/Debian

In standard Debian/Ubuntu distributions these should be available as packages.

 apt-get install php5-pgsql postgis postgresql php5 php-pear gcc proj libgeos-c1 postgresql-contrib subversion git
 apt-get install postgresql-9.1-postgis postgresql-server-dev-9.1
 apt-get install build-essential libxml2-dev libgeos-dev libpq-dev libbz2-dev libtool automake

In addition, you need to install the pear::DB module:

 pear install DB


Fedora/CentOS

Install these packages from the base and epsl repositories. proj-epsg is required, but broken:

 yum install php-pgsql postgis php php-pear php-pear-db gcc postgres postgresql-server postgresql-contrib bzip2-devel proj-devel geos-devel subversion git

Run these commands assuming that you haven't set up postgres:

 service postgresql initdb
 service postgresql start
 su postgres
 createuser -sdr <your username>
 exit

Run the following command to work around path issues with postgis.sql

 ln -s /usr/share/pgsql/contrib/postgis-64.sql /usr/share/pgsql/contrib/postgis-1.5/postgis.sql

There is also a problem with proj-epsg on some platforms, so we manually install it:

 wget ftp://ftp.muug.mb.ca/mirror/fedora/epel/6/x86_64/proj-epsg-4.7.0-1.el6.x86_64.rpm
 rpm -i proj-epsg-4.7.0-1.el6.x86_64.rpm  --nodeps

PostgreSQL and PostGIS Version

Currently, PostgreSQL 9.x is recommended, although it should also work with 8.4. 8.3 is no longer supported.

Also, Nominatim makes heavy use of the ST_CONTAINS PostGIS function which seems to be rather slow on PostGIS versions before 1.5, so if you have the option of using PostGIS 1.5 or later, that would be a good idea. Some versions of 1.3 also have stability problems.

Tuning PostgreSQL

You might want to tune your PostgreSQL installation so that the later steps make best use of your hardware. You should tune the following parameters:

  • shared_buffers (4GB)
  • maintenance_work_mem (10GB)
  • work_mem (50MB)
  • effective_cache_size (24GB)
  • synchronous_commit = off
  • checkpoint_segments = 100
  • checkpoint_timeout = 10min
  • checkpoint_completion_target = 0.9

The numbers in brackets behind some parameters seem to work fine for 32GB RAM machine. Adjust to your setup.

For the initial import, you should also set:

  • fsync = off
  • full_page_writes = off

Don't forget to switch them on again afterwards or you risk database corruption.

Autovacuum must not be switched off because it ensures that the tables are frequently analysed.

Hardware

For a full planet install you will need a minimum of 600GB of hard disk space (as of January 2012, take into account that the OSM database is growing fast).

On poldi the complete initial import required around 5 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.

First Installation

Compiling the Required Software

Next to the prerequisites mentioned above, you will need to get nominatim and osm2pgsql.

Osm2pgsql

You need to get the latest version of osm2pgsql from SVN and compile it. The process is described on the osm2pgsql page. Do not try to use osm2pgsql versions that are shipped with your Linux distribution. They are likely to old and will not work.

Note: make sure that osm2pgsql is compiled as a 64-bit binary. 32-bit mode will not work, not even for small OSM files.

Nominatim

Get the latest source code from Github (if necessary install git first: sudo apt-get install git)

 git clone git://github.com/twain47/Nominatim.git

Compile the postgresql module:

 cd module
 make

Compile the Nominatim tool:

 cd nominatim
 ./autogen.sh
 ./configure
 make

You can customize Nominatim by creating a local configuration file settings/local.php. Have a look at settings/settings.php for available configuration settings.

Here is an example of a local.php:

 <?php
   // Paths
   @define('CONST_Postgresql_Version', '9.1');
   @define('CONST_Osm2pgsql_Binary', '/opt/osm/osm2pgsql/osm2pgsql');
   // Website settings
   @define('CONST_Website_BaseURL', 'http://mysite/nominatim/');

Download (optional) wikipedia data

Wikipedia can be used as an optional auxiliary data source to help indicate the importance of osm features. Nominatim will work without this information but it will improve the quality of the results if this is installed. This data is available as a binary download.

 wget --output-document=data/wikipedia_article.sql.bin http://www.nominatim.org/data/wikipedia_article.sql.bin
 wget --output-document=data/wikipedia_redirect.sql.bin http://www.nominatim.org/data/wikipedia_redirect.sql.bin

Combined the 2 files are around 1.5GB and add around 30GB to the install size of nominatim. They also increase the install time by an hour or so.

Create website user

Create the website user www-data:

 createuser -SDR www-data

For the installation process, you must have this user. If you want to run the website under another user, see comment in section Set up the website. You also need a user with superuser rights for the account that is doing the import. You can create such a postgres superuser account by running sudo -u postgres createuser -s <your user name>. You must not run the import as user www-data.

Import and index OSM data

First download a Planet File. Using a file in PBF format is recommended.

Now start the import:

 ./utils/setup.php --osm-file <your planet file> --all

This will take as little as an hour for a small country extract and as much as 10 days for a full-scale planet import.

The import produces a lot of log messages, which you should carefully examine. If you get DEADLOCK messages at some point, then it is quite likely that an error earlier in the process was the cause.

Add special phrases

Add country codes and country names to the search index:

 ./utils/specialphrases.php --countries > specialphrases_countries.sql
 psql -d nominatim -f specialphrases_countries.sql

If you want to be able to search for special amenities like pubs in Dublin, you need to import special phrases from this wiki like this:

 ./utils/specialphrases.php --wiki-import > specialphrases.sql
 psql -d nominatim -f specialphrases.sql

This may be repeated from time to time when there are changes in the wiki. There is no need to repeat it after each update.

If you do not need phrases for all languages, edit utils/specialphrases.php and delete unneeded languages at the beginning of the file.

Set up the website for use with Apache

Create the directory for the website and make sure it is writable by you and readable by apache:

 sudo mkdir -m 755 /var/www/nominatim
 sudo chown <your username> /var/www/nominatim

Populate the website directory with the necessary symlinks:

 ./utils/setup.php --create-website /var/www/nominatim

You will need to make sure settings/local.php is configured with correct values for CONST_Website_BaseURL.

Also make sure your Apache configuration contains the following settings for the directory:

 <Directory "/var/www/nominatim/">
    Options FollowSymLinks MultiViews
    AddType text/html   .php     
 </Directory>

Note: The name of the website user is hard-coded into Nominatim. In most Linux distributions, apache will run as www-data, so this will work without any further modifications. If your web server runs under a different name (e.g. in Fedora and CentOS apache runs as user apache), simply alter the name of the www-data user in postgresql after the import has finished, e.g. psql -d nominatim -c 'ALTER USER "www-data" RENAME TO "apache".

Updates

There are many different possibilities to update your Nominatim database. The following section describes how to keep it up-to-date with osmosis. For a list of other methods see the output of ./utils/update.php --help.

Getting osmosis

Download and install osmosis. Both, the latest release and the latest git version will work fine with Nominatim. For instructions see Osmosis/Installation.

Adapt your settings/local.php to point to the osmosis binary. E.g.

 @define('CONST_Osmosis_Binary', CONST_BasePath.'/osmosis-0.40.1/bin/osmosis');

Setting up the update process

Next the update needs to be initialised. Determine the release date of your OSM file and subtract a day to make sure there will be no gap in the data. Use this date to set up osmosis:

 ./utils/setup.php --osmosis-init --osmosis-init-date 2011-11-11T11:11

Enabling hierarchical updates

When a place is updated in the database, all places that contain this place in their address need to be updated as well. These hierarchical updates are disabled by default because they slow down the initial import. Enable them by commenting the RETURN NEW around line 1110 in sql/functions.sql.

The functions then need to be reloaded:

 ./utils/setup.php --create-functions

Updating Nominatim

The following command will keep your database constantly up to date:

 ./utils/update.php --import-osmosis-all --no-npi