]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - support/doc/production.md
store uploaded video filename (#4885)
[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
0b495712 163Now you have the certificates you can reload nginx:
63bfad7e 164
a23f6c94 165```bash
63bfad7e
C
166$ sudo systemctl reload nginx
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
4c86a254
GN
178**FreeBSD**
179On FreeBSD you can use [Dehydrated](https://dehydrated.io/) `security/dehydrated` for [Let's Encrypt](https://letsencrypt.org/)
180
a23f6c94 181```bash
4c86a254
GN
182$ sudo pkg install dehydrated
183```
184
a23f6c94 185### :alembic: TCP/IP Tuning
f74c294a
MES
186
187**On Linux**
188
a23f6c94 189```bash
f74c294a
MES
190$ sudo cp /var/www/peertube/peertube-latest/support/sysctl.d/30-peertube-tcp.conf /etc/sysctl.d/
191$ sudo sysctl -p /etc/sysctl.d/30-peertube-tcp.conf
192```
193
194Your distro may enable this by default, but at least Debian 9 does not, and the default FIFO
195scheduler is quite prone to "Buffer Bloat" and extreme latency when dealing with slower client
196links as we often encounter in a video server.
197
a23f6c94 198### :bricks: systemd
63bfad7e 199
07aa93a8 200If your OS uses systemd, copy the configuration template:
63bfad7e 201
a23f6c94 202```bash
59c48d49 203$ sudo cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/
63bfad7e
C
204```
205
96df6ca6 206Check the service file (PeerTube paths and security directives):
63bfad7e 207
a23f6c94 208```bash
d2000ca6 209$ sudo vim /etc/systemd/system/peertube.service
63bfad7e
C
210```
211
63bfad7e
C
212
213Tell systemd to reload its config:
214
a23f6c94 215```bash
d2000ca6 216$ sudo systemctl daemon-reload
63bfad7e
C
217```
218
6b2ef589
C
219If you want to start PeerTube on boot:
220
a23f6c94 221```bash
9625507f 222$ sudo systemctl enable peertube
6b2ef589
C
223```
224
07aa93a8 225Run:
63bfad7e 226
a23f6c94 227```bash
d2000ca6
C
228$ sudo systemctl start peertube
229$ sudo journalctl -feu peertube
63bfad7e
C
230```
231
65fcf1e9
C
232**FreeBSD**
233On FreeBSD, copy the startup script and update rc.conf:
6d55bd21 234
a23f6c94 235```bash
31d45e0e
MP
236$ sudo install -m 0555 /var/www/peertube/peertube-latest/support/freebsd/peertube /usr/local/etc/rc.d/
237$ sudo sysrc peertube_enable="YES"
6d55bd21
GN
238```
239
07aa93a8 240Run:
6d55bd21 241
a23f6c94 242```bash
6d55bd21
GN
243$ sudo service peertube start
244```
245
a23f6c94 246### :bricks: OpenRC
67ac918d
W
247
248If your OS uses OpenRC, copy the service script:
249
a23f6c94 250```bash
67ac918d
W
251$ sudo cp /var/www/peertube/peertube-latest/support/init.d/peertube /etc/init.d/
252```
253
254If you want to start PeerTube on boot:
255
a23f6c94 256```bash
67ac918d
W
257$ sudo rc-update add peertube default
258```
259
260Run and print last logs:
261
a23f6c94 262```bash
67ac918d
W
263$ sudo /etc/init.d/peertube start
264$ tail -f /var/log/peertube/peertube.log
265```
266
a23f6c94 267### :technologist: Administrator
63bfad7e 268
fc10ecf1 269The administrator username is `root` and the password is automatically generated. It can be found in PeerTube
d8658f0f 270logs (path defined in `production.yaml`). You can also set another password with:
63bfad7e 271
a23f6c94 272```bash
59c48d49 273$ cd /var/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root
63bfad7e
C
274```
275
3daaa192
AV
276Alternatively you can set the environment variable `PT_INITIAL_ROOT_PASSWORD`,
277to your own administrator password, although it must be 6 characters or more.
278
a23f6c94 279### :tada: What now?
9c758359
C
280
281Now your instance is up you can:
2c92b063 282
4d582cec 283 * Add your instance to the public PeerTube instances index if you want to: https://instances.joinpeertube.org/
d06caf3e 284 * Check [available CLI tools](/support/doc/tools.md)
2e3a0215 285
63bfad7e
C
286## Upgrade
287
57c36b27 288### PeerTube instance
b314f983
C
289
290**Check the changelog (in particular BREAKING CHANGES!):** https://github.com/Chocobozzz/PeerTube/blob/develop/CHANGELOG.md
291
c0605e6e 292#### Auto
1007a018 293
4246247f
LD
294The password it asks is PeerTube's database user password.
295
a23f6c94 296```bash
fbd2ad19 297$ cd /var/www/peertube/peertube-latest/scripts && sudo -H -u peertube ./upgrade.sh
188aa774 298$ sudo systemctl restart peertube # Or use your OS command to restart PeerTube if you don't use systemd
1007a018
SL
299```
300
a8b5ce95
C
301#### Manually
302
ce487e1e 303Make a SQL backup
c7a9f34f 304
a23f6c94 305```bash
c7a9f34f 306$ SQL_BACKUP_PATH="backup/sql-peertube_prod-$(date -Im).bak" && \
59c48d49 307 cd /var/www/peertube && sudo -u peertube mkdir -p backup && \
43c4c639 308 sudo -u postgres pg_dump -F c peertube_prod | sudo -u peertube tee "$SQL_BACKUP_PATH" >/dev/null
c7a9f34f
C
309```
310
ce487e1e 311Fetch the latest tagged version of Peertube:
23e27dd5 312
a23f6c94 313```bash
ce487e1e 314$ 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
315```
316
ce487e1e 317Download the new version and unzip it:
c7a9f34f 318
a23f6c94 319```bash
ce487e1e 320$ cd /var/www/peertube/versions && \
fd206f0b 321 sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" && \
ce487e1e
C
322 sudo -u peertube unzip -o peertube-${VERSION}.zip && \
323 sudo -u peertube rm peertube-${VERSION}.zip
324```
325
4805cff1 326Install node dependencies:
ce487e1e 327
a23f6c94 328```bash
4805cff1 329$ cd /var/www/peertube/versions/peertube-${VERSION} && \
fbd2ad19 330 sudo -H -u peertube yarn install --production --pure-lockfile
ce487e1e
C
331```
332
4805cff1 333Copy new configuration defaults values and update your configuration file:
ce487e1e 334
a23f6c94 335```bash
4805cff1 336$ sudo -u peertube cp /var/www/peertube/versions/peertube-${VERSION}/config/default.yaml /var/www/peertube/config/default.yaml
c501cdef 337$ diff -u /var/www/peertube/versions/peertube-${VERSION}/config/production.yaml.example /var/www/peertube/config/production.yaml
ce487e1e
C
338```
339
4805cff1 340Change the link to point to the latest version:
ce487e1e 341
a23f6c94 342```bash
4805cff1 343$ cd /var/www/peertube && \
2519d9fe 344 sudo unlink ./peertube-latest && \
4805cff1 345 sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
ce487e1e
C
346```
347
7f6ff462
JL
348### Configuration
349
350You can check for configuration changes, and report them in your `config/production.yaml` file:
351
352```bash
353$ cd /var/www/peertube/versions
354$ diff -u "$(ls --sort=t | head -2 | tail -1)/config/production.yaml.example" "$(ls --sort=t | head -1)/config/production.yaml.example"
355```
356
b314f983
C
357### nginx
358
359Check changes in nginx configuration:
360
a23f6c94 361```bash
b314f983 362$ cd /var/www/peertube/versions
c501cdef 363$ diff -u "$(ls --sort=t | head -2 | tail -1)/support/nginx/peertube" "$(ls --sort=t | head -1)/support/nginx/peertube"
b314f983
C
364```
365
366### systemd
367
368Check changes in systemd configuration:
369
a23f6c94 370```bash
b314f983 371$ cd /var/www/peertube/versions
c501cdef 372$ diff -u "$(ls --sort=t | head -2 | tail -1)/support/systemd/peertube.service" "$(ls --sort=t | head -1)/support/systemd/peertube.service"
b314f983
C
373```
374
375### Restart PeerTube
376
377If you changed your nginx configuration:
378
a23f6c94 379```bash
b314f983
C
380$ sudo systemctl reload nginx
381```
382
383If you changed your systemd configuration:
4805cff1 384
a23f6c94 385```bash
b314f983
C
386$ sudo systemctl daemon-reload
387```
388
389Restart PeerTube and check the logs:
390
a23f6c94 391```bash
b314f983 392$ sudo systemctl restart peertube && sudo journalctl -fu peertube
ce487e1e
C
393```
394
4c86a254 395### Things went wrong?
c7a9f34f 396
ce487e1e 397Change `peertube-latest` destination to the previous version and restore your SQL backup:
c7a9f34f 398
a23f6c94 399```bash
c7a9f34f 400$ OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \
43c4c639 401 cd /var/www/peertube && sudo -u peertube unlink ./peertube-latest && \
c7a9f34f 402 sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \
43c4c639 403 sudo -u postgres pg_restore -c -C -d postgres "$SQL_BACKUP_PATH" && \
c7a9f34f
C
404 sudo systemctl restart peertube
405```