]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - support/doc/production.md
Move to new documentation links
[github/Chocobozzz/PeerTube.git] / support / doc / production.md
CommitLineData
63bfad7e
C
1# Production guide
2
4df6a1b8 3 * [Installation](#installation)
4c86a254 4 * [Upgrade](#upgrade)
4df6a1b8 5
63bfad7e
C
6## Installation
7
76dd3e89 8Please don't install PeerTube for production on a device behind a low bandwidth connection (example: your ADSL link).
b5fdfcbd 9If you want information about the appropriate hardware to run PeerTube, please see the [FAQ](https://joinpeertube.org/en_US/faq#should-i-have-a-big-server-to-run-peertube).
1185c246 10
a23f6c94 11### :hammer: Dependencies
63bfad7e 12
2426fe16 13Follow the steps of the [dependencies guide](/support/doc/dependencies.md).
63bfad7e 14
a23f6c94 15### :construction_worker: PeerTube user
63bfad7e 16
59c48d49 17Create a `peertube` user with `/var/www/peertube` home:
63bfad7e 18
a23f6c94 19```bash
59c48d49 20$ sudo useradd -m -d /var/www/peertube -s /bin/bash -p peertube peertube
e5203ffa
TC
21```
22
23Set its password:
a23f6c94 24```bash
d2000ca6 25$ sudo passwd peertube
63bfad7e
C
26```
27
dec49521
W
28Ensure the peertube root directory is traversable by nginx:
29
30```bash
31$ ls -ld /var/www/peertube # Should be drwxr-xr-x
32```
33
4c86a254
GN
34**On FreeBSD**
35
a23f6c94 36```bash
4c86a254
GN
37$ sudo pw useradd -n peertube -d /var/www/peertube -s /usr/local/bin/bash -m
38$ sudo passwd peertube
39```
40or use `adduser` to create it interactively.
41
a23f6c94 42### :card_file_box: Database
63bfad7e 43
e5203ffa 44Create the production database and a peertube user inside PostgreSQL:
63bfad7e 45
a23f6c94 46```bash
3dc8a86c 47$ cd /var/www/peertube
d2000ca6 48$ sudo -u postgres createuser -P peertube
c11fc2d9 49```
50
2c5eab14
C
51Here you should enter a password for PostgreSQL `peertube` user, that should be copied in `production.yaml` file.
52Don't just hit enter else it will be empty.
c11fc2d9 53
a23f6c94 54```bash
0539dba8 55$ sudo -u postgres createdb -O peertube -E UTF8 -T template0 peertube_prod
63bfad7e
C
56```
57
57c36b27
C
58Then enable extensions PeerTube needs:
59
a23f6c94 60```bash
57c36b27
C
61$ sudo -u postgres psql -c "CREATE EXTENSION pg_trgm;" peertube_prod
62$ sudo -u postgres psql -c "CREATE EXTENSION unaccent;" peertube_prod
63```
64
a23f6c94 65### :page_facing_up: Prepare PeerTube directory
63bfad7e 66
c501f441
C
67Fetch the latest tagged version of Peertube:
68
a23f6c94 69```bash
e5203ffa
TC
70$ VERSION=$(curl -s https://api.github.com/repos/chocobozzz/peertube/releases/latest | grep tag_name | cut -d '"' -f 4) && echo "Latest Peertube version is $VERSION"
71```
59c48d49 72
c501f441
C
73
74Open the peertube directory, create a few required directories:
75
a23f6c94 76```bash
d8658f0f
C
77$ cd /var/www/peertube
78$ sudo -u peertube mkdir config storage versions
6d8e1f28 79$ sudo -u peertube chmod 750 config/
e5203ffa 80```
59c48d49 81
c501f441
C
82
83Download the latest version of the Peertube client, unzip it and remove the zip:
84
a23f6c94 85```bash
d8658f0f 86$ cd /var/www/peertube/versions
c501f441 87$ # Releases are also available on https://builds.joinpeertube.org/release
15dbc134 88$ sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip"
c201278d 89$ sudo -u peertube unzip -q peertube-${VERSION}.zip && sudo -u peertube rm peertube-${VERSION}.zip
e5203ffa 90```
59c48d49 91
c501f441 92
cfdd9eb4 93Install Peertube:
c501f441 94
a23f6c94 95```bash
d8658f0f
C
96$ cd /var/www/peertube
97$ sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
09c93c20 98$ cd ./peertube-latest && sudo -H -u peertube yarn install --production --pure-lockfile
63bfad7e
C
99```
100
a23f6c94 101### :wrench: PeerTube configuration
63bfad7e 102
4948dcdb
C
103Copy the default configuration file that contains the default configuration provided by PeerTube.
104You **must not** update this file.
105
a23f6c94 106```bash
d8658f0f
C
107$ cd /var/www/peertube
108$ sudo -u peertube cp peertube-latest/config/default.yaml config/default.yaml
4948dcdb
C
109```
110
111Now copy the production example configuration:
63bfad7e 112
a23f6c94 113```bash
d8658f0f
C
114$ cd /var/www/peertube
115$ sudo -u peertube cp peertube-latest/config/production.yaml.example config/production.yaml
63bfad7e
C
116```
117
1ea868a9
C
118Then edit the `config/production.yaml` file according to your webserver and database configuration. In particular:
119 * `webserver`: Reverse proxy public information
120 * `secrets`: Secret strings you must generate manually (PeerTube version >= 5.0)
121 * `database`: PostgreSQL settings
122 * `redis`: Redis settings
123 * `smtp`: If you want to use emails
124 * `admin.email`: To correctly fill `root` user email
125
d8658f0f 126Keys defined in `config/production.yaml` will override keys defined in `config/default.yaml`.
63bfad7e 127
c5c95361 128**PeerTube does not support webserver host change**. Even though [PeerTube CLI can help you to switch hostname](https://docs.joinpeertube.org/maintain/tools?id=update-hostjs) there's no official support for that since it is a risky operation that might result in unforeseen errors.
30f55025 129
a23f6c94 130### :truck: Webserver
63bfad7e 131
e883399f
RK
132We only provide official configuration files for Nginx.
133
63bfad7e
C
134Copy the nginx configuration template:
135
a23f6c94 136```bash
59c48d49 137$ sudo cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube
63bfad7e
C
138```
139
2c92b063
C
140Then set the domain for the webserver configuration file.
141Replace `[peertube-domain]` with the domain for the peertube server.
7a3864e8 142
a23f6c94 143```bash
1a9b141d 144$ sudo sed -i 's/${WEBSERVER_HOST}/[peertube-domain]/g' /etc/nginx/sites-available/peertube
feb0f998 145$ sudo sed -i 's/${PEERTUBE_HOST}/127.0.0.1:9000/g' /etc/nginx/sites-available/peertube
7a3864e8
M
146```
147
5668bf2e
C
148Then modify the webserver configuration file. Please pay attention to the `alias` keys of the static locations.
149It should correspond to the paths of your storage directories (set in the configuration file inside the `storage` key).
63bfad7e 150
a23f6c94 151```bash
63bfad7e
C
152$ sudo vim /etc/nginx/sites-available/peertube
153```
154
0b495712
C
155Activate the configuration file:
156
a23f6c94 157```bash
0b495712
C
158$ sudo ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube
159```
160
161To generate the certificate for your domain as required to make https work you can use [Let's Encrypt](https://letsencrypt.org/):
162
a23f6c94 163```bash
0b495712 164$ sudo systemctl stop nginx
f35f23d8 165$ sudo certbot certonly --standalone --post-hook "systemctl restart nginx"
e6607b25 166$ sudo systemctl reload nginx
e883399f
RK
167```
168
d8658f0f
C
169Certbot should have installed a cron to automatically renew your certificate.
170Since our nginx template supports webroot renewal, we suggest you to update the renewal config file to use the `webroot` authenticator:
171
a23f6c94 172```bash
d8658f0f 173$ # Replace authenticator = standalone by authenticator = webroot
08a9ee19 174$ # Add webroot_path = /var/www/certbot
d8658f0f
C
175$ sudo vim /etc/letsencrypt/renewal/your-domain.com.conf
176```
177
66892149
C
178If you plan to have many concurrent viewers on your PeerTube instance, consider increasing `worker_connections` value: https://nginx.org/en/docs/ngx_core_module.html#worker_connections.
179
7a07da01
C
180<details>
181<summary><strong>If using FreeBSD</strong></summary>
182
4c86a254
GN
183On FreeBSD you can use [Dehydrated](https://dehydrated.io/) `security/dehydrated` for [Let's Encrypt](https://letsencrypt.org/)
184
a23f6c94 185```bash
4c86a254
GN
186$ sudo pkg install dehydrated
187```
7a07da01 188</details>
4c86a254 189
7a07da01 190### :alembic: Linux TCP/IP Tuning
f74c294a 191
a23f6c94 192```bash
f74c294a
MES
193$ sudo cp /var/www/peertube/peertube-latest/support/sysctl.d/30-peertube-tcp.conf /etc/sysctl.d/
194$ sudo sysctl -p /etc/sysctl.d/30-peertube-tcp.conf
195```
196
197Your distro may enable this by default, but at least Debian 9 does not, and the default FIFO
198scheduler is quite prone to "Buffer Bloat" and extreme latency when dealing with slower client
199links as we often encounter in a video server.
200
a23f6c94 201### :bricks: systemd
63bfad7e 202
07aa93a8 203If your OS uses systemd, copy the configuration template:
63bfad7e 204
a23f6c94 205```bash
59c48d49 206$ sudo cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/
63bfad7e
C
207```
208
96df6ca6 209Check the service file (PeerTube paths and security directives):
63bfad7e 210
a23f6c94 211```bash
d2000ca6 212$ sudo vim /etc/systemd/system/peertube.service
63bfad7e
C
213```
214
63bfad7e
C
215
216Tell systemd to reload its config:
217
a23f6c94 218```bash
d2000ca6 219$ sudo systemctl daemon-reload
63bfad7e
C
220```
221
6b2ef589
C
222If you want to start PeerTube on boot:
223
a23f6c94 224```bash
9625507f 225$ sudo systemctl enable peertube
6b2ef589
C
226```
227
07aa93a8 228Run:
63bfad7e 229
a23f6c94 230```bash
d2000ca6
C
231$ sudo systemctl start peertube
232$ sudo journalctl -feu peertube
63bfad7e
C
233```
234
7a07da01
C
235<details>
236<summary><strong>If using FreeBSD</strong></summary>
237
65fcf1e9 238On FreeBSD, copy the startup script and update rc.conf:
6d55bd21 239
a23f6c94 240```bash
31d45e0e
MP
241$ sudo install -m 0555 /var/www/peertube/peertube-latest/support/freebsd/peertube /usr/local/etc/rc.d/
242$ sudo sysrc peertube_enable="YES"
6d55bd21
GN
243```
244
07aa93a8 245Run:
6d55bd21 246
a23f6c94 247```bash
6d55bd21
GN
248$ sudo service peertube start
249```
7a07da01 250</details>
6d55bd21 251
7a07da01
C
252<details>
253<summary><strong>If using OpenRC</strong></summary>
67ac918d
W
254
255If your OS uses OpenRC, copy the service script:
256
a23f6c94 257```bash
67ac918d
W
258$ sudo cp /var/www/peertube/peertube-latest/support/init.d/peertube /etc/init.d/
259```
260
261If you want to start PeerTube on boot:
262
a23f6c94 263```bash
67ac918d
W
264$ sudo rc-update add peertube default
265```
266
267Run and print last logs:
268
a23f6c94 269```bash
67ac918d
W
270$ sudo /etc/init.d/peertube start
271$ tail -f /var/log/peertube/peertube.log
272```
7a07da01 273</details>
67ac918d 274
a23f6c94 275### :technologist: Administrator
63bfad7e 276
fc10ecf1 277The administrator username is `root` and the password is automatically generated. It can be found in PeerTube
d8658f0f 278logs (path defined in `production.yaml`). You can also set another password with:
63bfad7e 279
a23f6c94 280```bash
59c48d49 281$ cd /var/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root
63bfad7e
C
282```
283
3daaa192
AV
284Alternatively you can set the environment variable `PT_INITIAL_ROOT_PASSWORD`,
285to your own administrator password, although it must be 6 characters or more.
286
a23f6c94 287### :tada: What now?
9c758359
C
288
289Now your instance is up you can:
2c92b063 290
4d582cec 291 * Add your instance to the public PeerTube instances index if you want to: https://instances.joinpeertube.org/
d06caf3e 292 * Check [available CLI tools](/support/doc/tools.md)
2e3a0215 293
63bfad7e
C
294## Upgrade
295
57c36b27 296### PeerTube instance
b314f983 297
e76daa73 298**Check the changelog (in particular the *IMPORTANT NOTES* section):** https://github.com/Chocobozzz/PeerTube/blob/develop/CHANGELOG.md
b314f983 299
7a07da01 300Run the upgrade script (the password it asks is PeerTube's database user password):
4246247f 301
a23f6c94 302```bash
fbd2ad19 303$ cd /var/www/peertube/peertube-latest/scripts && sudo -H -u peertube ./upgrade.sh
188aa774 304$ sudo systemctl restart peertube # Or use your OS command to restart PeerTube if you don't use systemd
1007a018
SL
305```
306
7a07da01
C
307<details>
308<summary><strong>Prefer manual upgrade?</strong></summary>
a8b5ce95 309
ce487e1e 310Make a SQL backup
c7a9f34f 311
a23f6c94 312```bash
c7a9f34f 313$ SQL_BACKUP_PATH="backup/sql-peertube_prod-$(date -Im).bak" && \
59c48d49 314 cd /var/www/peertube && sudo -u peertube mkdir -p backup && \
43c4c639 315 sudo -u postgres pg_dump -F c peertube_prod | sudo -u peertube tee "$SQL_BACKUP_PATH" >/dev/null
c7a9f34f
C
316```
317
ce487e1e 318Fetch the latest tagged version of Peertube:
23e27dd5 319
a23f6c94 320```bash
ce487e1e 321$ VERSION=$(curl -s https://api.github.com/repos/chocobozzz/peertube/releases/latest | grep tag_name | cut -d '"' -f 4) && echo "Latest Peertube version is $VERSION"
23e27dd5
C
322```
323
ce487e1e 324Download the new version and unzip it:
c7a9f34f 325
a23f6c94 326```bash
ce487e1e 327$ cd /var/www/peertube/versions && \
fd206f0b 328 sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" && \
ce487e1e
C
329 sudo -u peertube unzip -o peertube-${VERSION}.zip && \
330 sudo -u peertube rm peertube-${VERSION}.zip
331```
332
4805cff1 333Install node dependencies:
ce487e1e 334
a23f6c94 335```bash
4805cff1 336$ cd /var/www/peertube/versions/peertube-${VERSION} && \
fbd2ad19 337 sudo -H -u peertube yarn install --production --pure-lockfile
ce487e1e
C
338```
339
4805cff1 340Copy new configuration defaults values and update your configuration file:
ce487e1e 341
a23f6c94 342```bash
4805cff1 343$ sudo -u peertube cp /var/www/peertube/versions/peertube-${VERSION}/config/default.yaml /var/www/peertube/config/default.yaml
c501cdef 344$ diff -u /var/www/peertube/versions/peertube-${VERSION}/config/production.yaml.example /var/www/peertube/config/production.yaml
ce487e1e
C
345```
346
4805cff1 347Change the link to point to the latest version:
ce487e1e 348
a23f6c94 349```bash
4805cff1 350$ cd /var/www/peertube && \
2519d9fe 351 sudo unlink ./peertube-latest && \
4805cff1 352 sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
ce487e1e 353```
7a07da01 354</details>
ce487e1e 355
7a07da01 356### Update PeerTube configuration
7f6ff462 357
7a07da01 358Check for configuration changes, and report them in your `config/production.yaml` file:
7f6ff462
JL
359
360```bash
361$ cd /var/www/peertube/versions
362$ diff -u "$(ls --sort=t | head -2 | tail -1)/config/production.yaml.example" "$(ls --sort=t | head -1)/config/production.yaml.example"
363```
364
7a07da01 365### Update nginx configuration
b314f983
C
366
367Check changes in nginx configuration:
368
a23f6c94 369```bash
b314f983 370$ cd /var/www/peertube/versions
c501cdef 371$ diff -u "$(ls --sort=t | head -2 | tail -1)/support/nginx/peertube" "$(ls --sort=t | head -1)/support/nginx/peertube"
b314f983
C
372```
373
7a07da01 374### Update systemd service
b314f983
C
375
376Check changes in systemd configuration:
377
a23f6c94 378```bash
b314f983 379$ cd /var/www/peertube/versions
c501cdef 380$ diff -u "$(ls --sort=t | head -2 | tail -1)/support/systemd/peertube.service" "$(ls --sort=t | head -1)/support/systemd/peertube.service"
b314f983
C
381```
382
383### Restart PeerTube
384
385If you changed your nginx configuration:
386
a23f6c94 387```bash
b314f983
C
388$ sudo systemctl reload nginx
389```
390
391If you changed your systemd configuration:
4805cff1 392
a23f6c94 393```bash
b314f983
C
394$ sudo systemctl daemon-reload
395```
396
397Restart PeerTube and check the logs:
398
a23f6c94 399```bash
b314f983 400$ sudo systemctl restart peertube && sudo journalctl -fu peertube
ce487e1e
C
401```
402
4c86a254 403### Things went wrong?
c7a9f34f 404
ce487e1e 405Change `peertube-latest` destination to the previous version and restore your SQL backup:
c7a9f34f 406
a23f6c94 407```bash
c7a9f34f 408$ OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \
43c4c639 409 cd /var/www/peertube && sudo -u peertube unlink ./peertube-latest && \
c7a9f34f 410 sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \
43c4c639 411 sudo -u postgres pg_restore -c -C -d postgres "$SQL_BACKUP_PATH" && \
c7a9f34f
C
412 sudo systemctl restart peertube
413```