]> git.openstreetmap.org Git - nominatim.git/blob - vagrant/Install-on-Ubuntu-22.sh
reintroduce cutoffs when searching for very frequent words
[nominatim.git] / vagrant / Install-on-Ubuntu-22.sh
1 #!/bin/bash -e
2 #
3 # hacks for broken vagrant box      #DOCS:
4 sudo rm -f /var/lib/dpkg/lock       #DOCS:
5 export APT_LISTCHANGES_FRONTEND=none #DOCS:
6 export DEBIAN_FRONTEND=noninteractive #DOCS:
7
8 # *Note:* these installation instructions are also available in executable
9 #         form for use with vagrant under vagrant/Install-on-Ubuntu-22.sh.
10 #
11 # Installing the Required Software
12 # ================================
13 #
14 # These instructions expect that you have a freshly installed Ubuntu 22.04.
15 #
16 # Make sure all packages are up-to-date by running:
17 #
18
19     sudo apt-get update -qq
20
21 # Now you can install all packages needed for Nominatim:
22
23     sudo apt-get install -y build-essential cmake g++ libboost-dev libboost-system-dev \
24                         libboost-filesystem-dev libexpat1-dev zlib1g-dev \
25                         libbz2-dev libpq-dev liblua5.3-dev lua5.3 lua-dkjson \
26                         nlohmann-json3-dev postgresql-14-postgis-3 \
27                         postgresql-contrib-14 postgresql-14-postgis-3-scripts \
28                         libicu-dev python3-dotenv \
29                         python3-psycopg2 python3-psutil python3-jinja2 \
30                         python3-sqlalchemy python3-asyncpg \
31                         python3-icu python3-datrie python3-yaml git
32
33
34 #
35 # System Configuration
36 # ====================
37 #
38 # The following steps are meant to configure a fresh Ubuntu installation
39 # for use with Nominatim. You may skip some of the steps if you have your
40 # OS already configured.
41 #
42 # Creating Dedicated User Accounts
43 # --------------------------------
44 #
45 # Nominatim will run as a global service on your machine. It is therefore
46 # best to install it under its own separate user account. In the following
47 # we assume this user is called nominatim and the installation will be in
48 # /srv/nominatim. To create the user and directory run:
49 #
50 #     sudo useradd -d /srv/nominatim -s /bin/bash -m nominatim
51 #
52 # You may find a more suitable location if you wish.
53 #
54 # The following instructions assume you are logged in as this user.
55 # You can also switch to the user with:
56 #
57 #     sudo -u nominatim bash
58 #
59 # To be able to copy and paste instructions from this manual, export
60 # user name and home directory now like this:
61 #
62 if [ "x$USERNAME" == "x" ]; then #DOCS:
63     export USERNAME=vagrant        #DOCS:    export USERNAME=nominatim
64     export USERHOME=/home/vagrant  #DOCS:    export USERHOME=/srv/nominatim
65 fi                                 #DOCS:
66 #
67 # **Never, ever run the installation as a root user.** You have been warned.
68 #
69 # Make sure that system servers can read from the home directory:
70
71     chmod a+x $USERHOME
72
73 # Setting up PostgreSQL
74 # ---------------------
75 #
76 # Tune the postgresql configuration, which is located in 
77 # `/etc/postgresql/14/main/postgresql.conf`. See section *Tuning the PostgreSQL database*
78 # in [the installation page](../admin/Installation.md#tuning-the-postgresql-database)
79 # for the parameters to change.
80 #
81 # Restart the postgresql service after updating this config file.
82
83 if [ "x$NOSYSTEMD" == "xyes" ]; then  #DOCS:
84     sudo pg_ctlcluster 14 main start  #DOCS:
85 else                                  #DOCS:
86     sudo systemctl restart postgresql
87 fi                                    #DOCS:
88 #
89 # Finally, we need to add two postgres users: one for the user that does
90 # the import and another for the webserver which should access the database
91 # for reading only:
92 #
93
94     sudo -u postgres createuser -s $USERNAME
95     sudo -u postgres createuser www-data
96
97 #
98 # Installing Nominatim
99 # ====================
100 #
101 # Building and Configuration
102 # --------------------------
103 #
104 # Get the source code from Github and change into the source directory
105 #
106 if [ "x$1" == "xyes" ]; then  #DOCS:    :::sh
107     cd $USERHOME
108     git clone --recursive https://github.com/openstreetmap/Nominatim.git
109     cd Nominatim
110 else                               #DOCS:
111     cd $USERHOME/Nominatim         #DOCS:
112 fi                                 #DOCS:
113
114 # When installing the latest source from github, you also need to
115 # download the country grid:
116
117 if [ ! -f data/country_osm_grid.sql.gz ]; then       #DOCS:    :::sh
118     wget -O data/country_osm_grid.sql.gz https://nominatim.org/data/country_grid.sql.gz
119 fi                                 #DOCS:
120
121 # The code must be built in a separate directory. Create this directory,
122 # then configure and build Nominatim in there:
123
124     mkdir $USERHOME/build
125     cd $USERHOME/build
126     cmake $USERHOME/Nominatim
127     make
128     sudo make install
129
130 # Nominatim is now ready to use. You can continue with
131 # [importing a database from OSM data](../admin/Import.md). If you want to set up
132 # the API frontend first, continue reading.
133 #
134 # Setting up the Python frontend
135 # ==============================
136 #
137 # Some of the Python packages in Ubuntu are too old. Therefore run the
138 # frontend from a Python virtualenv with current packages.
139 #
140 # To set up the virtualenv, run:
141
142 #DOCS:```sh
143 sudo apt-get install -y virtualenv
144 virtualenv $USERHOME/nominatim-venv
145 $USERHOME/nominatim-venv/bin/pip install SQLAlchemy PyICU psycopg[binary] \
146               psycopg2-binary python-dotenv PyYAML falcon uvicorn gunicorn
147 #DOCS:```
148
149 # Next you need to create a systemd job that runs Nominatim on gunicorn.
150 # First create a systemd job that manages the socket file:
151
152 #DOCS:```sh
153 sudo tee /etc/systemd/system/nominatim.socket << EOFSOCKETSYSTEMD
154 [Unit]
155 Description=Gunicorn socket for Nominatim
156
157 [Socket]
158 ListenStream=/run/nominatim.sock
159 SocketUser=www-data
160
161 [Install]
162 WantedBy=multi-user.target
163 EOFSOCKETSYSTEMD
164 #DOCS:```
165
166 # Then create the service for Nominatim itself.
167
168 #DOCS:```sh
169 sudo tee /etc/systemd/system/nominatim.service << EOFNOMINATIMSYSTEMD
170 [Unit]
171 Description=Nominatim running as a gunicorn application
172 After=network.target
173 Requires=nominatim.socket
174
175 [Service]
176 Type=simple
177 Environment="PYTHONPATH=/usr/local/lib/nominatim/lib-python/"
178 User=www-data
179 Group=www-data
180 WorkingDirectory=$USERHOME/nominatim-project
181 ExecStart=$USERHOME/nominatim-venv/bin/gunicorn -b unix:/run/nominatim.sock -w 4 -k uvicorn.workers.UvicornWorker nominatim.server.falcon.server:run_wsgi
182 ExecReload=/bin/kill -s HUP \$MAINPID
183 StandardOutput=append:/var/log/gunicorn-nominatim.log
184 StandardError=inherit
185 PrivateTmp=true
186 TimeoutStopSec=5
187 KillMode=mixed
188
189 [Install]
190 WantedBy=multi-user.target
191 EOFNOMINATIMSYSTEMD
192 #DOCS:```
193
194 # Activate the services:
195
196 if [ "x$NOSYSTEMD" != "xyes" ]; then  #DOCS:
197     sudo systemctl daemon-reload
198     sudo systemctl enable nominatim.socket
199     sudo systemctl start nominatim.socket
200     sudo systemctl enable nominatim.service
201 fi                                    #DOCS:
202
203 # Setting up a webserver
204 # ======================
205 #
206 # The webserver is only needed as a proxy between the public interface
207 # and the gunicorn service.
208 #
209 # The frontend will need configuration information from the project
210 # directory, which will be populated later
211 # [during the import process](../admin/Import.md#creating-the-project-directory)
212 # Already create the project directory itself now:
213
214     mkdir $USERHOME/nominatim-project
215
216 #
217 # Option 1: Using Apache
218 # ----------------------
219 #
220 if [ "x$2" == "xinstall-apache" ]; then #DOCS:
221 #
222 # First install apache itself and enable the proxy module:
223
224     sudo apt-get install -y apache2
225     sudo a2enmod proxy_http
226
227 #
228 # To set up proxying for Apache add the following configuration:
229
230 #DOCS:```sh
231 sudo tee /etc/apache2/conf-available/nominatim.conf << EOFAPACHECONF
232
233 ProxyPass /nominatim "unix:/run/nominatim.sock|http://localhost/"
234 EOFAPACHECONF
235 #DOCS:```
236
237 #
238 # Then enable the configuration and restart apache
239 #
240
241 #DOCS:```sh
242 sudo a2enconf nominatim
243 #DOCS:```
244
245 if [ "x$NOSYSTEMD" == "xyes" ]; then  #DOCS:
246     sudo apache2ctl start             #DOCS:
247 else                                  #DOCS:
248     sudo systemctl restart apache2
249 fi                                    #DOCS:
250
251 # The Nominatim API is now available at `http://localhost/nominatim/`.
252
253 fi   #DOCS:
254
255 #
256 # Option 2: Using nginx
257 # ---------------------
258 #
259 if [ "x$2" == "xinstall-nginx" ]; then #DOCS:
260
261 # First install nginx itself:
262
263     sudo apt-get install -y nginx
264
265
266 # Then create a Nginx configuration to forward http requests to that socket.
267
268 #DOCS:```sh
269 sudo tee /etc/nginx/sites-available/default << EOF_NGINX_CONF
270 server {
271     listen 80 default_server;
272     listen [::]:80 default_server;
273
274     root $USERHOME/nominatim-project/website;
275     index /search;
276
277     location /nominatim/ {
278             proxy_set_header Host \$http_host;
279             proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
280             proxy_set_header X-Forwarded-Proto \$scheme;
281             proxy_redirect off;
282             proxy_pass http://unix:/run/nominatim.sock:/;
283     }
284 }
285 EOF_NGINX_CONF
286 #DOCS:```
287
288 # Enable the configuration and restart Nginx
289 #
290
291 if [ "x$NOSYSTEMD" == "xyes" ]; then  #DOCS:
292     sudo /usr/sbin/nginx &            #DOCS:
293 else                                  #DOCS:
294     sudo systemctl restart nginx
295 fi                                    #DOCS:
296
297 # The Nominatim API is now available at `http://localhost/nominatim/`.
298
299 fi   #DOCS: