如何在阿里云ECS 部署Nodebb
一、准备工作1。购买并设置ECS实例
登录阿里云控制台,选择并购买ECS实例。
选择支持的操作系统(推荐使用Ubuntu 20.04或CentOS 8/9)。
配置安全组规则,确保开放以下端口:
22 (SSH,用于远程连接)
80 (HTTP)
443 (HTTPS,若需要)
自定义端口 (默认NodeBB为4567)
连接到ECS实例
2。使用SSH连接到你的ECS实例,例如
[*]ssh root@<your-ecs-ip>
[*]
复制代码
二、环境配置
更新系统
bash
[*]sudo apt update && sudo apt upgrade -y# Ubuntu
[*]yum update -y # CentOS
复制代码
安装必要的软件
Node.js 和 npm
使用NodeSource安装Node.js LTS版本:
bash
[*]curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -# Ubuntu
[*]sudo apt install -y nodejs # Ubuntu
[*]
[*]curl -fsSL https://rpm.nodesource.com/setup_16.x | bash - # CentOS
[*]yum install -y nodejs # CentOS
复制代码
验证安装:
bash
[*]node -v
[*]npm -v
复制代码
MongoDB 或 Redis
NodeBB需要MongoDB或Redis作为数据库,选择其一安装:
安装MongoDB:
bash
[*]sudo apt install -y mongodb # Ubuntu
[*]sudo systemctl enable mongodb --now # 启用并启动服务
复制代码
安装Redis:
bash
[*]sudo apt install -y redis-server # Ubuntu
[*]sudo systemctl enable redis-server --now
复制代码
验证运行状态:
bash
[*]systemctl status mongodb # MongoDB
[*]systemctl status redis-server # Redis
复制代码
安装其他依赖
git:
bash
[*]sudo apt install -y git # Ubuntu
[*]yum install -y git # CentOS
复制代码
Python 2(NodeBB需要):
bash
[*]sudo apt install -y python2 # Ubuntu
复制代码
三、安装NodeBB
克隆NodeBB源码
bash
[*]git clone -b v2.x https://github.com/NodeBB/NodeBB.git nodebb
[*]cd nodebb
复制代码
安装NodeBB依赖
bash
[*]npm install --production
复制代码
配置NodeBB
启动交互式安装:
bash
[*]./nodebb setup
复制代码
按提示输入以下信息:
数据库类型(MongoDB 或 Redis)
数据库连接信息
网站URL(如 http://<your-ecs-ip>:4567)
其他管理员信息
四、运行NodeBB
启动NodeBB
bash
./nodebb start
验证运行
访问 http://<your-ecs-ip>:4567,你应该可以看到NodeBB的初始界面。
如果需要后台管理界面,访问 http://<your-ecs-ip>:4567/admin。
五、持久化管理和优化
配置服务进程管理器
使用 systemd 管理NodeBB: 创建一个服务文件 /etc/systemd/system/nodebb.service:
bash
[*]
[*]Description=NodeBB
[*]After=network.target
[*]
[*]
[*]Type=simple
[*]User=root
[*]WorkingDirectory=/path/to/nodebb
[*]ExecStart=/usr/bin/node /path/to/nodebb/app.js
[*]Restart=always
[*]
[*]
[*]WantedBy=multi-user.target
复制代码
启用并启动服务:
sudo systemctl enable nodebb
sudo systemctl start nodebb
配置Nginx反向代理
安装Nginx:
bash
sudo apt install -y nginx # Ubuntu
yum install -y nginx # CentOS
配置NodeBB反向代理: 在 /etc/nginx/sites-available/nodebb 中写入:
nginx
server {
listen 80;
server_name <your-domain-or-ip>;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:4567;
}
}
启用配置并重启服务:
bash
sudo ln -s /etc/nginx/sites-available/nodebb /etc/nginx/sites-enabled/
sudo systemctl restart nginx
六、维护与更新
升级NodeBB
bash
./nodebb stop
git pull
./nodebb upgrade
./nodebb start
监控日志
bash
./nodebb log
完成这些步骤后,你的NodeBB论坛应该可以稳定运行了!
页:
[1]