欢迎光临
我们一直在努力

MediaCMS:功能齐全的开源视频CMS

MediaCMS是一个最近才开源的项目,目前作者还在不断更新和完善功能中。不过就目前而言这款程序的功能已经非常强大了,用来建一个小视频站完全没有问题。

我比较喜欢它的前端,可以说是高仿的Youtube,另外还支持HLS视频流。官方的演示站点:https://demo.mediacms.io/

由于这个项目是用Python+Django开发的,部署起来比较麻烦,官方目前也没有手动部署的文档,只有一个支持Ubuntu的安装脚本。

所以这里我先水一篇用Debian10手动部署的文章,未来官方应该会有Docker支持,到时候用Docker应该会省事很多。

安装所有需要用到的软件包:

apt -y update
apt -y dist-upgrade
apt -y install sudo wget git unzip build-essential 
apt -y install nginx python3-certbot-nginx python3-dev python3-pip python3-venv ffmpeg imagemagick postgresql redis-server

启动并设置nginx/postgresql/redis开机自启:

systemctl enable --now nginx postgresql redis-server

创建一个postgresql用户和数据库:

sudo -u postgres createuser -P mediacms
sudo -u postgres createdb -O mediacms mediacmsdb

拉取项目代码:

cd /opt
git clone https://github.com/mediacms-io/mediacms.git
cd mediacms

创建并启用python虚拟环境:

python3 -m venv mediacms.io
source mediacms.io/bin/activate

安装依赖:

pip install wheel
pip install -r requirements.txt

要支持HLS视频流,这里还需要装一个Bento4:

wget http://zebulon.bok.net/Bento4/binaries/Bento4-SDK-1-6-0-632.x86_64-unknown-linux.zip
unzip Bento4-SDK-1-6-0-632.x86_64-unknown-linux.zip
mkdir /opt/mediacms/media_files/hls

创建两个目录,一个用于存放日志文件,一个用于存放pid文件:

mkdir logs
mkdir pids

编辑默认的配置文件:

nano cms/settings.py

[可选]如果你不想直接改动这个默认的配置文件,可以新建一个local_settings.py来覆盖默认的配置:

nano cms/local_settings.py

这里可以改动的配置很多,我只说一下几个必须要改动的配置:

# 站点名字
PORTAL_NAME = "imlala"

# 时区设置
TIME_ZONE = "Asia/Shanghai"

# 站点域名
FRONTEND_HOST = "http://mediacms.imlala.best"

# 关闭用户注册,防止滥用
USERS_CAN_SELF_REGISTER = False

# 站点密钥,自己设置复杂一点
SECRET_KEY = "3dci5kog8k=5n37$fz)8dft)kg(s5&12)^xa*jv(bk+nv-z&cu"

# Bento4二进制文件的绝对路径
MP4HLS_COMMAND = (
    "/opt/mediacms/Bento4-SDK-1-6-0-632.x86_64-unknown-linux/bin/mp4hls"
)

# 数据库连接信息
DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "mediacmsdb",
        "HOST": "127.0.0.1",
        "PORT": "5432",
        "USER": "mediacms",
        "PASSWORD": "password",
    }
}

更多其他的配置,可以参考这里:

https://github.com/mediacms-io/mediacms/blob/main/docs/Configuration.md

初始化数据库/收集静态文件:

python manage.py migrate
python manage.py loaddata fixtures/encoding_profiles.json
python manage.py loaddata fixtures/categories.json
python manage.py collectstatic --noinput

创建管理员账号:

python manage.py createsuperuser

编辑uwsgi配置文件:

nano /opt/mediacms/uwsgi.ini

改为下面的配置:

[uwsgi]
chdir = /opt/mediacms/
virtualenv = /opt/mediacms/mediacms.io
module = cms.wsgi
uid = www-data
gid = www-data
processes = 2
threads = 2
master = true
socket = 127.0.0.1:9000
workers = 2
vacuum  = true
logto = /opt/mediacms/logs/errorlog.txt
disable-logging = true

给予正确的权限:

chown -R www-data:www-data /opt/mediacms

复制systemd配置文件:

cp deploy/celery_long.service /etc/systemd/system/celery_long.service
cp deploy/celery_short.service /etc/systemd/system/celery_short.service
cp deploy/celery_beat.service /etc/systemd/system/celery_beat.service
cp deploy/mediacms.service /etc/systemd/system/mediacms.service

编辑celery_long.service:

nano /etc/systemd/system/celery_long.service

里面相应的配置改为下面列出的:

Environment=APP_DIR="/opt/mediacms"
Environment=CELERY_BIN="/opt/mediacms/mediacms.io/bin/celery"
Environment=CELERYD_PID_FILE="/opt/mediacms/pids/%n.pid"
Environment=CELERYD_LOG_FILE="/opt/mediacms/logs/%N.log"
Environment=APP_DIR="/opt/mediacms"

编辑celery_short.service:

nano /etc/systemd/system/celery_short.service

里面相应的配置改为下面列出的:

Environment=APP_DIR="/opt/mediacms"
Environment=CELERY_BIN="/opt/mediacms/mediacms.io/bin/celery"
Environment=CELERYD_PID_FILE="/opt/mediacms/pids/%n.pid"
Environment=CELERYD_LOG_FILE="/opt/mediacms/logs/%N.log"
Environment=APP_DIR="/opt/mediacms"

编辑celery_beat.service:

nano /etc/systemd/system/celery_beat.service

里面相应的配置改为下面列出的:

Environment=APP_DIR="/opt/mediacms"
Environment=CELERY_BIN="/opt/mediacms/mediacms.io/bin/celery"
Environment=CELERYD_PID_FILE="/opt/mediacms/pids/beat%n.pid"
Environment=CELERYD_LOG_FILE="/opt/mediacms/logs/beat%N.log"
Environment=APP_DIR="/opt/mediacms"

编辑mediacms.service:

nano /etc/systemd/system/mediacms.service

里面相应的配置改为下面列出的:

ExecStart=/opt/mediacms/mediacms.io/bin/uwsgi --ini /opt/mediacms/uwsgi.ini

启动上面所有的服务并设置开机自启:

systemctl enable --now celery_long celery_short celery_beat mediacms

查看运行状态,确保所有服务都是Active的状态:

systemctl status celery_long celery_short celery_beat mediacms

接下来新建nginx站点配置文件:

nano /etc/nginx/conf.d/mediacms.conf

写入如下配置:

server {
    listen 80 ;
    server_name mediacms.imlala.best; # 换成你的域名
    client_max_body_size 0;
    gzip on;
    access_log /var/log/nginx/mediacms.io.access.log;
    error_log  /var/log/nginx/mediacms.io.error.log warn;

    location /static {
        alias /opt/mediacms/static ;
    }

    location /media/original {
        alias /opt/mediacms/media_files/original;
    }

    location /media {
        alias /opt/mediacms/media_files ;
    }

    location / {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
        include /etc/nginx/uwsgi_params;
        uwsgi_pass 127.0.0.1:9000;
    }
}

使用certbot签发ssl证书:

certbot --nginx

访问你的域名正常的话应该就能看到程序的首页了:

赞(0)
未经允许不得转载:拆东墙 » MediaCMS:功能齐全的开源视频CMS

评论 抢沙发

登录

找回密码

注册