宝塔面板部署 DJM CMS:Nginx、数据库与进程守护
从新建数据库到宝塔 Go 项目守护,完整走一遍生产部署。
这篇教程按“数据库 → 程序目录 → 配置 → 守护 → 反向代理”的顺序完成生产部署。示例使用独立目录 /www/wwwroot/cms.example.com 和端口 23280。
1. 准备数据库
在宝塔或云数据库控制台创建 utf8mb4 数据库与独立账号,记录主机、库名、用户名和密码。生产环境不建议直接使用 root 账号。
2. 解压发布包
mkdir -p /www/wwwroot/cms.example.com/releases
cd /tmp
unzip djm-cms_1.0.153_linux_amd64_update.zip
mv releases/1.0.153 /www/wwwroot/cms.example.com/releases/
cd /www/wwwroot/cms.example.com
ln -s releases/1.0.153 current
mkdir -p shared/configs shared/storage shared/logs shared/plugins shared/themes
ln -s shared/configs configs
ln -s shared/storage storage
ln -s shared/plugins plugins
ln -s shared/themes themes
cp -a releases/1.0.153/themes/. shared/themes/
3. 写入配置
server:
addr: "127.0.0.1:23280"
admin_path: /manage-xxxxxxxx
database:
host: 数据库地址
port: 3306
name: djm_cms_web
prefix: djm_
user: 数据库用户
password: ""
再创建 shared/configs/runtime.env:
export DJM_CONFIG=/www/wwwroot/cms.example.com/shared/configs/app.yaml
export DJM_DB_PASSWORD=真实数据库密码
注意:auth.identity_hash_key 请使用 Base64 编码的 32 字节随机值。配置文档允许 32–64 字节,但插件宿主只接受 32 字节,超出会在启动时报 invalid plugin secret key。
4. 执行安装并设置权限
chown -R www:www /www/wwwroot/cms.example.com
chmod 600 shared/configs/app.yaml shared/configs/runtime.env
su -s /bin/bash www -c 'cd /www/wwwroot/cms.example.com && \
source shared/configs/runtime.env && \
./current/bin/cms install -site-name "DJM CMS" \
-site-domain cms.example.com -admin-path /manage-xxxxxxxx \
-admin-user admin -admin-password-file /tmp/admin-password.txt'
5. 用宝塔 Go 项目守护
在宝塔「网站 → Go 项目」新增项目:
- 项目名称:
djmcms - 项目执行文件:
/www/wwwroot/cms.example.com/djm-cms(稳定启动器) - 执行命令:
/www/wwwroot/cms.example.com/djm-cms serve - 项目端口:
23280,运行用户www,环境变量文件指向runtime.env - 开机启动:开启
不要绕过宝塔进程管理器手动 nohup 启动,否则会出现游离进程占用端口、面板显示异常的问题。
6. 验证
curl -fsS http://127.0.0.1:23280/health/live
curl -fsS http://127.0.0.1:23280/health/ready
ss -lntp | grep 23280
最后把域名解析到服务器,按下一篇教程配置反向代理与 HTTPS。
讨论
发表评论