Merge branch '6591-6674-6676-nginx-docs-wip'
[arvados.git] / doc / install / install-api-server.html.textile.liquid
1 ---
2 layout: default
3 navsection: installguide
4 title: Install the API server
5 ...
6
7 h2. Install prerequisites
8
9 The Arvados package repository includes an API server package that can help automate much of the deployment.
10
11 h3(#install_ruby_and_bundler). Install Ruby and Bundler
12
13 {% include 'install_ruby_and_bundler' %}
14
15 h3(#install_postgres). Install PostgreSQL
16
17 {% include 'install_postgres' %}
18
19 h2(#install_apiserver). Install API server and dependencies
20
21 On a Debian-based system, install the following packages:
22
23 <notextile>
24 <pre><code>~$ <span class="userinput">sudo apt-get install bison build-essential libcurl4-openssl-dev git arvados-api-server</span>
25 </code></pre>
26 </notextile>
27
28 On a Red Hat-based system, install the following packages:
29
30 <notextile>
31 <pre><code>~$ <span class="userinput">sudo yum install bison make automake gcc gcc-c++ libcurl-devel git arvados-api-server</span>
32 </code></pre>
33 </notextile>
34
35 h2. Set up the database
36
37 Generate a new database password. Nobody ever needs to memorize it or type it, so we'll make a strong one:
38
39 <notextile>
40 <pre><code>~$ <span class="userinput">ruby -e 'puts rand(2**128).to_s(36)'</span>
41 6gqa1vu492idd7yca9tfandj3
42 </code></pre></notextile>
43
44 Create a new database user.
45
46 <notextile>
47 <pre><code>~$ <span class="userinput">sudo -u postgres createuser --encrypted -R -S --pwprompt arvados</span>
48 [sudo] password for <b>you</b>: <span class="userinput">yourpassword</span>
49 Enter password for new role: <span class="userinput">paste-password-you-generated</span>
50 Enter it again: <span class="userinput">paste-password-again</span>
51 </code></pre></notextile>
52
53 {% include 'notebox_begin' %}
54
55 This user setup assumes that your PostgreSQL is configured to accept password authentication.  Red Hat systems use ident-based authentication by default.  You may need to either adapt the user creation, or reconfigure PostgreSQL (in @pg_hba.conf@) to accept password authentication.
56
57 {% include 'notebox_end' %}
58
59 Create the database:
60
61 <notextile>
62 <pre><code>~$ <span class="userinput">sudo -u postgres createdb arvados_production -T template0 -E UTF8 -O arvados</span>
63 </code></pre>
64 </notextile>
65
66 h2. Set up configuration files
67
68 The API server package uses configuration files that you write to @/etc/arvados/api@ and ensures they're consistently deployed.  Create this directory and copy the example configuration files to it:
69
70 <notextile>
71 <pre><code>~$ <span class="userinput">sudo mkdir -p /etc/arvados/api</span>
72 ~$ <span class="userinput">sudo chmod 700 /etc/arvados/api</span>
73 ~$ <span class="userinput">cd /var/www/arvados-api/current</span>
74 /var/www/arvados-api/current$ <span class="userinput">sudo cp config/database.yml.example /etc/arvados/api/database.yml</span>
75 /var/www/arvados-api/current$ <span class="userinput">sudo cp config/application.yml.example /etc/arvados/api/application.yml</span>
76 </code></pre>
77 </notextile>
78
79 h2. Configure the database connection
80
81 Edit @/etc/arvados/api/database.yml@ and replace the @xxxxxxxx@ database password placeholders with the PostgreSQL password you generated above.
82
83 h2(#configure_application). Configure the API server
84
85 Edit @/etc/arvados/api/application.yml@ to configure the settings described in the following sections.  The deployment script will consistently deploy this to the API server's configuration directory.  The API server reads both @application.yml@ and its own @config/application.default.yml@ file.  The settings in @application.yml@ take precedence over the defaults that are defined in @config/application.default.yml@.  The @config/application.yml.example@ file is not read by the API server and is provided as a starting template only.
86
87 @config/application.default.yml@ documents additional configuration settings not listed here.  You can "view the current source version":https://arvados.org/projects/arvados/repository/revisions/master/entry/services/api/config/application.default.yml for reference.
88
89 Only put local configuration in @application.yml@.  Do not edit @application.default.yml@.
90
91 h3(#uuid_prefix). uuid_prefix
92
93 Define your @uuid_prefix@ in @application.yml@ by setting the @uuid_prefix@ field in the section for your environment.  This prefix is used for all database identifiers to identify the record as originating from this site.  It must be exactly 5 lowercase ASCII letters and digits.
94
95 Example @application.yml@:
96
97 <notextile>
98 <pre><code>  uuid_prefix: <span class="userinput">zzzzz</span></code></pre>
99 </notextile>
100
101 h3. secret_token
102
103 The @secret_token@ is used for for signing cookies.  IMPORTANT: This is a site secret. It should be at least 50 characters.  Generate a random value and set it in @application.yml@:
104
105 <notextile>
106 <pre><code>~$ <span class="userinput">ruby -e 'puts rand(2**400).to_s(36)'</span>
107 yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
108 </code></pre></notextile>
109
110 Example @application.yml@:
111
112 <notextile>
113 <pre><code>  secret_token: <span class="userinput">yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy</span></code></pre>
114 </notextile>
115
116 h3(#blob_signing_key). blob_signing_key
117
118 The @blob_signing_key@ is used to enforce access control to Keep blocks.  This same key must be provided to the Keepstore daemons when "installing Keepstore servers.":install-keepstore.html  IMPORTANT: This is a site secret. It should be at least 50 characters.  Generate a random value and set it in @application.yml@:
119
120 <notextile>
121 <pre><code>~$ <span class="userinput">ruby -e 'puts rand(2**400).to_s(36)'</span>
122 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
123 </code></pre></notextile>
124
125 Example @application.yml@:
126
127 <notextile>
128 <pre><code>  blob_signing_key: <span class="userinput">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</span></code></pre>
129 </notextile>
130
131 h3(#omniauth). sso_app_secret, sso_app_id, sso_provider_url
132
133 The following settings enable the API server to communicate with the "Single Sign On (SSO) server":install-sso.html to authenticate user log in.
134
135 Set @sso_provider_url@ to the base URL where your SSO server is installed.  This should be a URL consisting of the scheme and host (and optionally, port), without a trailing slash.
136
137 Set @sso_app_secret@ and @sso_app_id@ to the corresponding values for @app_secret@ and @app_id@ used in the "Create arvados-server client for Single Sign On (SSO)":install-sso.html#client step.
138
139 Example @application.yml@:
140
141 <notextile>
142 <pre><code>  sso_app_id: <span class="userinput">arvados-server</span>
143   sso_app_secret: <span class="userinput">wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww</span>
144   sso_provider_url: <span class="userinput">https://sso.example.com</span>
145 </code></pre>
146 </notextile>
147
148 h3. workbench_address
149
150 Set @workbench_address@ to the URL of your workbench application after following "Install Workbench.":install-workbench-app.html
151
152 Example @application.yml@:
153
154 <notextile>
155 <pre><code>  workbench_address: <span class="userinput">https://workbench.zzzzz.example.com</span></code></pre>
156 </notextile>
157
158 h3. websockets_address
159
160 Set @websockets_address@ to the @wss://@ URL of the API server websocket endpoint after following "Set up Web servers.":#set_up
161
162 Example @application.yml@:
163
164 <notextile>
165 <pre><code>  websockets_address: <span class="userinput">wss://ws.zzzzz.example.com</span></code></pre>
166 </notextile>
167
168 h3(#git_repositories_dir). git_repositories_dir
169
170 The @git_repositories_dir@ setting specifies the directory where user git repositories will be stored.  By default this is @/var/lib/arvados/git@.
171
172 Example @application.yml@:
173
174 <notextile>
175 <pre><code>  git_repositories_dir: <span class="userinput">/var/lib/arvados/git</span>
176 </code></pre>
177 </notextile>
178
179 Make sure a clone of the arvados repository exists in @git_repositories_dir@.
180
181 <notextile>
182 <pre><code>~$ <span class="userinput">sudo mkdir -p /var/lib/arvados/git</span>
183 ~$ <span class="userinput">sudo git clone --bare git://git.curoverse.com/arvados.git /var/lib/arvados/git/arvados.git</span>
184 </code></pre></notextile>
185
186 h3(#git_internal_dir). git_internal_dir
187
188 The @git_internal_dir@ setting specifies the location of Arvados' internal git repository.  By default this is @/var/lib/arvados/internal.git@.  This repository stores git commits that have been used to run Crunch jobs.  It should _not_ be a subdirectory of @git_repositories_dir@.
189
190 Example @application.yml@:
191
192 <notextile>
193 <pre><code>  git_internal_dir: <span class="userinput">/var/lib/arvados/internal.git</span>
194 </code></pre>
195 </notextile>
196
197 h2. Prepare the API server deployment
198
199 Now that all your configuration is in place, run @/usr/local/bin/arvados-api-server-upgrade.sh@.  This will install and check your configuration, install necessary gems, and run any necessary database setup.
200
201 {% include 'notebox_begin' %}
202 You can safely ignore the following error message you may see when loading the database structure:
203 <notextile>
204 <pre><code>ERROR:  must be owner of extension plpgsql</code></pre></notextile>
205 {% include 'notebox_end' %}
206
207 This command aborts when it encounters an error.  It's safe to rerun multiple times, so if there's a problem with your configuration, you can fix that and try again.
208
209 h2(#set_up). Set up Web servers
210
211 For best performance, we recommend you use Nginx as your Web server front-end, with a Passenger backend for the main API server and a Puma backend for API server Websockets.  To do that:
212
213 <notextile>
214 <ol>
215 <li><a href="https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html">Install Nginx and Phusion Passenger</a>.</li>
216
217 <li><p>Puma is already included with the API server's gems.  We recommend you run it as a service under <a href="http://smarden.org/runit/">runit</a> or a similar tool.  Here's a sample runit script for that:</p>
218
219 <pre><code>#!/bin/bash
220
221 set -e
222 exec 2>&1
223
224 # Uncomment the line below if you're using RVM.
225 #source /etc/profile.d/rvm.sh
226
227 envdir="`pwd`/env"
228 mkdir -p "$envdir"
229 echo ws-only > "$envdir/ARVADOS_WEBSOCKETS"
230
231 cd /var/www/arvados-api/current
232 echo "Starting puma in `pwd`"
233
234 # You may need to change arguments below to match your deployment, especially -u.
235 exec chpst -m 1073741824 -u www-data:www-data -e "$envdir" \
236   bundle exec puma -t 0:512 -e production -b tcp://127.0.0.1:8100
237 </code></pre>
238 </li>
239
240 <li><p>Edit the http section of your Nginx configuration to run the Passenger server, and act as a front-end for both it and Puma.  You might add a block like the following, adding SSL and logging parameters to taste:</p>
241
242 <pre><code>server {
243   listen 127.0.0.1:8000;
244   server_name localhost-api;
245
246   root /var/www/arvados-api/current/public;
247   index  index.html index.htm index.php;
248
249   passenger_enabled on;
250   # If you're using RVM, uncomment the line below.
251   #passenger_ruby /usr/local/rvm/wrappers/default/ruby;
252 }
253
254 upstream api {
255   server     127.0.0.1:8000  fail_timeout=10s;
256 }
257
258 upstream websockets {
259   # The address below must match the one specified in puma's -b option.
260   server     127.0.0.1:8100  fail_timeout=10s;
261 }
262
263 proxy_http_version 1.1;
264
265 # When Keep clients request a list of Keep services from the API server, the
266 # server will automatically return the list of available proxies if
267 # the request headers include X-External-Client: 1.  Following the example
268 # here, at the end of this section, add a line for each netmask that has
269 # direct access to Keep storage daemons to set this header value to 0.
270 geo $external_client {
271   default        1;
272   <span class="userinput">10.20.30.0/24</span>  0;
273 }
274
275 server {
276   listen       <span class="userinput">[your public IP address]</span>:443 ssl;
277   server_name  <span class="userinput">uuid_prefix.your.domain</span>;
278
279   ssl on;
280   ssl_certificate     <span class="userinput">/YOUR/PATH/TO/cert.pem</span>;
281   ssl_certificate_key <span class="userinput">/YOUR/PATH/TO/cert.key</span>;
282
283   index  index.html index.htm index.php;
284
285   location / {
286     proxy_pass            http://api;
287     proxy_redirect        off;
288     proxy_connect_timeout 90s;
289     proxy_read_timeout    300s;
290
291     proxy_set_header      X-Forwarded-Proto https;
292     proxy_set_header      Host $http_host;
293     proxy_set_header      X-External-Client $external_client;
294     proxy_set_header      X-Real-IP $remote_addr;
295     proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
296   }
297 }
298
299 server {
300   listen       <span class="userinput">[your public IP address]</span>:443 ssl;
301   server_name  ws.<span class="userinput">uuid_prefix.your.domain</span>;
302
303   ssl on;
304   ssl_certificate     <span class="userinput">/YOUR/PATH/TO/cert.pem</span>;
305   ssl_certificate_key <span class="userinput">/YOUR/PATH/TO/cert.key</span>;
306
307   index  index.html index.htm index.php;
308
309   location / {
310     proxy_pass            http://websockets;
311     proxy_redirect        off;
312     proxy_connect_timeout 90s;
313     proxy_read_timeout    300s;
314
315     proxy_set_header      Upgrade $http_upgrade;
316     proxy_set_header      Connection "upgrade";
317     proxy_set_header      Host $host;
318     proxy_set_header      X-Real-IP $remote_addr;
319     proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
320   }
321 }
322 </code></pre>
323 </li>
324
325 <li>Restart Nginx.</li>
326
327 </ol>
328 </notextile>