]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - support/doc/production.md
Encrypt OTP secret
[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
a23f6c94 13Follow the steps of the [dependencies guide](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
118Then edit the `config/production.yaml` file according to your webserver
d8658f0f
C
119and database configuration (`webserver`, `database`, `redis`, `smtp` and `admin.email` sections in particular).
120Keys defined in `config/production.yaml` will override keys defined in `config/default.yaml`.
63bfad7e 121
7cf88d09 122**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 123
a23f6c94 124### :truck: Webserver
63bfad7e 125
e883399f
RK
126We only provide official configuration files for Nginx.
127
63bfad7e
C
128Copy the nginx configuration template:
129
a23f6c94 130```bash
59c48d49 131$ sudo cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube
63bfad7e
C
132```
133
2c92b063
C
134Then set the domain for the webserver configuration file.
135Replace `[peertube-domain]` with the domain for the peertube server.
7a3864e8 136
a23f6c94 137```bash
1a9b141d 138$ sudo sed -i 's/${WEBSERVER_HOST}/[peertube-domain]/g' /etc/nginx/sites-available/peertube
feb0f998 139$ sudo sed -i 's/${PEERTUBE_HOST}/127.0.0.1:9000/g' /etc/nginx/sites-available/peertube
7a3864e8
M
140```
141
5668bf2e
C
142Then modify the webserver configuration file. Please pay attention to the `alias` keys of the static locations.
143It should correspond to the paths of your storage directories (set in the configuration file inside the `storage` key).
63bfad7e 144
a23f6c94 145```bash
63bfad7e
C
146$ sudo vim /etc/nginx/sites-available/peertube
147```
148
0b495712
C
149Activate the configuration file:
150
a23f6c94 151```bash
0b495712
C
152$ sudo ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube
153```
154
155To generate the certificate for your domain as required to make https work you can use [Let's Encrypt](https://letsencrypt.org/):
156
a23f6c94 157```bash
0b495712 158$ sudo systemctl stop nginx
f35f23d8 159$ sudo certbot certonly --standalone --post-hook "systemctl restart nginx"
e6607b25 160$ sudo systemctl reload nginx
e883399f
RK
161```
162
d8658f0f
C
163Certbot should have installed a cron to automatically renew your certificate.
164Since our nginx template supports webroot renewal, we suggest you to update the renewal config file to use the `webroot` authenticator:
165
a23f6c94 166```bash
d8658f0f 167$ # Replace authenticator = standalone by authenticator = webroot
08a9ee19 168$ # Add webroot_path = /var/www/certbot
d8658f0f
C
169$ sudo vim /etc/letsencrypt/renewal/your-domain.com.conf
170```
171
4c86a254
GN
172**FreeBSD**
173On FreeBSD you can use [Dehydrated](https://dehydrated.io/) `security/dehydrated` for [Let's Encrypt](https://letsencrypt.org/)
174
a23f6c94 175```bash
4c86a254
GN
176$ sudo pkg install dehydrated
177```
178
a23f6c94 179### :alembic: TCP/IP Tuning
f74c294a
MES
180
181**On Linux**
182
a23f6c94 183```bash
f74c294a
MES
184$ sudo cp /var/www/peertube/peertube-latest/support/sysctl.d/30-peertube-tcp.conf /etc/sysctl.d/
185$ sudo sysctl -p /etc/sysctl.d/30-peertube-tcp.conf
186```
187
188Your distro may enable this by default, but at least Debian 9 does not, and the default FIFO
189scheduler is quite prone to "Buffer Bloat" and extreme latency when dealing with slower client
190links as we often encounter in a video server.
191
a23f6c94 192### :bricks: systemd
63bfad7e 193
07aa93a8 194If your OS uses systemd, copy the configuration template:
63bfad7e 195
a23f6c94 196```bash
59c48d49 197$ sudo cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/
63bfad7e
C
198```
199
96df6ca6 200Check the service file (PeerTube paths and security directives):
63bfad7e 201
a23f6c94 202```bash
d2000ca6 203$ sudo vim /etc/systemd/system/peertube.service
63bfad7e
C
204```
205
63bfad7e
C
206
207Tell systemd to reload its config:
208
a23f6c94 209```bash
d2000ca6 210$ sudo systemctl daemon-reload
63bfad7e
C
211```
212
6b2ef589
C
213If you want to start PeerTube on boot:
214
a23f6c94 215```bash
9625507f 216$ sudo systemctl enable peertube
6b2ef589
C
217```
218
07aa93a8 219Run:
63bfad7e 220
a23f6c94 221```bash
d2000ca6
C
222$ sudo systemctl start peertube
223$ sudo journalctl -feu peertube
63bfad7e
C
224```
225
65fcf1e9
C
226**FreeBSD**
227On FreeBSD, copy the startup script and update rc.conf:
6d55bd21 228
a23f6c94 229```bash
31d45e0e
MP
230$ sudo install -m 0555 /var/www/peertube/peertube-latest/support/freebsd/peertube /usr/local/etc/rc.d/
231$ sudo sysrc peertube_enable="YES"
6d55bd21
GN
232```
233
07aa93a8 234Run:
6d55bd21 235
a23f6c94 236```bash
6d55bd21
GN
237$ sudo service peertube start
238```
239
a23f6c94 240### :bricks: OpenRC
67ac918d
W
241
242If your OS uses OpenRC, copy the service script:
243
a23f6c94 244```bash
67ac918d
W
245$ sudo cp /var/www/peertube/peertube-latest/support/init.d/peertube /etc/init.d/
246```
247
248If you want to start PeerTube on boot:
249
a23f6c94 250```bash
67ac918d
W
251$ sudo rc-update add peertube default
252```
253
254Run and print last logs:
255
a23f6c94 256```bash
67ac918d
W
257$ sudo /etc/init.d/peertube start
258$ tail -f /var/log/peertube/peertube.log
259```
260
a23f6c94 261### :technologist: Administrator
63bfad7e 262
fc10ecf1 263The administrator username is `root` and the password is automatically generated. It can be found in PeerTube
d8658f0f 264logs (path defined in `production.yaml`). You can also set another password with:
63bfad7e 265
a23f6c94 266```bash
59c48d49 267$ cd /var/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root
63bfad7e
C
268```
269
3daaa192
AV
270Alternatively you can set the environment variable `PT_INITIAL_ROOT_PASSWORD`,
271to your own administrator password, although it must be 6 characters or more.
272
a23f6c94 273### :tada: What now?
9c758359
C
274
275Now your instance is up you can:
2c92b063 276
4d582cec 277 * Add your instance to the public PeerTube instances index if you want to: https://instances.joinpeertube.org/
d06caf3e 278 * Check [available CLI tools](/support/doc/tools.md)
2e3a0215 279
63bfad7e
C
280## Upgrade
281
57c36b27 282### PeerTube instance
b314f983 283
e76daa73 284**Check the changelog (in particular the *IMPORTANT NOTES* section):** https://github.com/Chocobozzz/PeerTube/blob/develop/CHANGELOG.md
b314f983 285
c0605e6e 286#### Auto
1007a018 287
4246247f
LD
288The password it asks is PeerTube's database user password.
289
a23f6c94 290```bash
fbd2ad19 291$ cd /var/www/peertube/peertube-latest/scripts && sudo -H -u peertube ./upgrade.sh
188aa774 292$ sudo systemctl restart peertube # Or use your OS command to restart PeerTube if you don't use systemd
1007a018
SL
293```
294
a8b5ce95
C
295#### Manually
296
ce487e1e 297Make a SQL backup
c7a9f34f 298
a23f6c94 299```bash
c7a9f34f 300$ SQL_BACKUP_PATH="backup/sql-peertube_prod-$(date -Im).bak" && \
59c48d49 301 cd /var/www/peertube && sudo -u peertube mkdir -p backup && \
43c4c639 302 sudo -u postgres pg_dump -F c peertube_prod | sudo -u peertube tee "$SQL_BACKUP_PATH" >/dev/null
c7a9f34f
C
303```
304
ce487e1e 305Fetch the latest tagged version of Peertube:
23e27dd5 306
a23f6c94 307```bash
ce487e1e 308$ 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
309```
310
ce487e1e 311Download the new version and unzip it:
c7a9f34f 312
a23f6c94 313```bash
ce487e1e 314$ cd /var/www/peertube/versions && \
fd206f0b 315 sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" && \
ce487e1e
C
316 sudo -u peertube unzip -o peertube-${VERSION}.zip && \
317 sudo -u peertube rm peertube-${VERSION}.zip
318```
319
4805cff1 320Install node dependencies:
ce487e1e 321
a23f6c94 322```bash
4805cff1 323$ cd /var/www/peertube/versions/peertube-${VERSION} && \
fbd2ad19 324 sudo -H -u peertube yarn install --production --pure-lockfile
ce487e1e
C
325```
326
4805cff1 327Copy new configuration defaults values and update your configuration file:
ce487e1e 328
a23f6c94 329```bash
4805cff1 330$ sudo -u peertube cp /var/www/peertube/versions/peertube-${VERSION}/config/default.yaml /var/www/peertube/config/default.yaml
c501cdef 331$ diff -u /var/www/peertube/versions/peertube-${VERSION}/config/production.yaml.example /var/www/peertube/config/production.yaml
ce487e1e
C
332```
333
4805cff1 334Change the link to point to the latest version:
ce487e1e 335
a23f6c94 336```bash
4805cff1 337$ cd /var/www/peertube && \
2519d9fe 338 sudo unlink ./peertube-latest && \
4805cff1 339 sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
ce487e1e
C
340```
341
7f6ff462
JL
342### Configuration
343
344You can check for configuration changes, and report them in your `config/production.yaml` file:
345
346```bash
347$ cd /var/www/peertube/versions
348$ diff -u "$(ls --sort=t | head -2 | tail -1)/config/production.yaml.example" "$(ls --sort=t | head -1)/config/production.yaml.example"
349```
350
b314f983
C
351### nginx
352
353Check changes in nginx configuration:
354
a23f6c94 355```bash
b314f983 356$ cd /var/www/peertube/versions
c501cdef 357$ diff -u "$(ls --sort=t | head -2 | tail -1)/support/nginx/peertube" "$(ls --sort=t | head -1)/support/nginx/peertube"
b314f983
C
358```
359
360### systemd
361
362Check changes in systemd configuration:
363
a23f6c94 364```bash
b314f983 365$ cd /var/www/peertube/versions
c501cdef 366$ diff -u "$(ls --sort=t | head -2 | tail -1)/support/systemd/peertube.service" "$(ls --sort=t | head -1)/support/systemd/peertube.service"
b314f983
C
367```
368
369### Restart PeerTube
370
371If you changed your nginx configuration:
372
a23f6c94 373```bash
b314f983
C
374$ sudo systemctl reload nginx
375```
376
377If you changed your systemd configuration:
4805cff1 378
a23f6c94 379```bash
b314f983
C
380$ sudo systemctl daemon-reload
381```
382
383Restart PeerTube and check the logs:
384
a23f6c94 385```bash
b314f983 386$ sudo systemctl restart peertube && sudo journalctl -fu peertube
ce487e1e
C
387```
388
4c86a254 389### Things went wrong?
c7a9f34f 390
ce487e1e 391Change `peertube-latest` destination to the previous version and restore your SQL backup:
c7a9f34f 392
a23f6c94 393```bash
c7a9f34f 394$ OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \
43c4c639 395 cd /var/www/peertube && sudo -u peertube unlink ./peertube-latest && \
c7a9f34f 396 sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \
43c4c639 397 sudo -u postgres pg_restore -c -C -d postgres "$SQL_BACKUP_PATH" && \
c7a9f34f
C
398 sudo systemctl restart peertube
399```