Contents
Preface
A while ago, I wrote an article:Docker series builds a simple video gallery based on wordpress+minio, but I still feel uncomfortable. First, the playback experience is not very good. You can't play it by clicking on the picture directly, you have to click on the text link; second, uploading a video is also quite troublesome, and you have to manually specify the thumbnail. . In short, it feels more and more low! So I thought about it and simply deployed a separate video sharing platform to store videos.
After some research, I chose peertube. PeerTube is an open source, distributed, interconnected video platform, similar to youtube, but decentralized, and uses WebTorrent (the first Torrent client running on the browser) technology to implement a p2p network to reduce the load on a single server. Anyone can build PeerTube on a server and share uploaded videos.
Preparation
The deployment of peertube is a bit complicated. It depends on PostgreSQL (>= 9.6) and Redis (>=2.8.18), so you need to prepare PostgreSQL and Redis first. PostgreSQL needs to be initialized again. This time I will not use the docker compose method, otherwise, will I pull countless PostgreSQL in the future? This time I will use the docker run command for deployment, and it is also for the convenience of future reuse. The initialization file .env has been provided by the official, the link is as follows:Official env fileThis file contains both the initialization information of PostgreSQL and the initial information of peertube. Since I don’t use the docker compose command, I can only translate it into the docker run command myself. The official docker-compose yml file link is as follows:Official yml file, but the above parameter description is not complete, the complete one can be reduced:Official complete custom parameter description, you can download it if you need it.
Creating a bridge
Because a bridge named public-net is used below, it needs to be created in advance:
docker network create public-net
Deploy PostgreSQL
Create a directory:
mkdir -p /docker/postgres/data
Create the postgres container:
docker run --name postgres -d --restart=always --net=public-net \ -p 5432:5432 \ #Map host port 5432 to container port 5432 -e POSTGRES_USER=root \ #Set postgres login username -e POSTGRES_PASSWORD=123456 \ #Set postgres login password -e POSTGRES_DB=peertube \ #Add peertube corresponding library -e PGDATA=/var/lib/postgresql/data/pgdata \ #Specify the subdirectory containing data -v /docker/postgres/data:/var/lib/postgresql/data \ #Specify the actual mount path of the container data directory on the host: postgres:15.4
When using the above commands, please delete the comments after #.
-e PGDATA
Official description: "This optional variable can be used to define an alternative location (such as a subdirectory) for the database files. The default location is /var/lib/postgresql/data. If the data volume used is a file system mount point (such as a GCE persistent disk), or a remote folder that cannot be owned by the postgres user (such as some NFS mounts), or contains folders/files (such as lost+found), Postgres initdb needs to create a subdirectory containing the data within the mount point."
In layman's terms, the -v parameter cannot directly/var/lib/postgresql/data
To map a file, you must first specify a subdirectory under it as the data directory. This got me into trouble. The container couldn't start at first. I spent a lot of time looking at the official parameters before I figured it out.
Deploy redis
Create a directory:
mkdir -p /docker/redis/data
Create a redis container:
docker run --name redis -d --restart=always --net=public-net \ -p 6379:6379 \ # maps the host's port 6379 to the container's port 6379 -v /docker/redis/data:/data # specifies the actual mount path of the container data directory on the host redis
Deploy peertube
Create a directory:
mkdir -p /docker/redis/data
Create peertube:
docker run --name peertube -d --restart=always --net=public-net \ -p 1935:1935 -p 9500:9000 \ #Map the host's port 1935 and port 9500 to the container's port 1935 and port 9000. You can modify it according to your actual situation. Port 1395 is the default port of the rmtp protocol -e PEERTUBE_DB_HOSTNAME=postgres \ #Specify the address of the postgres database -e PEERTUBE_DB_USERNAME=root \ #Specify the login username of the postgres database -e PEERTUBE_DB_PASSWORD=123456 \ #Specify the login username and password of the postgres database -e PEERTUBE_DB_NAME=peertube \ #Specify the library name used by peertube on the postgres database -e PEERTUBE_DB_SSL=false \ #Specify whether to use SSL to connect to the database -e PEERTUBE_DB_PORT=5432 \ #Specify the port used to connect to the database -e PEERTUBE_REDIS_HOSTNAME=redis \ #Specify the redis database address -e PEERTUBE_REDIS_PORT=6379 \ #Specify the port used to connect to the redis database -e PEERTUBE_WEBSERVER_HOSTNAME=video.example.com \ #Specify the domain name used by peertube publishing. This must be determined before the deployment begins. Once specified, it cannot be changed. It is best to use a registered domain name with port 443. If there is no registered cloud host or home broadband, you can only use a non-standard port -e PEERTUBE_WEBSERVER_PORT=55555 \ #Specify the actual port for the client to access peertube, for example, directly access it through the non-standard port of home broadband with a public IP, which is the mapped port on the router (such as 55555 in this article); if you are like me, home broadband is used as the source station and is actually placed on the CDN, then you have to change it to port 443 here -e PEERTUBE_WEBSERVER_HTTPS=true \ #Specify whether to use https for publishing -v /docker/peertube/data:/data \ #Specify the mount point of the container directory in the real path of the host -v /docker/peertube/config:/config \ -v assets:/app/client/dist \ -e PEERTUBE_SECRET=xxxxxxx \ #Find a linux host and run openssl rand -hex 32 in the terminal to get -e PEERTUBE_SMTP_USERNAME=abc \ #Mainly do not add the email suffix. Fill in the other SMTP settings according to the actual information of the email provider you use -e PEERTUBE_SMTP_PASSWORD=xxxxx \ #The authorization code generated by your mail provider, not the email login password -e PEERTUBE_SMTP_HOSTNAME=smtp.163.com \ -e PEERTUBE_SMTP_PORT=25 \ -e [email protected] \ -e PEERTUBE_SMTP_TLS=false \ -e PEERTUBE_SMTP_DISABLE_STARTTLS=false \ -e [email protected] \ #Specify the administrator email address, this is very important -e PEERTUBE_SIGNUP_ENABLED=true \ #Does it support registration of chocobozzz/peertube:v5.2.1-bullseye
(Optional) Use with COS system
I wrote an article earlier:Docker series builds a video COS sharing platform based on minio, which can be used here. Combined with peertube, you can store the uploaded videos directly in the COS system you built. This is a step higher than uploading them directly to peertube. If you are interested, you can try it.
-e PEERTUBE_OBJECT_STORAGE_ENABLED=true # supports object storage COS -e PEERTUBE_OBJECT_STORAGE_ENDPOINT= # object storage URL, only fill in the domain name, the default is https -e PEERTUBE_OBJECT_STORAGE_REGION= # object storage region, fill in if there is, otherwise leave it blank -e PEERTUBE_OBJECT_STORAGE_CREDENTIALS_ACCESS_KEY_ID=xxxx # object storage access-key-id -e PEERTUBE_OBJECT_STORAGE_CREDENTIALS_SECRET_ACCESS_KEY=xxxxx # object storage secret-key -e PEERTUBE_OBJECT_STORAGE_STREAMING_PLAYLISTS_BUCKET_NAME= # streaming object storage bucket name -e PEERTUBE_OBJECT_STORAGE_STREAMING_PLAYLISTS_PREFIX=streaming # Bucket directory for streaming storage. If this bucket is not the same as the storage location for uploaded videos, this can be left blank. -e PEERTUBE_OBJECT_STORAGE_VIDEOS_BUCKET_NAME= # Bucket name for uploaded videos -e PEERTUBE_OBJECT_STORAGE_VIDEOS_PREFIX= # Bucket directory for uploaded videos. If this bucket is not the same as the storage location for streaming, this can be left blank.
If you want to use it with a reverse proxy and enable https, you need to make the corresponding configuration in advance so that you can usehttps://video.example.com:55555
Visit peertube. For detailed configuration of reverse proxy, please refer to my other two articles:Linux panel series configure reverse proxy and use non-443 port for publishingandDocker series uses Docker to build its own reverse proxy based on NPM, remember to modify the parameters in the nginx configurationclient_max_body_size 50m
, the default is 50 MB, the video you upload cannot exceed 50 MB in size, change it to the value you need.
I have to complain. This is the most complicated container deployment I have ever encountered. If docker compose is used for deployment, it will be much simpler because many of the environment variables above have default values. For example, redis. I have been unable to deploy peertube, so I can only go to the official website to find the complete parameters and use the elimination method to find which variable is the problem. That's why I wrote so much. Now I understand why the official does not mention the command to run with docker run. I guess they are too lazy to say it, so they directly provide an env environment file in the yml file for several containers at the same time. It's just because I want to write everything in a txt file, so I have to try it slowly by myself. I guess I am the only one in the whole network who uses docker run to do this.
Since the complete function chain of peertube also requires functions such as websites, SSL certificates, and emails, the official docker-complete.yml also includes webserver, certbot, and postfix containers. However, if you have an existing reverse proxy, certificate, or email, you can directly use the above environment variables instead.
The most difficult environment variable isPEERTUBE_OBJECT_STORAGE_MAX_UPLOAD_PART
and PEERTUBE_TRUST_PROXY=
, the container cannot start as long as these two parameters are added, so I have to not add them. I guess there will be no problem when using docker compose. If you are interested, you can try it.
Although the process is very troublesome, I think that if you just need to set it up and don't care about the technical details, you can just use docker compose; but if you want to gain more technical details, you might as well use the docker run command more often. After all, one advantage of using the docker run command is that you only need one txt file to back up all containers, which is a must-have for lazy people, hahaha.
Configure peertube
Log in
Do not use directlyhttp://host IP:9500
Port access, otherwise an error will occur:
Cannot retrieve OAuth Client credentials: Getting client tokens for host 192.168.10.99:9500 is forbidden. Ensure you have correctly configured PeerTube (config/ directory), in particular the "webserver" section.
The reason for the error is that I have told peertube in the environment variables that it will use video.example.com and port 55555 and https to access, so the correct way to open it is to use
https://video.example.com:55555
Log in.
Get the root password
There are 3 ways to get the root password, here we mainly introduce 2 of them.
1. Get from the host mount path
Use vim to open the following file (you can also open it directly with a text editor if you have a graphical interface):
vim /docker/peertube/data/logs/peertube.log
Simply enter "/root" and press Enter to search for the word root:
The mosaic field in quotation marks after "password": is the root password.
2. Retrieve your password using your email
If the email provider information configured above is correct, you can directly click "I forgot my password" in the red box on the login page:
Enter the administrator email address that you set with the "PEERTUBE_ADMIN_EMAIL" variable when you created the container earlier, and then click reset:
Then you will receive an email from peertube:
Directly click the link in the red box in the above picture, and the following interface will appear:
Enter your new password and click the button in the red box in the above picture to reset your password.
Note: If an error occurs when resetting the password, please add the following code to the reverse proxy configuration:
proxy_set_header X-Forwarded-Protocol https; proxy_redirect http:// https://;
I also encountered similar problems when deploying chevereto, and I solved it in this way. This is still a problem caused by using http on the backend and https on the front end. For specific problem phenomena, please refer to:Docker series solves the problem that chevereto is deployed behind a reverse proxy and works abnormally.
Log in to the system using the root account
After clicking the login button in the upper left corner and logging into the system using the root account (or the administrator's email address) and password, the following interface appears:
Next you can start configuring your peertube.
See also:Docker series builds a private video sharing platform based on peertube (Part 2)