]>
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 | ||
4c86a254 GN |
28 | **On FreeBSD** |
29 | ||
a23f6c94 | 30 | ```bash |
4c86a254 GN |
31 | $ sudo pw useradd -n peertube -d /var/www/peertube -s /usr/local/bin/bash -m |
32 | $ sudo passwd peertube | |
33 | ``` | |
34 | or use `adduser` to create it interactively. | |
35 | ||
a23f6c94 | 36 | ### :card_file_box: Database |
63bfad7e | 37 | |
e5203ffa | 38 | Create the production database and a peertube user inside PostgreSQL: |
63bfad7e | 39 | |
a23f6c94 | 40 | ```bash |
3dc8a86c | 41 | $ cd /var/www/peertube |
d2000ca6 | 42 | $ sudo -u postgres createuser -P peertube |
c11fc2d9 | 43 | ``` |
44 | ||
2c5eab14 C |
45 | Here you should enter a password for PostgreSQL `peertube` user, that should be copied in `production.yaml` file. |
46 | Don't just hit enter else it will be empty. | |
c11fc2d9 | 47 | |
a23f6c94 | 48 | ```bash |
0539dba8 | 49 | $ sudo -u postgres createdb -O peertube -E UTF8 -T template0 peertube_prod |
63bfad7e C |
50 | ``` |
51 | ||
57c36b27 C |
52 | Then enable extensions PeerTube needs: |
53 | ||
a23f6c94 | 54 | ```bash |
57c36b27 C |
55 | $ sudo -u postgres psql -c "CREATE EXTENSION pg_trgm;" peertube_prod |
56 | $ sudo -u postgres psql -c "CREATE EXTENSION unaccent;" peertube_prod | |
57 | ``` | |
58 | ||
a23f6c94 | 59 | ### :page_facing_up: Prepare PeerTube directory |
63bfad7e | 60 | |
c501f441 C |
61 | Fetch the latest tagged version of Peertube: |
62 | ||
a23f6c94 | 63 | ```bash |
e5203ffa TC |
64 | $ 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" |
65 | ``` | |
59c48d49 | 66 | |
c501f441 C |
67 | |
68 | Open the peertube directory, create a few required directories: | |
69 | ||
a23f6c94 | 70 | ```bash |
d8658f0f C |
71 | $ cd /var/www/peertube |
72 | $ sudo -u peertube mkdir config storage versions | |
6d8e1f28 | 73 | $ sudo -u peertube chmod 750 config/ |
e5203ffa | 74 | ``` |
59c48d49 | 75 | |
c501f441 C |
76 | |
77 | Download the latest version of the Peertube client, unzip it and remove the zip: | |
78 | ||
a23f6c94 | 79 | ```bash |
d8658f0f | 80 | $ cd /var/www/peertube/versions |
c501f441 | 81 | $ # Releases are also available on https://builds.joinpeertube.org/release |
15dbc134 | 82 | $ sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" |
c201278d | 83 | $ sudo -u peertube unzip -q peertube-${VERSION}.zip && sudo -u peertube rm peertube-${VERSION}.zip |
e5203ffa | 84 | ``` |
59c48d49 | 85 | |
c501f441 | 86 | |
cfdd9eb4 | 87 | Install Peertube: |
c501f441 | 88 | |
a23f6c94 | 89 | ```bash |
d8658f0f C |
90 | $ cd /var/www/peertube |
91 | $ sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest | |
09c93c20 | 92 | $ cd ./peertube-latest && sudo -H -u peertube yarn install --production --pure-lockfile |
63bfad7e C |
93 | ``` |
94 | ||
a23f6c94 | 95 | ### :wrench: PeerTube configuration |
63bfad7e | 96 | |
4948dcdb C |
97 | Copy the default configuration file that contains the default configuration provided by PeerTube. |
98 | You **must not** update this file. | |
99 | ||
a23f6c94 | 100 | ```bash |
d8658f0f C |
101 | $ cd /var/www/peertube |
102 | $ sudo -u peertube cp peertube-latest/config/default.yaml config/default.yaml | |
4948dcdb C |
103 | ``` |
104 | ||
105 | Now copy the production example configuration: | |
63bfad7e | 106 | |
a23f6c94 | 107 | ```bash |
d8658f0f C |
108 | $ cd /var/www/peertube |
109 | $ sudo -u peertube cp peertube-latest/config/production.yaml.example config/production.yaml | |
63bfad7e C |
110 | ``` |
111 | ||
112 | Then edit the `config/production.yaml` file according to your webserver | |
d8658f0f C |
113 | and database configuration (`webserver`, `database`, `redis`, `smtp` and `admin.email` sections in particular). |
114 | Keys defined in `config/production.yaml` will override keys defined in `config/default.yaml`. | |
63bfad7e | 115 | |
7cf88d09 | 116 | **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 | 117 | |
a23f6c94 | 118 | ### :truck: Webserver |
63bfad7e | 119 | |
e883399f RK |
120 | We only provide official configuration files for Nginx. |
121 | ||
63bfad7e C |
122 | Copy the nginx configuration template: |
123 | ||
a23f6c94 | 124 | ```bash |
59c48d49 | 125 | $ sudo cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube |
63bfad7e C |
126 | ``` |
127 | ||
2c92b063 C |
128 | Then set the domain for the webserver configuration file. |
129 | Replace `[peertube-domain]` with the domain for the peertube server. | |
7a3864e8 | 130 | |
a23f6c94 | 131 | ```bash |
1a9b141d | 132 | $ sudo sed -i 's/${WEBSERVER_HOST}/[peertube-domain]/g' /etc/nginx/sites-available/peertube |
feb0f998 | 133 | $ sudo sed -i 's/${PEERTUBE_HOST}/127.0.0.1:9000/g' /etc/nginx/sites-available/peertube |
7a3864e8 M |
134 | ``` |
135 | ||
5668bf2e C |
136 | Then modify the webserver configuration file. Please pay attention to the `alias` keys of the static locations. |
137 | It should correspond to the paths of your storage directories (set in the configuration file inside the `storage` key). | |
63bfad7e | 138 | |
a23f6c94 | 139 | ```bash |
63bfad7e C |
140 | $ sudo vim /etc/nginx/sites-available/peertube |
141 | ``` | |
142 | ||
0b495712 C |
143 | Activate the configuration file: |
144 | ||
a23f6c94 | 145 | ```bash |
0b495712 C |
146 | $ sudo ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube |
147 | ``` | |
148 | ||
149 | To generate the certificate for your domain as required to make https work you can use [Let's Encrypt](https://letsencrypt.org/): | |
150 | ||
a23f6c94 | 151 | ```bash |
0b495712 | 152 | $ sudo systemctl stop nginx |
f35f23d8 | 153 | $ sudo certbot certonly --standalone --post-hook "systemctl restart nginx" |
e6607b25 | 154 | $ sudo systemctl reload nginx |
e883399f RK |
155 | ``` |
156 | ||
0b495712 | 157 | Now you have the certificates you can reload nginx: |
63bfad7e | 158 | |
a23f6c94 | 159 | ```bash |
63bfad7e C |
160 | $ sudo systemctl reload nginx |
161 | ``` | |
162 | ||
d8658f0f C |
163 | Certbot should have installed a cron to automatically renew your certificate. |
164 | Since 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** |
173 | On 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 | ||
188 | Your distro may enable this by default, but at least Debian 9 does not, and the default FIFO | |
189 | scheduler is quite prone to "Buffer Bloat" and extreme latency when dealing with slower client | |
190 | links as we often encounter in a video server. | |
191 | ||
a23f6c94 | 192 | ### :bricks: systemd |
63bfad7e | 193 | |
07aa93a8 | 194 | If 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 | 200 | Check 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 | |
207 | Tell systemd to reload its config: | |
208 | ||
a23f6c94 | 209 | ```bash |
d2000ca6 | 210 | $ sudo systemctl daemon-reload |
63bfad7e C |
211 | ``` |
212 | ||
6b2ef589 C |
213 | If you want to start PeerTube on boot: |
214 | ||
a23f6c94 | 215 | ```bash |
9625507f | 216 | $ sudo systemctl enable peertube |
6b2ef589 C |
217 | ``` |
218 | ||
07aa93a8 | 219 | Run: |
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** |
227 | On 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 | 234 | Run: |
6d55bd21 | 235 | |
a23f6c94 | 236 | ```bash |
6d55bd21 GN |
237 | $ sudo service peertube start |
238 | ``` | |
239 | ||
a23f6c94 | 240 | ### :bricks: OpenRC |
67ac918d W |
241 | |
242 | If 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 | ||
248 | If you want to start PeerTube on boot: | |
249 | ||
a23f6c94 | 250 | ```bash |
67ac918d W |
251 | $ sudo rc-update add peertube default |
252 | ``` | |
253 | ||
254 | Run 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 | 263 | The administrator username is `root` and the password is automatically generated. It can be found in PeerTube |
d8658f0f | 264 | logs (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 |
270 | Alternatively you can set the environment variable `PT_INITIAL_ROOT_PASSWORD`, |
271 | to your own administrator password, although it must be 6 characters or more. | |
272 | ||
a23f6c94 | 273 | ### :tada: What now? |
9c758359 C |
274 | |
275 | Now 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 C |
283 | |
284 | **Check the changelog (in particular BREAKING CHANGES!):** https://github.com/Chocobozzz/PeerTube/blob/develop/CHANGELOG.md | |
285 | ||
c0605e6e | 286 | #### Auto |
1007a018 | 287 | |
4246247f LD |
288 | The 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 | 297 | Make 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 | 305 | Fetch 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 | 311 | Download 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 | 320 | Install 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 | 327 | Copy 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 | 334 | Change 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 | ||
b314f983 C |
342 | ### nginx |
343 | ||
344 | Check changes in nginx configuration: | |
345 | ||
a23f6c94 | 346 | ```bash |
b314f983 | 347 | $ cd /var/www/peertube/versions |
c501cdef | 348 | $ diff -u "$(ls --sort=t | head -2 | tail -1)/support/nginx/peertube" "$(ls --sort=t | head -1)/support/nginx/peertube" |
b314f983 C |
349 | ``` |
350 | ||
351 | ### systemd | |
352 | ||
353 | Check changes in systemd configuration: | |
354 | ||
a23f6c94 | 355 | ```bash |
b314f983 | 356 | $ cd /var/www/peertube/versions |
c501cdef | 357 | $ diff -u "$(ls --sort=t | head -2 | tail -1)/support/systemd/peertube.service" "$(ls --sort=t | head -1)/support/systemd/peertube.service" |
b314f983 C |
358 | ``` |
359 | ||
360 | ### Restart PeerTube | |
361 | ||
362 | If you changed your nginx configuration: | |
363 | ||
a23f6c94 | 364 | ```bash |
b314f983 C |
365 | $ sudo systemctl reload nginx |
366 | ``` | |
367 | ||
368 | If you changed your systemd configuration: | |
4805cff1 | 369 | |
a23f6c94 | 370 | ```bash |
b314f983 C |
371 | $ sudo systemctl daemon-reload |
372 | ``` | |
373 | ||
374 | Restart PeerTube and check the logs: | |
375 | ||
a23f6c94 | 376 | ```bash |
b314f983 | 377 | $ sudo systemctl restart peertube && sudo journalctl -fu peertube |
ce487e1e C |
378 | ``` |
379 | ||
4c86a254 | 380 | ### Things went wrong? |
c7a9f34f | 381 | |
ce487e1e | 382 | Change `peertube-latest` destination to the previous version and restore your SQL backup: |
c7a9f34f | 383 | |
a23f6c94 | 384 | ```bash |
c7a9f34f | 385 | $ OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \ |
43c4c639 | 386 | cd /var/www/peertube && sudo -u peertube unlink ./peertube-latest && \ |
c7a9f34f | 387 | sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \ |
43c4c639 | 388 | sudo -u postgres pg_restore -c -C -d postgres "$SQL_BACKUP_PATH" && \ |
c7a9f34f C |
389 | sudo systemctl restart peertube |
390 | ``` |