PeerTube
Updated 25 February 2022
PeerTube is a distributed video hosting and broadcasting platform. [PeerTube] (https://joinpeertube.org) is an independent, lightweight, scalable alternative to YouTube, Dailymotion and Vimeo. It uses visitor browsers to create a P2P-based distributed network. PeerTube supports the ActivityPub protocol, which allows you to merge isolated servers with video content into a federated network. People visiting it can subscribe to channels and be notified about new videos. This open source application is distributed under the AGPLv3 license.
Preparing a LXC container
We recommend that you install PeerTub in a separate container and configure it according to the manual.
Installing and configuring PostgreSQL
Install and configure PostgreSQL according to the manual. Replace dbtest with your peertube_prod database, and the test user with peertube. Complete the setup process:
psql -U postgres
psql (11.2) Type "help" for help. postgres=# \c peertube_prod postgres=# CREATE EXTENSION pg_trgm; postgres=# CREATE EXTENSION unaccent; postgres=# \q
Installing PeerTube
Install the packages required by PeerTube:
emerge -a app-arch/unzip dev-db/redis media-video/ffmpeg dev-python/nodeenv
Create a peertube user account and protect it with a password:
mkdir -p /var/calculate/www
useradd -m -d /var/calculate/www/peertube -s /bin/bash -p peertube peertube
passwd peertube
Install Node.js in the user directory:
su - peertube
nodeenv --node=14.17.6 .node-14
ln -sfT .node-14 .node-live
source .node-live/bin/activate
npm install -g yarn
echo 'source ~/.node-live/bin/activate' >> ~/.bash_profile
Create the necessary paths, download and extract the latest version of PeerTube:
mkdir config storage versions
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"
wget "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" -P versions
unzip versions/peertube-${VERSION}.zip -d versions
rm versions/peertube-${VERSION}.zip
Install PeerTube:
ln -s versions/peertube-${VERSION} ./peertube-latest
cd ./peertube-latest
yarn install --production --pure-lockfile
cp /var/calculate/www/peertube/peertube-latest/config/default.yaml /var/calculate/www/peertube/config/default.yaml
cp config/production.yaml.example ../../config/production.yaml
PeerTube configuration
Setup PeerTube, replacing peertube.example.org with your site:
# Correspond to your reverse proxy server_name/listen configuration webserver: https: true hostname: 'peertube.example.org' port: 443 # Your database name will be "peertube"+database.suffix database: hostname: 'localhost' port: 5432 suffix: '_prod' username: 'peertube' password: 'secret' pool: max: 5 # SMTP server to send emails smtp: hostname: mail.example.org port: 465 # If you use StartTLS: 587 username: null password: null tls: false # If you use StartTLS: false disable_starttls: false ca_file: null # Used for self signed certificates from_address: 'admin@mail.example.org' # From the project root directory storage: tmp: '/var/calculate/www/peertube/storage/tmp/' # Used to download data (imports etc), store uploaded files before processing... avatars: '/var/calculate/www/peertube/storage/avatars/' videos: '/var/calculate/www/peertube/storage/videos/' streaming_playlists: '/var/calculate/www/peertube/storage/streaming-playlists/' redundancy: '/var/calculate/www/peertube/storage/videos/' logs: '/var/calculate/www/peertube/storage/logs/' previews: '/var/calculate/www/peertube/storage/previews/' thumbnails: '/var/calculate/www/peertube/storage/thumbnails/' torrents: '/var/calculate/www/peertube/storage/torrents/' captions: '/var/calculate/www/peertube/storage/captions/' cache: '/var/calculate/www/peertube/storage/cache/' plugins: '/var/calculate/www/peertube/storage/plugins/' client_overrides: '/var/calculate/www/peertube/storage/client-overrides/' admin: # Used to generate the root user at first startup # And to receive emails from the contact form email: 'support@example.org'
Getting Let's Encrypt certificate
Get a certificate for Nginx on peertube.example.org according to the manual.
Installing and configuring Nginx
Setup and configure your Nginx server, as described in the manual.
Copy the default Nginx configuration file for PeerTube:
cp /var/calculate/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-enabled/peertube.conf
Specify the paths and the server name, peertube.example.org:
server { listen 80; listen [::]:80; server_name peertube.example.org; location /.well-known/acme-challenge/ { default_type "text/plain"; root /var/www/certbot; } location / { return 301 https://$host$request_uri; } } upstream backend { server localhost:9000; } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name peertube.example.org; ssl_certificate /etc/letsencrypt/live/peertube.example.org/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/peertube.example.org/privkey.pem; ... # Bypass PeerTube for performance reasons. Could be removed location ~ ^/client/(.*\.(js|css|woff2|otf|ttf|woff|eot))$ { add_header Cache-Control "public, max-age=31536000, immutable"; alias /var/calculate/www/peertube/peertube-latest/client/dist/$1; } ... # Cache 2 hours add_header Cache-Control "public, max-age=7200"; root /var/calculate/www/peertube/storage; rewrite ^/static/(thumbnails|avatars)/(.*)$ /$1/$2 break; try_files $uri ... # Don't spam access log file with byte range requests access_log off; } root /var/calculate/www/peertube/storage; rewrite ^/static/webseed/(.*)$ /videos/$1 break; rewrite ^/static/redundancy/(.*)$ /redundancy/$1 break; }
Starting PeerTube
Create an OpenRC script for PeerTube:
#!/sbin/openrc-run # Copyright 2019 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 name="PeerTube daemon" description="" pidfile=/run/peertube.pid command_user=peertube output_log=/var/log/peertube.log error_log=/var/log/peertube.log directory=/var/calculate/www/peertube/peertube-latest start_stop_daemon_args="-e NODE_ENV=production -e NODE_CONFIG_DIR=/var/calculate/www/peertube/config -e PATH=/var/calculate/www/peertube/.node-live/lib/node_modules/.bin:/var/calculate/www/peertube/.node-live/bin:\"$PATH\"" command="/var/calculate/www/peertube/.node-live/bin/npm" command_args="start" command_background=true depend() { need nginx postgresql redis } start_pre() { checkpath -f -o peertube -m 0600 /var/log/peertube.log }
Define the privileges:
chmod 0755 /etc/init.d/peertube
Launch the PeerTube daemon:
/etc/init.d/peertube start
Add PeerTube to autostart:
rc-update add peertube
Open peertube.example.org in your Web browser:
Defining the administration password
The administrator password is created automatically. You can find it in the log. To reset the password, run:
su - peertube
cd /var/calculate/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/calculate/www/peertube/config NODE_ENV=production npm run reset-password -- -u root
exit
Updating PeerTube
Node.js update
When updating PeerTube to version 4.1.0, we ensure that Node.js version is at least 14:
su - peertube
node -v
v14.17.6
If the Node.js version is below 14, then install the 14.17.6 version in the new .node-14
environment and make it current:
deactivate_node
nodeenv --node=14.17.6 .node-14
ln -sfT .node-14 .node-live
source .node-live/bin/activate
npm install -g yarn
If you set up PeerTube according to the previous version of the guide, then change the scripts /var/calculate/www/peertube/.bash_profile and /etc/init.d/peertube .node-12 to .node -live.
Source code update
Download and unpack the new version of PeerTube:
su - peertube
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"
wget "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" -P versions
unzip versions/peertube-${VERSION}.zip -d versions
rm versions/peertube-${VERSION}.zip
Install PeerTube:
cd versions/peertube-${VERSION}
yarn install --production --pure-lockfile
Configuration update
Copy the new default configuration file:
cp config/default.yaml /var/calculate/www/peertube/config/default.yaml
Update your production.yml configuration:
mv /var/calculate/www/peertube/config/production.yaml /var/calculate/www/peertube/config/production-old.yaml
cp config/production.yaml.example /var/calculate/www/peertube/config/production.yaml
Check the differences and move your settings to production.yaml:
git diff /var/calculate/www/peertube/config/production{,-old}.yaml
Choosing current version
Update the symlink:
cd
unlink peertube-latest
ln -s versions/peertube-${VERSION} ./peertube-latest
exit
Now restart PeerTube:
/etc/init.d/peertube restart
Update to v2.1.0
To update to version 2.1.0, run the HLS video torrents creation script:
su - peertube
cd /var/calculate/www/peertube/peertube-latest
NODE_CONFIG_DIR=/var/calculate/www/peertube/config NODE_ENV=production node dist/scripts/migrations/peertube-2.1.js
exit
Update to v2.2.0
Connect to the database and make the following request:
psql -U postgres
psql (11.7) Type "help" for help. postgres=# \c peertube_prod You are now connected to database "peertube_prod" as user "postgres". peertube_prod=# select "preferredUsername" from actor where "serverId" is null group by "preferredUsername" having count(*) > 1; preferredUsername ------------------- (0 rows)
If the result of the query is not empty, you need to change preferredUsername for each entry so that it be unique.