惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
AWS News Blog
AWS News Blog
V
Vulnerabilities – Threatpost
D
Darknet – Hacking Tools, Hacker News & Cyber Security
量子位
博客园 - 叶小钗
AI
AI
T
Tor Project blog
Forbes - Security
Forbes - Security
W
WeLiveSecurity
博客园_首页
爱范儿
爱范儿
J
Java Code Geeks
B
Blog
G
GRAHAM CLULEY
aimingoo的专栏
aimingoo的专栏
Cloudbric
Cloudbric
C
CXSECURITY Database RSS Feed - CXSecurity.com
TaoSecurity Blog
TaoSecurity Blog
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
有赞技术团队
有赞技术团队
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
H
Help Net Security
博客园 - 三生石上(FineUI控件)
C
Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Palo Alto Networks Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园 - 司徒正美
The Last Watchdog
The Last Watchdog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
S
Secure Thoughts
Spread Privacy
Spread Privacy
F
Fortinet All Blogs
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
Security Latest
Security Latest
Webroot Blog
Webroot Blog
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog

Dejavu's Blog

甲骨文 ARM 实例部署 Gemma 4 模型 Headscale + Tailscale 组建虚拟专用网 在 Linux 上使用 Yubikey OpenPGP 应用 BuyVM VPS 块存储挂载教程 Alpine Linux 服务器配置指南 Alpine Linux 安装 Cloudflared Docker 多容器共享中心数据库 安装 Komari 服务器监控工具 Scaleway VPS 安装 Debian Linux Debian 13 下部署 AsmBB 论坛 使用 Kopia 自动化备份服务器数据 给 Docker 启用 IPv6 支持 Netcup 服务器安装自定义 ISO 镜像 烽火 HG5582A 光猫开启桥接模式 Docker 自托管 Shlink 短链服务 部署 Obsidian LiveSync 实时同步服务指南 我的 2025 年不完全回顾 Linux 下 Intel 核显驱动配置与硬件加速 Fedora Linux 安装配置记录 2025 年优雅地自托管 RSS 服务 Woodpecker CI 和 Gitea 实现 Hugo 自动部署 Gitea/Forgejo 集成 Woodpecker CI/CD 在 Blinko 中使用 Ollama 作为 AI 供应商 Docker 部署 Gitea/Forgejo Plausible CE 启用城市级地理位置识别 Blinko 开源 AI 知识库 Docker 部署指南 Netcup 免税账号注册及购买服务器全记录 Docker 自托管 Cloudreve Pro 私有网盘服务 GiffGaff SIM 卡使用体验和注意事项 简体中文互联网在变得糟糕吗? 如何低成本申请 S/MIME 证书用于个人邮件服务 迁移到 NameCrane Mail 域名邮箱套件服务 香烟与咖啡 在 Windows 中使用 Yubikey 的 OpenPGP 应用 Windows 11 IoT LTSC 养老指南 巧用浏览器生成 HAR 文件批量下载所需网页资源 聊聊静态网站的评论系统 在 Hugo 站点中优雅地展示实况照片 使用 snac 部署一个简洁优雅的 ActivityPub 实例 当 25 岁来临的时候 断网的这两年 从 Bitwarden/Vaultwarden 到 KeePassXC 也许是 Android 上最好的本地播放器 - 椒盐音乐 2023 半年小结 写一个好玩的 Hugo 货币汇率转换短代码 写一个 Hugo 短代码将不同类别的总字数统计转换为书名显示 海信 Touch Lite 墨水屏音乐阅读器的简单体验 从 Debian 11(bullseye) 无感升级到 Debian 12(bookworm) 使用 GitHub Actions 自动提交 URL 到 IndexNow 批量重写 Git 历史提交记录 使用 cgit 托管小小的也很可爱的 Git 服务器 在 Debian 上使用 stagit 和 Nginx 的简单 Git 服务器 托管简单 Git 服务器的一些尝试 使用 stagit 自托管纯静态 Git 存储库 使用 Docker 快速部署单人 Fediverse 实例 我是如何建立自己的个人博客的? 简单、隐私友好的谷歌分析替代品,Plausible 自托管部署指南 服务器使用 Cloudflare CDN 的最佳实践 甲骨文服务器分配并启用 IPv6 地址 Git 版本控制学习笔记(二) Cloudflare WAF 防护策略简易指南 Mastodon 服务器批量导入自定义表情 低成本自托管 Mastodon 实例简明指南 自托管服务指南──有了服务器可以做什么? 使用 Miniflux + RSSHub 打造个人 RSS 阅读器 构建支持多种 CPU 架构的 Docker 镜像 一个可自托管的静态短链接应用 别了,二〇二二! Duplicacy CLI 进阶使用指南 Duplicacy CLI 备份工具的基本使用 初探 Cloudflare 零信任 - 通过 Docker 部署 Bitwarden 密码管理器 Yubikey 转运日志及上手指南 初探 Cloudflare 零信任 — 通过 Cloudflare Tunnel 搭建 SSH 聊天室 初探 Cloudflare 零信任 - 通过 Cloudflare Tunnel 访问服务 某科学的 PGP 算号指南 2022 年的 MacBook Air M1 使用体验及应用推荐 使用 Vercel 和 Supabase 自托管 Cusdis 评论系统 为什么你的搜索引擎不好用? 个人在 Windows 上常用软件清单 macOS 基础开发环境设置指南 在 macOS 上使用 Canokey 的 OpenPGP 应用 提取 Windows UWP 应用商店的安装包以供离线安装 Git 版本控制学习笔记(一) 使用 Notion 管理 GitHub Star 项目 使用 Vercel 免费部署 Giscus 评论系统 将博客评论从 Utterances 无缝迁移到 Giscus Canokey 签名和认证应用指南 Canokey 的基本使用指南 Canokey Pigeon 揽件日志及简单开箱 关于 Google Play 保护机制和 DRM 安全等级的那些事 记录一次捡垃圾装机 GitHub 使用 GPG 密钥提交签名认证 使用 Scoop 管理 Windows 下的软件和开发环境 Windows Terminal+PowerShell 7 打造 Windows 下最好用的终端 一个好用的 Telegram 文件批量上传/下载工具 Clash for Windows 优雅地使用 TUN 模式接管系统流量 全平台搭建 Hexo 静态博客指南 尝试将 Manjaro 作为主力操作系统使用 Hexo 进行 SEO 优化的基本指南 使用本地代理给 Git 和 NPM 加速
NodeBB 论坛部署教程
Dejavu Moe · 2026-04-14 · via Dejavu's Blog

前言

NodeBB 是一款拥有 10 多年历史的开源论坛应用,拥有出色的运行性能与流畅的交互体验,是搭建小型社区的理想方案。

硬件需求

  • 最低配置:1 vCPU、512MB RAM
  • 推荐配置:2 vCPU、4GB RAM 以上

本文使用 Netcup VPS 500 (4vCPU/4GB RAM),基于 Debian GNU/Linux 13 进行演示。

环境准备

1.内核参数调优

cat <<EOF | sudo tee /etc/sysctl.d/99-nodebb.conf
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_tw_reuse = 1
fs.file-max = 1000000
EOF

使内核配置立即生效:

2.禁用透明大页(THP)

NodeBB 使用 MongoDB 数据库时,官方建议禁用 Transparent Huge Pages (THP),以避免高并发压力下内存碎片化及严重的锁竞争问题。

创建一个 systemd 服务以实现持久化配置:

cat <<EOF | sudo tee /etc/systemd/system/disable-thp.service
[Unit]
Description=Disable Transparent Huge Pages (THP)
DefaultDependencies=no
After=sysinit.target local-fs.target
Before=mongod.service

[Service]
Type=oneshot
ExecStart=/bin/sh -c 'echo never | tee /sys/kernel/mm/transparent_hugepage/enabled > /dev/null'
ExecStart=/bin/sh -c 'echo never | tee /sys/kernel/mm/transparent_hugepage/defrag > /dev/null'

[Install]
WantedBy=basic.target
EOF

设置开机自启:

sudo systemctl daemon-reload \
  && sudo systemctl enable --now disable-thp.service \
  && sudo systemctl status disable-thp.service

3.调整 Swap 优先级

降低系统使用 Swap 交换分区的倾向,尽可能优先使用物理内存:

echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

4.安装基础构建依赖

sudo apt update \
  && sudo apt install -y ca-certificates \
  git \
  curl \
  gnupg \
  git \
  build-essential

5.安装 Node.js

使用 Nodesource 存储库安装 Nodejs 指定版本:

sudo mkdir -p /etc/apt/keyrings
# 导入 GPG 密钥
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
# 添加软件源
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list \
# 安装 Nodejs
sudo apt update && sudo apt install -y nodejs

6.安装与配置 MongoDB

curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \
   --dearmor
# 添加软件源
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
# 安装 MongoDB 8.0
sudo apt update && sudo apt install -y mongodb-org

在生产环境中,建议锁定数据库版本,避免意外升级导致的兼容性问题:

echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-database hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-mongosh hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
# 或者使用 apt-mark hold(只需要这一条)
sudo apt-mark hold mongodb-org mongodb-org-database mongodb-org-server mongodb-mongosh mongodb-org-mongos mongodb-org-tools

检查安装:

启动 MongoDB 服务:

sudo systemctl enable --now mongod
sudo systemctl status mongod

7.数据库初始化

进入 MongoDB Shell:

创建管理员账号:

use admin
/* 替换为一个强大的密码 */
db.createUser( { user: "admin", pwd: "<strongPassWord>", roles: [ { role: "root", db: "admin" } ] } )

为 NodeBB 创建专用数据库及用户:

赋予 readWrite 权限用于日常数据存取,clusterMonitor 权限以便在 NodeBB 管理后台(ACP)查看数据库统计信息。

use nodebb 
/* 替换为一个强大的密码 */
db.createUser( { user: "nodebb", pwd: "<strongPassWord>", roles: [ { role: "readWrite", db: "nodebb" }, { role: "clusterMonitor", db: "admin" } ] } )
/* OK 后退出 MongoDB Shell */
quit()

修改 MongoDB 配置文件 /etc/mongod.conf 启用鉴权:

security:
  authorization: enabled

重启 MongoDB 使新配置生效:

sudo systemctl restart mongod

准备专用用户

准备一个专门的 nodebb 用户,并配置合理的权限:

# NodeBB 工作目录
sudo mkdir -p /opt/nodebb
sudo adduser --system --group --home /opt/nodebb --shell /bin/bash nodebb
sudo chown -R nodebb:nodebb /opt/nodebb

从源码安装

# 切换到 nodebb 用户
sudo su - nodebb
# 确保在 /opt/nodebb 目录下
cd /opt/nodebb
# 拉取最新的 v4.x 稳定版分支
git clone -b v4.x https://github.com/NodeBB/NodeBB.git .
# 启动安装向导
./nodebb setup

启动后等待 node 模块安装完成:

Dependencies outdated or not yet installed.
Installing them now...

完成后会进入配置向导:

2026-03-08T12:20:08.655Z [8304] - info: NodeBB Setup Triggered via Command Line

Welcome to NodeBB v4.9.1!

This looks like a new installation, so you'll have to answer a few questions about your environment before we can proceed.
Press enter to accept the default setting (shown in brackets).
# 输入你打算访问 NodeBB 的完整 URL(不带末尾斜杠)
URL used to access this NodeBB (http://localhost:4567) https://bbs.your.domain
# 随机机密
Please enter a NodeBB secret (<一串随机 uuid>)
# 是否提交匿名插件统计信息
Would you like to submit anonymous plugin usage to nbbpm? (yes) no
# 使用什么数据库?
Which database to use (mongo)
2026-03-08T12:21:10.690Z [8304] - info:
Now configuring mongo database:
MongoDB connection URI: (leave blank if you wish to specify host, port, username/password and database individually)
Format: mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
# 数据库主机名
Host IP or address of your MongoDB instance (127.0.0.1)
# 数据库端口,MongoDB 默认 27017
Host port of your MongoDB instance (27017)
# 数据库用户名
MongoDB username nodebb
# 数据库密码
Password of your MongoDB database
# 数据库名称
MongoDB database name (nodebb) nodebb
Configuration Saved OK
Populating database with default configs, if not already set...
Enabling default theme: nodebb-theme-harmony
No categories found, populating instance with default categories
2026-03-08T12:23:01.264Z [8304] - warn: No administrators have been detected, running initial user setup
# 管理员用户名
Administrator username dejavu
# 管理员邮箱
Administrator email address [email protected]
# 管理员密码
Password
Confirm Password
Schema update complete!
NodeBB Setup Completed. Run "./nodebb start" to manually start your NodeBB server.

初始安装完成,在 NodeBB 服务启动前,修改服务监听地址:

sudo vim /opt/nodebb/config.json
# 监听地址修改为 127.0.0.1
{
    "url": "https://bbs.zsh.moe",
    "secret": "uuid",
    "database": "mongo",
    "port": 4567,
    "bind_address": "127.0.0.1",
    "mongo": {
        "host": "127.0.0.1",
        "port": "27017",
        "username": "nodebb",
        "password": "",
        "database": "nodebb",
        "uri": ""
    }
}

配置 Systemd 守护进程

cat <<EOF | sudo tee /etc/systemd/system/nodebb.service
[Unit]
Description=NodeBB Forum Daemon
Documentation=https://docs.nodebb.org
After=system.slice multi-user.target mongod.service

[Service]
Type=forking
User=nodebb
Group=nodebb
WorkingDirectory=/opt/nodebb
PIDFile=/opt/nodebb/pidfile
ExecStart=/usr/bin/env node /opt/nodebb/loader.js --no-silent
ExecStop=/usr/bin/env node /opt/nodebb/nodebb stop
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF

启动 NodeBB 服务:

sudo systemctl daemon-reload \
  && sudo systemctl enable --now nodebb.service \
  && sudo systemctl status nodebb.service
# 检查运行日志
sudo journalctl -u nodebb -f

Nginx 反向代理

下面是一个适用于 NodeBB 的示例虚拟主机配置:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 80;
    listen [::]:80;
    server_name bbs.your.domain;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;
    server_name bbs.your.domain;

    ssl_certificate /etc/nginx/cert/bbs.your.domain.pem;
    ssl_certificate_key /etc/nginx/cert/bbs.your.domain.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ecdh_curve X25519:P-256:P-384;
    ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:ECDHE+AES128:RSA+AES128:ECDHE+AES256:RSA+AES256';
    ssl_prefer_server_ciphers off;
    ssl_session_timeout 1d;
    ssl_session_cache shared:MozSSL:10m;

    access_log /var/log/nginx/bbs.your.domain.access.log;
    error_log /var/log/nginx/bbs.your.domain.error.log;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-XSS-Protection "1; mode=block" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "no-referrer-when-downgrade" always;
    add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline' 'unsafe-eval' " always;

    client_max_body_size 100M;

    location / {
        proxy_pass http://127.0.0.1:27017;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_redirect off;

        proxy_set_header Host $host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

重载 Nginx 配置:

sudo nginx -t && sudo nginx -s reload

升级 NodeBB

后续日常维护需要进行版本升级,下面以 v4.9.1 升级到 v4.9.2 为例。

在进行任何升级操作前,务必备份好数据:

# 停止 NodeBB 服务
sudo systemctl stop nodebb.service
# 备份数据库
mongodump --db=nodebb --archive=nodebb_backup_v4.9.1.gz --gzip
# 备份配置和附件
sudo tar -czvf nodebb_files_backup_v4.9.1.tar.gz -C /opt/nodebb config.json public/uploads
# 切换到 nodebb 用户
sudo su - nodebb
# 进入工作目录
cd /opt/nodebb
# 获取远程仓库的最新变更
git fetch
# 合并最新代码
git checkout v4.x
git merge origin/v4.x
# 开始升级
./nodebb upgrade

升级完成后重新启动服务:

# 退出 nodebb 用户
exit
# 启动服务
sudo systemctl start nodebb.service
# 检查实时日志,确定运行正常
sudo journalctl -u nodebb -f