环境:vultr的2GB内存云服务器, debian 8 64位
目的:安装1.5.x版本的nodebb,通过 https://test.anqun.org 访问
过程:
- apt-get update 更新软件库
- apt-get install imagemagick git build-essential 安装相关的软件和编译工具
- curl -sL https://deb.nodesource.com/setup_8.x | bash - 添加新版本nodejs安装源
- apt-get install nodejs 安装nodejs
- apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 准备安装新版本的mongodb
- echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 main" | tee /etc/apt/sources.list.d/mongodb-org-3.4.list 添加新版本的mongodb安装源
- apt-get install -y mongodb-org 安装mongodb
- echo never > /sys/kernel/mm/transparent_hugepage/defrag 设置配置文件,忽略mongodb性能提示信息
- systemctl enable mongod.service 设置mongod随系统自动启动
- service mongod start 启动mongodb
- mongo 连接到mongodb
- use nodebb 创建nodebb数据库
- db.createUser( { user: "nodebb", pwd: "shanghiaaini", roles: [ "readWrite" ] } ) 创建nodebb数据库用户,设置密码为shanghiaaini
- vi /etc/mongod.conf 退出mongodb连接后,编辑配置文件,让mongodb支持密码验证
- 添加 security: authorization: enabled 的内容
- service mongod restart 重启mongodb
- 以普通用户 liujia 登录到系统
- git clone -b v1.5.x https://github.com/NodeBB/NodeBB.git nodebb 下载nodebb文件
- cd nodebb 切换到nodebb目录
- npm install 安装相关的组件
- ./nodebb setup 初始化安装nodebb,填写网站访问地址,数据库连接信息等
vi /lib/systemd/system/nodebb.service 创建nodebb的自启动服务,内容如下(请替换相应的运行用户名和nodebb文件路径):
[Unit]
Description=NodeBB forum for Node.js.
Documentation=http://nodebb.readthedocs.io/en/latest/
After=system.slice multi-user.target
[Service]
Type=simple
User=liujia
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodebb
Environment=NODE_ENV=production
WorkingDirectory=/home/liujia/nodebb
ExecStart=/usr/bin/node loader.js --no-daemon --no-silent
Restart=always
[Install]
WantedBy=multi-user.target
23.systemctl enable nodebb 激活endebb服务
24.apt-get install nginx 安装nginx
25.vi /etc/nginx/sites-enabled/default 编辑nginx默认站点配置文件,增加一个nodebb的站点配置,内容如下(请根据实际情况修改绑定域名和证书路径):
server {
listen 443;
server_name test.anqun.org;
ssl_certificate /root/.acme.sh/test.anqun.org/fullchain.cer;
ssl_certificate_key /root/.acme.sh/test.anqun.org/test.anqun.org.key;
ssl on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 2d;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:4567/;
proxy_redirect off;
# Socket.IO Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
26.systemctl enable nginx 让nginx服务能随系统启动自启动
27.systemctl start nodebb 启动nodebb
28.systemctl start nginx 启动nginx
29.在浏览器访问,nodebb前台和后台显示正常
参考:
- https://www.kancloud.cn/a632079/nodebb-cn/372106
- https://www.kancloud.cn/a632079/nodebb-cn/372108
- https://nodejs.org/en/download/package-manager/
- https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/
- https://docs.nodebb.org/installing/os/debian/