ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

production.md 12 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. # Production guide
  2. * [Installation](#installation)
  3. * [Upgrade](#upgrade)
  4. ## Installation
  5. Please don't install PeerTube for production on a device behind a low bandwidth connection (example: your ADSL link).
  6. 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).
  7. ### :hammer: Dependencies
  8. Follow the steps of the [dependencies guide](/support/doc/dependencies.md).
  9. ### :construction_worker: PeerTube user
  10. Create a `peertube` user with `/var/www/peertube` home:
  11. ```bash
  12. sudo useradd -m -d /var/www/peertube -s /bin/bash -p peertube peertube
  13. ```
  14. Set its password:
  15. ```bash
  16. sudo passwd peertube
  17. ```
  18. Ensure the peertube root directory is traversable by nginx:
  19. ```bash
  20. ls -ld /var/www/peertube # Should be drwxr-xr-x
  21. ```
  22. **On FreeBSD**
  23. ```bash
  24. sudo pw useradd -n peertube -d /var/www/peertube -s /usr/local/bin/bash -m
  25. sudo passwd peertube
  26. ```
  27. or use `adduser` to create it interactively.
  28. ### :card_file_box: Database
  29. Create the production database and a peertube user inside PostgreSQL:
  30. ```bash
  31. cd /var/www/peertube
  32. sudo -u postgres createuser -P peertube
  33. ```
  34. Here you should enter a password for PostgreSQL `peertube` user, that should be copied in `production.yaml` file.
  35. Don't just hit enter else it will be empty.
  36. ```bash
  37. sudo -u postgres createdb -O peertube -E UTF8 -T template0 peertube_prod
  38. ```
  39. Then enable extensions PeerTube needs:
  40. ```bash
  41. sudo -u postgres psql -c "CREATE EXTENSION pg_trgm;" peertube_prod
  42. sudo -u postgres psql -c "CREATE EXTENSION unaccent;" peertube_prod
  43. ```
  44. ### :page_facing_up: Prepare PeerTube directory
  45. Fetch the latest tagged version of Peertube:
  46. ```bash
  47. 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"
  48. ```
  49. Open the peertube directory, create a few required directories:
  50. ```bash
  51. cd /var/www/peertube
  52. sudo -u peertube mkdir config storage versions
  53. sudo -u peertube chmod 750 config/
  54. ```
  55. Download the latest version of the Peertube client, unzip it and remove the zip:
  56. ```bash
  57. cd /var/www/peertube/versions
  58. # Releases are also available on https://builds.joinpeertube.org/release
  59. sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip"
  60. sudo -u peertube unzip -q peertube-${VERSION}.zip && sudo -u peertube rm peertube-${VERSION}.zip
  61. ```
  62. Install Peertube:
  63. ```bash
  64. cd /var/www/peertube
  65. sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
  66. cd ./peertube-latest && sudo -H -u peertube yarn install --production --pure-lockfile
  67. ```
  68. ### :wrench: PeerTube configuration
  69. Copy the default configuration file that contains the default configuration provided by PeerTube.
  70. You **must not** update this file.
  71. ```bash
  72. cd /var/www/peertube
  73. sudo -u peertube cp peertube-latest/config/default.yaml config/default.yaml
  74. ```
  75. Now copy the production example configuration:
  76. ```bash
  77. cd /var/www/peertube
  78. sudo -u peertube cp peertube-latest/config/production.yaml.example config/production.yaml
  79. ```
  80. Then edit the `config/production.yaml` file according to your webserver and database configuration. In particular:
  81. * `webserver`: Reverse proxy public information
  82. * `secrets`: Secret strings you must generate manually (PeerTube version >= 5.0)
  83. * `database`: PostgreSQL settings
  84. * `redis`: Redis settings
  85. * `smtp`: If you want to use emails
  86. * `admin.email`: To correctly fill `root` user email
  87. Keys defined in `config/production.yaml` will override keys defined in `config/default.yaml`.
  88. **PeerTube does not support webserver host change**. Even though [PeerTube CLI can help you to switch hostname](https://docs.joinpeertube.org/maintain/tools#update-host-js) there's no official support for that since it is a risky operation that might result in unforeseen errors.
  89. ### :truck: Webserver
  90. We only provide official configuration files for Nginx.
  91. Copy the nginx configuration template:
  92. ```bash
  93. sudo cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube
  94. ```
  95. Set the domain for the webserver configuration file by replacing `[peertube-domain]` with the domain for the peertube server:
  96. ```bash
  97. sudo sed -i 's/${WEBSERVER_HOST}/[peertube-domain]/g' /etc/nginx/sites-available/peertube
  98. sudo sed -i 's/${PEERTUBE_HOST}/127.0.0.1:9000/g' /etc/nginx/sites-available/peertube
  99. ```
  100. Then modify the webserver configuration file. Please pay attention to:
  101. * the `alias`, `root` and `rewrite` directives paths, the paths must correspond to your PeerTube filesystem location
  102. * the `proxy_limit_rate` and `limit_rate` directives if you plan to stream high bitrate videos (like 4K at 60FPS)
  103. ```bash
  104. sudo vim /etc/nginx/sites-available/peertube
  105. ```
  106. Activate the configuration file:
  107. ```bash
  108. sudo ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube
  109. ```
  110. To generate the certificate for your domain as required to make https work you can use [Let's Encrypt](https://letsencrypt.org/):
  111. ```bash
  112. sudo systemctl stop nginx
  113. sudo certbot certonly --standalone --post-hook "systemctl restart nginx"
  114. sudo systemctl reload nginx
  115. ```
  116. Certbot should have installed a cron to automatically renew your certificate.
  117. Since our nginx template supports webroot renewal, we suggest you to update the renewal config file to use the `webroot` authenticator:
  118. ```bash
  119. # Replace authenticator = standalone by authenticator = webroot
  120. # Add webroot_path = /var/www/certbot
  121. sudo vim /etc/letsencrypt/renewal/your-domain.com.conf
  122. ```
  123. 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.
  124. <details>
  125. <summary><strong>If using FreeBSD</strong></summary>
  126. On FreeBSD you can use [Dehydrated](https://dehydrated.io/) `security/dehydrated` for [Let's Encrypt](https://letsencrypt.org/)
  127. ```bash
  128. sudo pkg install dehydrated
  129. ```
  130. </details>
  131. ### :alembic: Linux TCP/IP Tuning
  132. ```bash
  133. sudo cp /var/www/peertube/peertube-latest/support/sysctl.d/30-peertube-tcp.conf /etc/sysctl.d/
  134. sudo sysctl -p /etc/sysctl.d/30-peertube-tcp.conf
  135. ```
  136. Your distro may enable this by default, but at least Debian 9 does not, and the default FIFO
  137. scheduler is quite prone to "Buffer Bloat" and extreme latency when dealing with slower client
  138. links as we often encounter in a video server.
  139. ### :bricks: systemd
  140. If your OS uses systemd, copy the configuration template:
  141. ```bash
  142. sudo cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/
  143. ```
  144. Check the service file (PeerTube paths and security directives):
  145. ```bash
  146. sudo vim /etc/systemd/system/peertube.service
  147. ```
  148. Tell systemd to reload its config:
  149. ```bash
  150. sudo systemctl daemon-reload
  151. ```
  152. If you want to start PeerTube on boot:
  153. ```bash
  154. sudo systemctl enable peertube
  155. ```
  156. Run:
  157. ```bash
  158. sudo systemctl start peertube
  159. sudo journalctl -feu peertube
  160. ```
  161. <details>
  162. <summary><strong>If using FreeBSD</strong></summary>
  163. On FreeBSD, copy the startup script and update rc.conf:
  164. ```bash
  165. sudo install -m 0555 /var/www/peertube/peertube-latest/support/freebsd/peertube /usr/local/etc/rc.d/
  166. sudo sysrc peertube_enable="YES"
  167. ```
  168. Run:
  169. ```bash
  170. sudo service peertube start
  171. ```
  172. </details>
  173. <details>
  174. <summary><strong>If using OpenRC</strong></summary>
  175. If your OS uses OpenRC, copy the service script:
  176. ```bash
  177. sudo cp /var/www/peertube/peertube-latest/support/init.d/peertube /etc/init.d/
  178. ```
  179. If you want to start PeerTube on boot:
  180. ```bash
  181. sudo rc-update add peertube default
  182. ```
  183. Run and print last logs:
  184. ```bash
  185. sudo /etc/init.d/peertube start
  186. tail -f /var/log/peertube/peertube.log
  187. ```
  188. </details>
  189. ### :technologist: Administrator
  190. The administrator username is `root` and the password is automatically generated. It can be found in PeerTube
  191. logs (path defined in `production.yaml`). You can also set another password with:
  192. ```bash
  193. cd /var/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root
  194. ```
  195. Alternatively you can set the environment variable `PT_INITIAL_ROOT_PASSWORD`,
  196. to your own administrator password, although it must be 6 characters or more.
  197. ### :tada: What now?
  198. Now your instance is up you can:
  199. * Add your instance to the public PeerTube instances index if you want to: https://instances.joinpeertube.org/
  200. * Check [available CLI tools](/support/doc/tools.md)
  201. ## Upgrade
  202. ### PeerTube instance
  203. **Check the changelog (in particular the *IMPORTANT NOTES* section):** https://github.com/Chocobozzz/PeerTube/blob/develop/CHANGELOG.md
  204. Run the upgrade script (the password it asks is PeerTube's database user password):
  205. ```bash
  206. cd /var/www/peertube/peertube-latest/scripts && sudo -H -u peertube ./upgrade.sh
  207. sudo systemctl restart peertube # Or use your OS command to restart PeerTube if you don't use systemd
  208. ```
  209. You may want to run `sudo -u peertube yarn cache clean` after several upgrades to free up disk space.
  210. <details>
  211. <summary><strong>Prefer manual upgrade?</strong></summary>
  212. Make a SQL backup
  213. ```bash
  214. SQL_BACKUP_PATH="backup/sql-peertube_prod-$(date -Im).bak" && \
  215. cd /var/www/peertube && sudo -u peertube mkdir -p backup && \
  216. sudo -u postgres pg_dump -F c peertube_prod | sudo -u peertube tee "$SQL_BACKUP_PATH" >/dev/null
  217. ```
  218. Fetch the latest tagged version of Peertube:
  219. ```bash
  220. 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"
  221. ```
  222. Download the new version and unzip it:
  223. ```bash
  224. cd /var/www/peertube/versions && \
  225. sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" && \
  226. sudo -u peertube unzip -o peertube-${VERSION}.zip && \
  227. sudo -u peertube rm peertube-${VERSION}.zip
  228. ```
  229. Install node dependencies:
  230. ```bash
  231. cd /var/www/peertube/versions/peertube-${VERSION} && \
  232. sudo -H -u peertube yarn install --production --pure-lockfile
  233. ```
  234. Copy new configuration defaults values and update your configuration file:
  235. ```bash
  236. sudo -u peertube cp /var/www/peertube/versions/peertube-${VERSION}/config/default.yaml /var/www/peertube/config/default.yaml
  237. diff -u /var/www/peertube/versions/peertube-${VERSION}/config/production.yaml.example /var/www/peertube/config/production.yaml
  238. ```
  239. Change the link to point to the latest version:
  240. ```bash
  241. cd /var/www/peertube && \
  242. sudo unlink ./peertube-latest && \
  243. sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
  244. ```
  245. </details>
  246. ### Update PeerTube configuration
  247. Check for configuration changes, and report them in your `config/production.yaml` file:
  248. ```bash
  249. cd /var/www/peertube/versions
  250. diff -u "$(ls -t | head -2 | tail -1)/config/production.yaml.example" "$(ls -t | head -1)/config/production.yaml.example"
  251. ```
  252. ### Update nginx configuration
  253. Check changes in nginx configuration:
  254. ```bash
  255. cd /var/www/peertube/versions
  256. diff -u "$(ls -t | head -2 | tail -1)/support/nginx/peertube" "$(ls -t | head -1)/support/nginx/peertube"
  257. ```
  258. ### Update systemd service
  259. Check changes in systemd configuration:
  260. ```bash
  261. cd /var/www/peertube/versions
  262. diff -u "$(ls -t | head -2 | tail -1)/support/systemd/peertube.service" "$(ls -t | head -1)/support/systemd/peertube.service"
  263. ```
  264. ### Restart PeerTube
  265. If you changed your nginx configuration:
  266. ```bash
  267. sudo systemctl reload nginx
  268. ```
  269. If you changed your systemd configuration:
  270. ```bash
  271. sudo systemctl daemon-reload
  272. ```
  273. Restart PeerTube and check the logs:
  274. ```bash
  275. sudo systemctl restart peertube && sudo journalctl -fu peertube
  276. ```
  277. ### Things went wrong?
  278. Change `peertube-latest` destination to the previous version and restore your SQL backup:
  279. ```bash
  280. OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \
  281. cd /var/www/peertube && sudo -u peertube unlink ./peertube-latest && \
  282. sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \
  283. sudo -u postgres pg_restore -c -C -d postgres "$SQL_BACKUP_PATH" && \
  284. sudo systemctl restart peertube
  285. ```