Docker+Discuz X3.2论坛部署记录

最新版的运维脚本见这里:GitHub Gist链接

首先安装Docker

sudo apt install docker docker.io

安装discuz

sudo mkdir -p /opt/discuz-data sudo docker run --restart=always --name discuz -p 80:80 -d -v /opt/discuz-data:/var/www/html/ dockerfiles/centos-lamp 下载discuz安装包后解压,将里面的upload文件夹里面的内容全部复制到/opt/discuz-data 也许需要修改权限 chown www-data:www-data /opt/discuz-data -R chmod 777 -R /opt/discuz-data 修改mysql密码 sudo docker exec -i discuz bash mysql_secure_installation ###直接打开服务器地址即可开始安装###

配置服务器

在图形界面设置静态ip,关闭系统休眠、待机

运维

  • 打开shell:sudo docker exec -i discuz bash
  • 复制文件: sudo docker cp file container:to_path

设置+插件篇

  • 买域名
  • 修改界面、论坛名称、备案号
  • MarkDown插件
  • Tex插件
  • 访问控制:开启手机访问、禁止未注册用户访问

我写的一些自动备份脚本,配合crontab使用,注意提前设置好备份服务器的ssh免密码登陆

#!/usr/bin/python3
import os
import time


backup_len = 1
backup_from = ['/opt/discuz-data/data/']
backup_ssh_user = 'user@host'
backup_ssh_port = '22'
backup_to = '/data/backup/discuz/hourly'
identity_file = '/root/.ssh/id_rsa'

now = time.strftime('%Y-%m-%d_%X', time.localtime(time.time()))

os.system('ssh -p {backup_ssh_port} -i {identity_file} {backup_ssh_user} -T "mkdir -p {backup_to}}/{now}}"'.format(
    identity_file=identity_file,
    backup_ssh_port=backup_ssh_port,
    backup_ssh_user=backup_ssh_user,
    backup_to=backup_to,
    now=now))

for path_i in backup_from:
    os.system("scp -p -P {backup_ssh_port} -i {identity_file} -r {backup_from} {backup_ssh_user}:{backup_to}}/{now}}".format(
        identity_file=identity_file,
        backup_ssh_port=backup_ssh_port,
        backup_from=path_i,
        backup_ssh_user=backup_ssh_user,
        backup_to=backup_to,
        now=now))

pipe = os.popen('ssh -p {backup_ssh_port} -i {identity_file} {backup_ssh_user} -T "ls {backup_to}"'.format(
    identity_file=identity_file,
    backup_ssh_port=backup_ssh_port,
    backup_ssh_user=backup_ssh_user,
    backup_to=backup_to), 'r', -1)
pathes = []
for i in pipe:
    pathes.append(i.strip())

pathes.sort()
if len(pathes) > backup_len:
    for i in pathes[:-backup_len]:
        os.system("ssh -p {backup_ssh_port} -i {identity_file} -T {backup_ssh_user} 'rm -rf {backup_to}}/{now}}'".format(
            backup_ssh_port = backup_ssh_port,
            identity_file=identity_file,
            backup_ssh_user=backup_ssh_user,
            backup_to=backup_to,
            now=i))

又写了一个把文件复制到crontab的脚本

#!/bin/bash
cp $1 /etc/cron.hourly
cp $1 /etc/cron.daily
cp $1 /etc/cron.weekly
cp $1 /etc/cron.monthly
vi /etc/cron.hourly/$1
vi /etc/cron.daily/$1
vi /etc/cron.weekly/$1
vi /etc/cron.monthly/$1
echo /etc/cron.hourly/$1
cat /etc/cron.hourly/$1|grep -E '^backup_to'
echo /etc/cron.daily/$1
cat /etc/cron.daily/$1|grep -E '^backup_to'
echo /etc/cron.weekly/$1
cat /etc/cron.weekly/$1|grep -E '^backup_to'
echo /etc/cron.monthly/$1
cat/etc/cron.monthly/$1|grep -E '^backup_to'



此博客中的热门博文

免费爬墙网站项目(ShadowSocksShare)开发简记

Ubuntu Gnome 酷炫完整指南(一):小工具篇