2021-08-21 11:45:22 +03:00
|
|
|
#!/bin/bash -e
|
2020-05-06 00:10:35 +03:00
|
|
|
#
|
|
|
|
# hacks for broken vagrant box #DOCS:
|
|
|
|
sudo rm -f /var/lib/dpkg/lock #DOCS:
|
|
|
|
export APT_LISTCHANGES_FRONTEND=none #DOCS:
|
|
|
|
export DEBIAN_FRONTEND=noninteractive #DOCS:
|
|
|
|
|
|
|
|
# *Note:* these installation instructions are also available in executable
|
2024-06-24 21:07:02 +03:00
|
|
|
# form for use with vagrant under vagrant/Install-on-Ubuntu-24.sh.
|
2020-05-06 00:10:35 +03:00
|
|
|
#
|
|
|
|
# Installing the Required Software
|
|
|
|
# ================================
|
|
|
|
#
|
2024-06-24 21:07:02 +03:00
|
|
|
# These instructions expect that you have a freshly installed Ubuntu 24.04.
|
2020-05-06 00:10:35 +03:00
|
|
|
#
|
2021-08-21 11:45:22 +03:00
|
|
|
# Make sure all packages are up-to-date by running:
|
2020-05-06 00:10:35 +03:00
|
|
|
#
|
|
|
|
|
2024-02-19 19:08:23 +03:00
|
|
|
sudo apt-get update -qq
|
2020-05-06 00:10:35 +03:00
|
|
|
|
|
|
|
# Now you can install all packages needed for Nominatim:
|
|
|
|
|
2024-06-24 21:07:02 +03:00
|
|
|
sudo apt-get install -y osm2pgsql postgresql-postgis postgresql-postgis-scripts \
|
|
|
|
pkg-config libicu-dev virtualenv git
|
2022-12-13 14:12:05 +03:00
|
|
|
|
|
|
|
|
2020-05-06 00:10:35 +03:00
|
|
|
#
|
|
|
|
# System Configuration
|
|
|
|
# ====================
|
|
|
|
#
|
|
|
|
# The following steps are meant to configure a fresh Ubuntu installation
|
|
|
|
# for use with Nominatim. You may skip some of the steps if you have your
|
|
|
|
# OS already configured.
|
|
|
|
#
|
|
|
|
# Creating Dedicated User Accounts
|
|
|
|
# --------------------------------
|
|
|
|
#
|
|
|
|
# Nominatim will run as a global service on your machine. It is therefore
|
|
|
|
# best to install it under its own separate user account. In the following
|
|
|
|
# we assume this user is called nominatim and the installation will be in
|
|
|
|
# /srv/nominatim. To create the user and directory run:
|
|
|
|
#
|
|
|
|
# sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
|
|
|
|
#
|
|
|
|
# You may find a more suitable location if you wish.
|
|
|
|
#
|
2023-06-13 15:12:56 +03:00
|
|
|
# The following instructions assume you are logged in as this user.
|
|
|
|
# You can also switch to the user with:
|
|
|
|
#
|
|
|
|
# sudo -u nominatim bash
|
|
|
|
#
|
2020-05-06 00:10:35 +03:00
|
|
|
# To be able to copy and paste instructions from this manual, export
|
|
|
|
# user name and home directory now like this:
|
|
|
|
#
|
2021-08-21 11:45:22 +03:00
|
|
|
if [ "x$USERNAME" == "x" ]; then #DOCS:
|
2020-05-06 00:10:35 +03:00
|
|
|
export USERNAME=vagrant #DOCS: export USERNAME=nominatim
|
|
|
|
export USERHOME=/home/vagrant #DOCS: export USERHOME=/srv/nominatim
|
2021-08-21 11:45:22 +03:00
|
|
|
fi #DOCS:
|
2020-05-06 00:10:35 +03:00
|
|
|
#
|
|
|
|
# **Never, ever run the installation as a root user.** You have been warned.
|
|
|
|
#
|
|
|
|
# Make sure that system servers can read from the home directory:
|
|
|
|
|
|
|
|
chmod a+x $USERHOME
|
|
|
|
|
|
|
|
# Setting up PostgreSQL
|
|
|
|
# ---------------------
|
|
|
|
#
|
|
|
|
# Tune the postgresql configuration, which is located in
|
2024-06-29 17:27:26 +03:00
|
|
|
# `/etc/postgresql/16/main/postgresql.conf`. See section *Tuning the PostgreSQL database*
|
2023-08-31 02:11:54 +03:00
|
|
|
# in [the installation page](../admin/Installation.md#tuning-the-postgresql-database)
|
2020-05-06 00:10:35 +03:00
|
|
|
# for the parameters to change.
|
|
|
|
#
|
|
|
|
# Restart the postgresql service after updating this config file.
|
|
|
|
|
2021-08-21 11:45:22 +03:00
|
|
|
if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
|
2024-06-24 21:07:02 +03:00
|
|
|
sudo pg_ctlcluster 16 main start #DOCS:
|
2021-08-21 11:45:22 +03:00
|
|
|
else #DOCS:
|
2021-08-22 19:42:20 +03:00
|
|
|
sudo systemctl restart postgresql
|
2021-08-21 11:45:22 +03:00
|
|
|
fi #DOCS:
|
2020-05-06 00:10:35 +03:00
|
|
|
#
|
|
|
|
# Finally, we need to add two postgres users: one for the user that does
|
|
|
|
# the import and another for the webserver which should access the database
|
|
|
|
# for reading only:
|
|
|
|
#
|
|
|
|
|
|
|
|
sudo -u postgres createuser -s $USERNAME
|
|
|
|
sudo -u postgres createuser www-data
|
|
|
|
|
|
|
|
#
|
|
|
|
# Installing Nominatim
|
|
|
|
# ====================
|
|
|
|
#
|
|
|
|
# Building and Configuration
|
|
|
|
# --------------------------
|
|
|
|
#
|
|
|
|
# Get the source code from Github and change into the source directory
|
|
|
|
#
|
|
|
|
if [ "x$1" == "xyes" ]; then #DOCS: :::sh
|
|
|
|
cd $USERHOME
|
2024-06-24 21:07:02 +03:00
|
|
|
git clone https://github.com/openstreetmap/Nominatim.git
|
2020-05-06 00:10:35 +03:00
|
|
|
cd Nominatim
|
|
|
|
else #DOCS:
|
|
|
|
cd $USERHOME/Nominatim #DOCS:
|
|
|
|
fi #DOCS:
|
|
|
|
|
|
|
|
# When installing the latest source from github, you also need to
|
|
|
|
# download the country grid:
|
|
|
|
|
|
|
|
if [ ! -f data/country_osm_grid.sql.gz ]; then #DOCS: :::sh
|
2022-12-20 18:55:47 +03:00
|
|
|
wget -O data/country_osm_grid.sql.gz https://nominatim.org/data/country_grid.sql.gz
|
2020-05-06 00:10:35 +03:00
|
|
|
fi #DOCS:
|
|
|
|
|
2024-06-24 21:07:02 +03:00
|
|
|
# Nominatim should be installed in a separate Python virtual environment.
|
|
|
|
# Create the virtual environment:
|
|
|
|
|
|
|
|
virtualenv $USERHOME/nominatim-venv
|
|
|
|
|
|
|
|
# Now install Nominatim using pip:
|
|
|
|
|
|
|
|
cd $USERHOME/Nominatim
|
2024-06-27 22:26:12 +03:00
|
|
|
$USERHOME/nominatim-venv/bin/pip install packaging/nominatim-db
|
2020-05-06 00:10:35 +03:00
|
|
|
|
2024-06-24 21:07:02 +03:00
|
|
|
# Nominatim is now ready to use. The nominatim binary is available at
|
|
|
|
# `$USERHOME/venv/bin/nominatim`. If you want to have 'nominatim' in your
|
|
|
|
# path, simply activate the virtual environment:
|
2024-06-29 17:27:26 +03:00
|
|
|
#
|
|
|
|
#DOCS:```sh
|
|
|
|
# . $USERHOME/nominatim-venv/bin/activate
|
|
|
|
#DOCS:```
|
|
|
|
#
|
2024-06-24 21:07:02 +03:00
|
|
|
# You can continue with
|
2020-09-16 17:27:34 +03:00
|
|
|
# [importing a database from OSM data](../admin/Import.md). If you want to set up
|
2024-02-19 19:08:23 +03:00
|
|
|
# the API frontend first, continue reading.
|
2020-09-16 17:27:34 +03:00
|
|
|
#
|
2024-02-19 19:08:23 +03:00
|
|
|
# Setting up the Python frontend
|
|
|
|
# ==============================
|
|
|
|
#
|
2024-06-24 21:07:02 +03:00
|
|
|
# The Python frontend is contained in the nominatim-api package. To run
|
2024-06-29 17:27:26 +03:00
|
|
|
# the API as a webservice, you also need falcon with uvicorn to serve the API.
|
|
|
|
# It is generally recommended to run falcon/uvicorn on top of gunicorn.
|
2024-02-19 19:08:23 +03:00
|
|
|
#
|
2024-06-24 21:07:02 +03:00
|
|
|
# To install all packages, run:
|
2024-02-19 19:08:23 +03:00
|
|
|
|
|
|
|
#DOCS:```sh
|
2024-06-24 21:07:02 +03:00
|
|
|
$USERHOME/nominatim-venv/bin/pip install psycopg[binary] falcon uvicorn gunicorn
|
|
|
|
cd $USERHOME/Nominatim
|
|
|
|
$USERHOME/nominatim-venv/bin/pip install packaging/nominatim-api
|
2024-02-19 19:08:23 +03:00
|
|
|
#DOCS:```
|
|
|
|
|
|
|
|
# Next you need to create a systemd job that runs Nominatim on gunicorn.
|
|
|
|
# First create a systemd job that manages the socket file:
|
|
|
|
|
|
|
|
#DOCS:```sh
|
|
|
|
sudo tee /etc/systemd/system/nominatim.socket << EOFSOCKETSYSTEMD
|
|
|
|
[Unit]
|
|
|
|
Description=Gunicorn socket for Nominatim
|
|
|
|
|
|
|
|
[Socket]
|
|
|
|
ListenStream=/run/nominatim.sock
|
|
|
|
SocketUser=www-data
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOFSOCKETSYSTEMD
|
|
|
|
#DOCS:```
|
|
|
|
|
|
|
|
# Then create the service for Nominatim itself.
|
|
|
|
|
|
|
|
#DOCS:```sh
|
|
|
|
sudo tee /etc/systemd/system/nominatim.service << EOFNOMINATIMSYSTEMD
|
|
|
|
[Unit]
|
|
|
|
Description=Nominatim running as a gunicorn application
|
|
|
|
After=network.target
|
|
|
|
Requires=nominatim.socket
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
Environment="PYTHONPATH=/usr/local/lib/nominatim/lib-python/"
|
|
|
|
User=www-data
|
|
|
|
Group=www-data
|
|
|
|
WorkingDirectory=$USERHOME/nominatim-project
|
2024-06-24 21:07:02 +03:00
|
|
|
ExecStart=$USERHOME/nominatim-venv/bin/gunicorn -b unix:/run/nominatim.sock -w 4 -k uvicorn.workers.UvicornWorker nominatim_api.server.falcon.server:run_wsgi
|
2024-02-19 19:08:23 +03:00
|
|
|
ExecReload=/bin/kill -s HUP \$MAINPID
|
|
|
|
StandardOutput=append:/var/log/gunicorn-nominatim.log
|
|
|
|
StandardError=inherit
|
|
|
|
PrivateTmp=true
|
|
|
|
TimeoutStopSec=5
|
|
|
|
KillMode=mixed
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOFNOMINATIMSYSTEMD
|
|
|
|
#DOCS:```
|
|
|
|
|
|
|
|
# Activate the services:
|
|
|
|
|
|
|
|
if [ "x$NOSYSTEMD" != "xyes" ]; then #DOCS:
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
sudo systemctl enable nominatim.socket
|
|
|
|
sudo systemctl start nominatim.socket
|
|
|
|
sudo systemctl enable nominatim.service
|
|
|
|
fi #DOCS:
|
|
|
|
|
2020-09-16 17:27:34 +03:00
|
|
|
# Setting up a webserver
|
|
|
|
# ======================
|
2021-02-16 14:04:34 +03:00
|
|
|
#
|
2024-02-19 19:08:23 +03:00
|
|
|
# The webserver is only needed as a proxy between the public interface
|
|
|
|
# and the gunicorn service.
|
|
|
|
#
|
|
|
|
# The frontend will need configuration information from the project
|
|
|
|
# directory, which will be populated later
|
|
|
|
# [during the import process](../admin/Import.md#creating-the-project-directory)
|
|
|
|
# Already create the project directory itself now:
|
|
|
|
|
2021-02-16 14:04:34 +03:00
|
|
|
mkdir $USERHOME/nominatim-project
|
2021-08-21 11:45:22 +03:00
|
|
|
|
2024-06-24 21:07:02 +03:00
|
|
|
#
|
2020-09-16 17:27:34 +03:00
|
|
|
# Option 1: Using Apache
|
|
|
|
# ----------------------
|
|
|
|
#
|
|
|
|
if [ "x$2" == "xinstall-apache" ]; then #DOCS:
|
2024-06-24 21:07:02 +03:00
|
|
|
#
|
2024-02-19 19:08:23 +03:00
|
|
|
# First install apache itself and enable the proxy module:
|
2020-09-16 17:27:34 +03:00
|
|
|
|
2024-02-19 19:08:23 +03:00
|
|
|
sudo apt-get install -y apache2
|
|
|
|
sudo a2enmod proxy_http
|
2020-09-16 17:27:34 +03:00
|
|
|
|
2024-06-24 21:07:02 +03:00
|
|
|
#
|
2024-02-19 19:08:23 +03:00
|
|
|
# To set up proxying for Apache add the following configuration:
|
2020-09-16 17:27:34 +03:00
|
|
|
|
|
|
|
#DOCS:```sh
|
|
|
|
sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
|
2024-06-24 21:07:02 +03:00
|
|
|
|
2024-02-19 19:08:23 +03:00
|
|
|
ProxyPass /nominatim "unix:/run/nominatim.sock|http://localhost/"
|
2020-09-16 17:27:34 +03:00
|
|
|
EOFAPACHECONF
|
|
|
|
#DOCS:```
|
|
|
|
|
|
|
|
#
|
|
|
|
# Then enable the configuration and restart apache
|
|
|
|
#
|
|
|
|
|
2024-06-24 21:07:02 +03:00
|
|
|
#DOCS:```sh
|
|
|
|
sudo a2enconf nominatim
|
|
|
|
#DOCS:```
|
|
|
|
|
2021-08-21 11:45:22 +03:00
|
|
|
if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
|
|
|
|
sudo apache2ctl start #DOCS:
|
|
|
|
else #DOCS:
|
2020-09-16 17:27:34 +03:00
|
|
|
sudo systemctl restart apache2
|
2021-08-21 11:45:22 +03:00
|
|
|
fi #DOCS:
|
2020-09-16 17:27:34 +03:00
|
|
|
|
2024-07-29 17:41:24 +03:00
|
|
|
# The Nominatim API is now available at `http://localhost/nominatim/`. Point your browser
|
|
|
|
# to the status output `http://localhost/nominatim/status` to test if everything is ok.
|
2020-09-16 17:27:34 +03:00
|
|
|
|
|
|
|
fi #DOCS:
|
|
|
|
|
|
|
|
#
|
|
|
|
# Option 2: Using nginx
|
|
|
|
# ---------------------
|
|
|
|
#
|
|
|
|
if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
|
|
|
|
|
2024-02-19 19:08:23 +03:00
|
|
|
# First install nginx itself:
|
2020-09-16 17:27:34 +03:00
|
|
|
|
2024-02-19 19:08:23 +03:00
|
|
|
sudo apt-get install -y nginx
|
2020-09-16 17:27:34 +03:00
|
|
|
|
2024-06-24 21:07:02 +03:00
|
|
|
|
2020-09-16 17:27:34 +03:00
|
|
|
# Then create a Nginx configuration to forward http requests to that socket.
|
|
|
|
|
|
|
|
#DOCS:```sh
|
|
|
|
sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
|
|
|
|
server {
|
|
|
|
listen 80 default_server;
|
|
|
|
listen [::]:80 default_server;
|
|
|
|
|
2021-02-16 14:04:34 +03:00
|
|
|
root $USERHOME/nominatim-project/website;
|
2024-02-19 19:08:23 +03:00
|
|
|
index /search;
|
|
|
|
|
|
|
|
location /nominatim/ {
|
|
|
|
proxy_set_header Host \$http_host;
|
|
|
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
|
|
|
proxy_set_header X-Forwarded-Proto \$scheme;
|
|
|
|
proxy_redirect off;
|
|
|
|
proxy_pass http://unix:/run/nominatim.sock:/;
|
2020-09-16 17:27:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF_NGINX_CONF
|
|
|
|
#DOCS:```
|
|
|
|
|
|
|
|
# Enable the configuration and restart Nginx
|
|
|
|
#
|
|
|
|
|
2021-08-21 11:45:22 +03:00
|
|
|
if [ "x$NOSYSTEMD" == "xyes" ]; then #DOCS:
|
|
|
|
sudo /usr/sbin/nginx & #DOCS:
|
|
|
|
else #DOCS:
|
2024-02-19 19:08:23 +03:00
|
|
|
sudo systemctl restart nginx
|
2021-08-21 11:45:22 +03:00
|
|
|
fi #DOCS:
|
2020-09-16 17:27:34 +03:00
|
|
|
|
2024-07-29 17:41:24 +03:00
|
|
|
# The Nominatim API is now available at `http://localhost/nominatim/`. Point your browser
|
|
|
|
# to the status output `http://localhost/nominatim/status` to test if everything is ok.
|
2020-05-06 00:10:35 +03:00
|
|
|
|
2020-09-16 17:27:34 +03:00
|
|
|
fi #DOCS:
|