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