centos7 64安装peertube详细教程

本次实验在centos7 64位系统的基础上进行
1、安装静态编译版ffmpeg

cd /usr/local/
wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-64bit-static.tar.xz
tar -xvf ffmpeg-release-64bit-static.tar.xz
mv ffmpeg-4.0.2-64bit-static ffmpeg
ln -s /usr/local/ffmpeg/ffmpeg /usr/bin/ffmpeg
ln -s /usr/local/ffmpeg/ffprobe /usr/bin/ffprobe
ln -s /usr/local/ffmpeg/qt-faststart /usr/bin/qt-faststart

2、安装nvm及nodejs
更新系统/安装依赖/安装开发工具包:

yum -y update
yum -y install wget git screen libicu-devel
yum -y groupinstall "Development Tools"

3、关闭防火墙:

systemctl stop firewalld.service
systemctl disable firewalld.service

4、关闭SELinux:

vi /etc/selinux/config
SELINUX=disabled
setenforce 0

5、安装nvm,安装完成后关闭你的putty重新登录才能正常使用:

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

6、接着使用nvm安装Node.js:

nvm install v10.17.0
nvm alias default v10.17.0

7、安装Yarn

wget https://github.com/yarnpkg/yarn/releases/download/v1.7.0/yarn-v1.7.0.tar.gz
tar -zxvf yarn-v1.7.0.tar.gz -C /usr/local
mv yarn-v1.7.0 yarn
vi /etc/profile
export PATH=$PATH:/var/local/yarn/bin
source /etc/profile
yarn -v

8、执行安装必须组件

yum update -y
yum install epel-release centos-release-scl -y
yum update -y
yum install -y jemalloc
yum install openssl gcc-c++ make redis git devtoolset-7 -y
scl enable devtoolset-7 bash

8.1 PostgreSQL 9.6安装
1、添加RPM

wget https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
rpm -ivh pgdg-centos96-9.6-3.noarch.rpm
yum install postgresql96 postgresql96-server postgresql96-contrib postgresql96-devel

8.2 安装redis

wget http://www.rpmfind.net/linux/remi/enterprise/7/test/x86_64/redis-5.0.0~RC6-1.el7.remi.x86_64.rpm
rpm -ivh redis-5.0.0~RC6-1.el7.remi.x86_64.rpm

二、设置服务开机启动

# systemctl enable redis

三、服务常用操作

// 服务状态
# systemctl status redis
// 服务启动
# systemctl start redis
// 服务停止
# systemctl stop redis
// 服务重启
# systemctl restart redis

9、更新环境变量

PATH=$PATH:/usr/local/bin:/usr/local/sbin:/usr/pgsql-9.6/bin

下面是重点
10、初始化数据库

/usr/pgsql-9.6/bin/postgresql96-setup initdb

11、启动数据库

systemctl enable postgresql-9.6.service
systemctl start postgresql-9.6.service

12、修改数据库超级账户密码

su - postgres
psql
\password postgres

13、创建网站数据库用户

su - postgres
psql
CREATE USER peertubeuser WITH PASSWORD 'peertube';

14、创建网站数据库

CREATE DATABASE peertube_prod OWNER peertubeuser;

14、将数据库peertube_prod的所有权限都赋予peertubeuser

GRANT ALL PRIVILEGES ON DATABASE peertube_prod to peertubeuser;

15、退出数据库创建界面

\q

16、用超级管理员postgres登录数据库peertube_prod,并创建pg_trgm扩展

psql -U postgres -d peertube_prod -h 127.0.0.1 -p 5432
CREATE EXTENSION pg_trgm;
CREATE EXTENSION unaccent;

17、退出数据库创建界面

\q

18、开启远程访问
18.1、编辑配置文件
文件:postgresql.conf
位置:vi /var/lib/pgsql/9.6/data/postgresql.conf
添加/修改:在所有IP地址上监听,从而允许远程连接到数据库服务器:

listening_address: '*'

18.2文件:pg_hba.conf
位置:/var/lib/pgsql/9.6/data/pg_hba.conf
添加/修改:允许任意用户从任意机器上以密码方式访问数据库,把下行添加为第一条规则:

host    all             all             0.0.0.0/0               md5

18.3、重启数据库服务:

systemctl restart postgresql-9.6.service

18.4、测试数据库账户密码是否正常连接

psql -U peertubeuser -d peertube_prod -h 127.0.0.1 -p 5432

19、下载网站源码

cd /home/wwwroot
wget https://github.com/Chocobozzz/PeerTube/releases/download/v2.0.0/peertube-v2.0.0.tar.xz
tar xvf peertube-v2.0.0.tar.xz
mv peertube-v2.0.0 peertube
cd peertube
mkdir storage
cp config/production.yaml.example config/production.yaml

20、修改网站配置文件production.yaml

webserver:
  https: true
  hostname: 'example.com'
  port: 443

改成你的域名

将这里的数据库用户名和密码改成你刚创建的

database:
  hostname: '127.0.0.1'
  port: 5432
  suffix: '_prod'
  username: 'peertubeuser'
  password: 'peertube'
  pool:
    max: 5

配置smtp发件

smtp:
  hostname: null
  port: 465 # If you use StartTLS: 587
  username: null
  password: null
  tls: true # If you use StartTLS: false
  disable_starttls: false
  ca_file: null # Used for self signed certificates
  from_address: '[email protected]'

配置网站的实际目录

storage:
  avatars: '/www/wwwroot/peertube/storage/avatars/'
  videos: '/www/wwwroot/peertube/storage/videos/'
  logs: '/www/wwwroot/peertube/storage/logs/'
  previews: '/www/wwwroot/peertube/storage/previews/'
  thumbnails: '/www/wwwroot/peertube/storage/thumbnails/'
  torrents: '/www/wwwroot/peertube/storage/torrents/'
  captions: '/www/wwwroot/peertube/storage/captions/'
  cache: '/www/wwwroot/peertube/storage/cache/'

其他配置自行参考注释文件

20、安装组件

yarn install --production --pure-lockfile

21、上一步操作没有报错的话,接下来执行

npm start

不出意外,会运行成功

22、然后ctrl+C退出,接着配置nginx

 # Configure with your resolvers
    # resolver $DNS-IP-1 $DNS-IP-2 valid=300s;
    # resolver_timeout 5s;
 
  	add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
  	add_header X-Content-Type-Options nosniff;
  	add_header X-XSS-Protection "1; mode=block";
  	add_header X-Robots-Tag none;
  
 
  location ~ ^/client/(.*\.(js|css|woff2|otf|ttf|woff|eot))$ {
    add_header Cache-Control "public, max-age=31536000, immutable";
 
    alias  /www/wwwroot/peertube/client/dist/$1;
  }
 
  location ~ ^/static/(thumbnails|avatars)/(.*)$ {
    add_header Cache-Control "public, max-age=31536000, immutable";
 
    alias  /www/wwwroot/peertube/storage/$1/$2;
  }
 
  location / {
    proxy_pass http://localhost:9000;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 
    # Hard limit, PeerTube does not support videos > 4GB
    client_max_body_size 4G;
    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;
  }
 
  # Bypass PeerTube webseed route for better performances
  location /static/webseed {
    # Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client
    limit_rate 800k;
 
    if ($request_method = 'OPTIONS') {
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Max-Age' 1728000;
      add_header 'Content-Type' 'text/plain charset=UTF-8';
      add_header 'Content-Length' 0;
      return 204;
    }
 
    if ($request_method = 'GET') {
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      access_log off;
    }
 
    alias  /www/wwwroot/peertube/storage/videos;
  }
 
  # Websocket tracker
  location /tracker/socket {
    # Peers send a message to the tracker every 15 minutes
    proxy_read_timeout 1200s;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_pass http://localhost:9000;
  }

网站路径改成你的实际路径

修改peertube.service里面的路径

vi /www/wwwroot/peertube/support/systemd/peertube.service
[Unit]
Description=PeerTube daemon
After=network.target postgresql.service redis-server.service

[Service]
Type=simple
Environment=NODE_ENV=production
Environment=NODE_CONFIG_DIR=/var/www/peertube/config
User=peertube
Group=peertube
ExecStart=/usr/bin/npm start
WorkingDirectory=/var/www/peertube/peertube
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=peertube
Restart=always

[Install]
WantedBy=multi-user.target

修改完将其拷贝到系统目录

cp /www/wwwroot/peertube/support/systemd/peertube.service /etc/systemd/system/peertube.service

设置开机启动

systemctl enable peertube.service

启动网站

export NODE_ENV=production
systemctl start peertube.service

现在可以打开你的网站了

最后如果需要修改网站管理员密码,执行以下操作

cd /www/wwwroot/peertube && NODE_CONFIG_DIR=/www/wwwroot/peertube/config NODE_ENV=production npm run reset-password -- -u root

手工!

点赞