老铁们,是不是被各种“一键安装NodeBB”的教程坑到怀疑人生?今天咱们就站在一个正常人的角度,手把手教你如何在阿里云ECS 2核3G Debian12.6 + 宝塔9.x的环境下,不!用!Docker!把NodeBB撸起来,MongoDB和Redis两种数据库方案一次讲透。踩过的坑、爆过的肝,全都给你标出来,保你少走弯路。
目录
- 环境确认与前置吐槽
- MongoDB安装:宝塔商店版 vs 手工版
- Redis7.4安装:面板点一下就完事?
- 方案A:NodeBB+MongoDB配置全流程
- 方案B:NodeBB+Redis配置全流程
- 给NodeBB写个systemd守护:崩溃自启不背锅
- 高频翻车现场FAQ
1. 环境确认与前置吐槽
先把家底亮一亮:
- 阿里云ECS:2核3G,Debian12.6,北京地域
- 宝塔国际版 9.2.0:已装Nginx 1.26、PHP 8.2(用不上,但懒得卸)
- MySQL 8.0:跑在另一台2核2G轻量上,内网互通,3306端口已开
- 域名:bbs.example.com,已备案并解析
为什么不用Docker?
“Docker确实香,但一想到每次改配置都要重新build镜像,我就想给当初写Dockerfile的自己一个大嘴巴子。”
2. MongoDB安装:宝塔商店版 vs 手工版
宝塔商店里的MongoDB版本停留在4.x,NodeBB官方要求≥5.0,所以只能手动装。
2.1 导入官方源
sudo apt-get install -y gnupg curl
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] \
https://repo.mongodb.org/apt/debian bookworm/mongodb-org/7.0 main" | \
sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt update
2.2 apt一条龙
sudo apt install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod
2.3 创建nodebb库+用户
mongo
use nodebb
db.createUser({
user: "nodebb",
pwd: "Al1yun_NodeBB@2025",
roles: [{ role: "readWrite", db: "nodebb" }]
})
exit
编辑配置文件 /etc/mongod.conf
:
net:
bindIp: 127.0.0.1
security:
authorization: enabled
sudo systemctl restart mongod
3. Redis7.4安装:面板点一下就完事?
宝塔商店已经提供Redis7.4,直接软件商店→Redis→安装→设置密码,完事。
密码建议:Re@NodeBB_2025,别忘了在“性能调整”里把maxmemory设成512mb,省得它吃光内存。
4. 方案A:NodeBB+MongoDB配置全流程
4.1 安装Node.js 20 LTS
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
node -v # v20.16.0
4.2 拉代码
cd /www/wwwroot
git clone -b v3.x https://github.com/NodeBB/NodeBB.git bbs.example.com
cd bbs.example.com
4.3 依赖+编译
npm install --production
./nodebb setup
交互问答示例:
URL used to access this NodeBB (http://bbs.example.com)
Please enter a NodeBB secret (随机32位)
Which database to use (mongo)
Host IP or address of your MongoDB instance (127.0.0.1)
Host port of your MongoDB instance (27017)
MongoDB username (nodebb)
MongoDB password (Al1yun_NodeBB@2025)
MongoDB database name (nodebb)
4.4 Nginx反向代理
宝塔→网站→添加站点→纯静态→域名bbs.example.com→提交。
配置文件(伪静态留空):
location / {
proxy_pass http://127.0.0.1:4567;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
5. 方案B:NodeBB+Redis配置全流程
如果你铁了心要用Redis当主存储,先停MongoDB,再:
./nodebb setup
...
Which database to use (redis)
Host IP or address of your Redis instance (127.0.0.1)
Host port of your Redis instance (6379)
Password of your Redis database (Re@NodeBB_2025)
Redis database number (0)
其余步骤同上。
6. 给NodeBB写个systemd守护:崩溃自启不背锅
sudo tee /etc/systemd/system/nodebb.service > /dev/null <<'EOF'
[Unit]
Description=NodeBB Forum
After=network.target mongod.service redis.service
[Service]
Type=forking
User=www
WorkingDirectory=/www/wwwroot/bbs.example.com
ExecStart=/usr/bin/node loader.js
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now nodebb
7. 高频翻车现场FAQ
- 启动报“illegal instruction”
多半是CPU太老,Node.js 20默认SSE4.2,降级到18.x:
sudo apt install nodejs=18.20.4-1nodesource1
- 上传头像504
Nginx client_max_body_size 设成 10m 即可。 - MongoDB吃内存
在/etc/mongod.conf
加:storage: wiredTiger: engineConfig: cacheSizeGB: 0.5
好了,至此你已经拥有了一个不依赖Docker、MongoDB/Redis双方案、宝塔面板友好的NodeBB论坛。如果还翻车,评论区见,一起吐槽!
没有回复内容