Waline 本可以部署在 Vercel 等平台上,但有一天突然就不能用了,本文记录自己部署基于 MongoDB 数据库的 Waline 服务。
背景
- Vercel 不香了之后,自己建 Waline 服务器
- 数据库之所以选择 MongoDB,主要在于安装使用方便,对于网站存取性能更优
自己动手,丰衣足食,数据安全,速度还快,无人可挡!
配置环境
安装 MongoDB
- 参考 MongoDB 安装
创建 MongoDB 用户
- 进入 mongosh
- 切换到新数据库 waline
123 | test> use fooswitched to db foowaline> |
---|
- 创建用户 在数据库 foo 中创建用户 vvd 密码 123456,赋予他在 foo 数据库上的读写权限
1234567 | db.createUser( { user: "vvd", pwd: "123456", roles: [ { role: "readWrite", db: "foo" }] }) |
---|
成功运行命令返回结果:
1 | { ok: 1 } |
---|
- 运行
show users
命令查看结果
1234567891011 | foo> show users[ { _id: 'foo.vvd', userId: UUID("91cab2c3-5fae-42fb-9cd4-3c971ff58e3f"), user: 'vvd', db: 'foo', roles: [ { role: 'readWrite', db: 'foo' } ], mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ] }] |
---|
创建环境变量
- 根据官方文档
- 如果和我一样是本地 MongoDB 的话,我们最主要需要配置:
MONGO_DB
,MONGO_USER
,MONGO_PASSWORD
三个变量 - 修改
~/.bashrc
,按照之前的配置加入上述变量
123 | export MONGO_DB=fooexport MONGO_USER=vvdexport MONGO_PASSWORD=123456 |
---|
至此环境配置完毕
Waline
安装、运行
- 按照官方文档(真的很方便啊)
- 在服务器找一个没人的空地方,运行命令:
12 | npm install @waline/vercelnode node_modules/@waline/vercel/vanilla.js |
---|
- 正常运行返回信息
123456 | waline$ node node_modules/@waline/vercel/vanilla.js[2022-08-31T17:17:30.583] [296133] [INFO] - Server running at http://127.0.0.1:8360[2022-08-31T17:17:30.585] [296133] [INFO] - ThinkJS version: 3.2.14[2022-08-31T17:17:30.586] [296133] [INFO] - Environment: production[2022-08-31T17:17:30.586] [296133] [INFO] - Workers: 1[2022-08-31T17:22:07.683] [296140] [INFO] - |
---|
测试
- 此时可以访问
http://IP:8360
访问 waline 页面:
测试评论
- 此时后台信息输出
1234567891011121314 | [2022-08-31T17:22:25.285] [296140] [DEBUG] - Post Comment Start![2022-08-31T17:22:25.285] [296140] [DEBUG] - Post Comment initial Data: { link: 'www.zywvvd.com', mail: 'zywvvd@mail.ustc.edu.cn', nick: 'VVD', pid: 'undefined', rid: 'undefined', ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36', url: '/', comment: '测试?<img class="wl-emoji" src="//unpkg.com/@waline/emojis@1.0.1/weibo/weibo_joy.png" alt="weibo_joy">', ip: '::ffff:180.171.132.122', insertedAt: '2022-08-31T09:22:25.285Z', user_id: 'undefined'} |
---|
- 说明我们 Waline 配置成功
创建服务后台运行
- 将刚刚成功运行 waline 的文件夹移到
/usr/local/waline
- 在
/lib/systemd/system
文件夹创建waline.service
文件
123456789101112131415 | [Unit]Description = Service for waline backendAfter = network.target[Service]ExecStart = /usr/bin/node node_modules/@waline/vercel/vanilla.jsWorkingDirectory = /usr/local/waline/StandardOutput = inheritStandardError = inheritRestart = alwaysUser = lighthouse[Install]WantedBy=multi-user.target |
---|
- 设置 waline 开机自启动
1 | sudo systemctl enable waline.service |
---|
- 开启 waline 服务
1 | sudo systemctl start waline.service |
---|
- 查看 waline.service 状态
12345678910111213141516 | $ systemctl status waline.service● waline.service - Service for waline backend Loaded: loaded (/lib/systemd/system/waline.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2022-08-31 18:08:29 CST; 9s ago Main PID: 304641 (node) Tasks: 18 (limit: 3988) Memory: 131.8M CGroup: /system.slice/waline.service ├─304641 /usr/bin/node node_modules/@waline/vercel/vanilla.js └─304662 /usr/bin/node /usr/local/waline/node_modules/@waline/vercel/vanilla.jsAug 31 18:08:30 VM-16-11-ubuntu node[304641]: [2022-08-31T18:08:30.082] [304641] [INFO] - Server running at http://127.0.0.1:8360Aug 31 18:08:30 VM-16-11-ubuntu node[304641]: [2022-08-31T18:08:30.085] [304641] [INFO] - ThinkJS version: 3.2.14Aug 31 18:08:30 VM-16-11-ubuntu node[304641]: [2022-08-31T18:08:30.085] [304641] [INFO] - Environment: productionAug 31 18:08:30 VM-16-11-ubuntu node[304641]: [2022-08-31T18:08:30.085] [304641] [INFO] - Workers: 1 |
---|
参考资料
- https://waline.js.org/guide/server/databases.html
- https://www.cnblogs.com/yanzi2020/p/14701428.html
- https://blog.csdn.net/hbtj_1216/article/details/120875957
- https://www.tj520.top/views/articles/back-end/waline-service.html