如何在Ubuntu 18.04/16.04上安装nodebb
在本教程中,我们将学习在Ubuntu 18.04/16.04上安装NodeBB。
NodeBB是在Node.js中编写的免费且开源论坛软件,并利用Web Sockets进行即时交互和实时通知。
NodeBB可以集成到或者社交媒体中,以使客户更新和订阅。
设置nodeBB时,可以从redis或者mongodb数据库中进行选择。
NodeBB的一些很好的功能是:社交网络集成和流式传输与大多数浏览器一起讨论,包括旧的浏览器。
内置本地化,支持超过50个语音分析仪表板,具有内容视图的实时数据
第1步:安装Node.js
node.js是一个快速不断变化的平台,它驱动NodeBB。
在Ubuntu和Debian Systems上,我们可以从nodesource存储库中安装Node.js:
sudo apt update curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash sudo apt-get -y install gcc g++ make nodejs
我们应该有与NPM一起安装的Node.js的版本8.
验证版本使用:
$node -v v10.17.0 $npm -v 6.11.3
第2步:在Ubuntu 18.04上安装MongoDB数据库
MongoDB是NodeBB的默认数据库。
使用下面的教程安装MongoDB
在Ubuntu上安装MongoDB
验证MongoDB的安装。
你应该有3.6版:
$mongod --version db version v4.2.1 git version: edf6d45851c0b9ee15548f0f847df141764a317e OpenSSL version: OpenSSL 1.1.1 11 Sep 2016 allocator: tcmalloc modules: none build environment: distmod: ubuntu1804 distarch: x86_64 target_arch: x86_64
第3步:配置MongoDB
MongoDB配有一个用于一般管理的shell 蒙古。
MongoDB默认安装MongoDB在端口27017上侦听,可在本地访问。
使用:使用:
$mongo
升级到管理员内置数据库:
> use admin switched to db admin
创建一个管理用户:
> db.createUser( { user: "admin", pwd: "adminpassword", roles: [ { role: "readWriteAnyDatabase", db: "admin" }, { role: "userAdminAnyDatabase", db: "admin" } ] } )
此用户将被选为数据库 admin
启用授权后管理MongoDB。
用所需的管理员密码替换adminpassword。
添加一个名为新数据库 nodebb
:
> use nodebb switched to db nodebb
接下来,创建 nodebb
用户具有适当权限:
> db.createUser( { user: "nodebb", pwd: "password", roles: [ { role: "readWrite", db: "nodebb" }, { role: "clusterMonitor", db: "admin" } ] } )
许可 readWrite
允许NodeBB从数据库存储和检索数据 nodebb
。
许可 clusterMonitor
提供NodeBB只读访问权限,然后在NodeBB管理控制面板(ACP)中公开。
最后,退出Mongo Shell:
> quit()
通过添加以下行启用MongoDB配置文件/etc/mongod.conf中的数据库授权:
security: authorization: enabled
重新启动MongoDB并验证之前创建的管理用户可以连接:
$sudo systemctl restart mongod $mongo -u admin -p adminpassword --authenticationDatabase=admin MongoDB shell version v3.6.5 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.6.5 >
第4步:在Ubuntu 18.04上安装nodeBB
确保安装了Git:
$sudo -y apt-get install git
NodeBB的克隆稳定分支:
$git clone https://github.com/NodeBB/NodeBB.git nodebb Cloning into 'nodebb'... remote: Counting objects: 151894, done. remote: Compressing objects: 100% (19/19), done. remote: Total 151894 (delta 10), reused 16 (delta 8), pack-reused 151867 Receiving objects: 100% (151894/151894), 45.92 MiB | 15.51 MiB/s, done. Resolving deltas: 100% (115325/115325), done. $cd nodebb
NodeBB Branches Github页面中有一个备用分支列表,但只有版本后的分支是稳定的。
nodeBB具有用于设置NodeBB的命令行实用程序。
我们将使用它来设置nodeBB,这将从NPM安装模块,然后输入设置实用程序。
$./nodebb setup 2016-06-21T21:03:34.559Z [3956] - info: NodeBB Setup Triggered via Command Line Welcome to NodeBB v1.9.3! 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). URL used to access this NodeBB (http://localhost:4567) <Enter> Please enter a NodeBB secret (48e1fe7e-a54a-4329-a4d1-448970f4e530) <Enter> Which database to use (mongo) <Enter> 2016-06-21T21:03:38.835Z [3956] - 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:Hyman@theitroad]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]<Enter> Host IP or address of your MongoDB instance (127.0.0.1) <Enter> Host port of your MongoDB instance (27017) <Enter> MongoDB username nodebb Password of your MongoDB database MongoDB database name (nodebb) 2016-06-21T21:04:05.019Z [3956] - info: [database] Checking database indices. 2016-06-21T21:04:05.063Z [3956] - info: [database] Checking database indices done! Configuration Saved OK Populating database with default configs, if not already set... 2016-06-21T21:04:06.670Z [3956] - warn: [cache-buster] could not read cache buster message=ENOENT: no such file or directory, open '/home/jmutai/nodebb/build/cache-buster', stack=Error: ENOENT: no such file or directory, open '/home/jmutai/nodebb/build/cache-buster', errno=-2, code=ENOENT, syscall=open, path=/home/jmutai/nodebb/build/cache-buster Enabling default theme: nodebb-theme-persona No categories found, populating instance with default categories 2016-06-21T21:04:08.001Z [3956] - warn: No administrators have been detected, running initial user setup Administrator username admin Administrator email address Hyman@theitroad Password Confirm Password ...... NodeBB Setup Completed. Run "./nodebb start" to manually start your NodeBB server.
要启动NodeBB,请运行:
$./nodebb start Starting NodeBB "./nodebb stop" to stop the NodeBB server "./nodebb log" to view server output "./nodebb help" for more commands
第5步:安装和配置nginx
默认情况下,NodeBB在端口4567上运行。
我们将NginX配置为对其的代理请求。
安装nginx:
sudo apt -y install nginx
配置nginx.
创建nginx配置文件:
$sudo vim /etc/nginx/conf.d/nodebb.conf
然后添加内容:
server { listen 80; server_name forum.theitroad.com; location/{ 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; 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"; } }
检查服务是否运行:
$ss -tunelp | grep 4567 tcp LISTEN 0 128 0.0.0.0:4567 0.0.0.0:* users:(("node",pid=4068,fd=13)) uid:1000 ino:506425 sk:6 <->
重新启动nginx:
sudo systemctl restart nginx
步骤5:访问NodeBB Web界面
为此,我们应该在Ubuntu 18.04/16.04服务器上成功安装nodeBB。
我们应该能够访问http://forum.example.com并与论坛进行互动。
要访问Admin Dashboard,请使用http://forum.example.com/admin。