云网牛站
所在位置:首页 > Linux云服务器 > 在Ubuntu 18.04/16.04上安装nodeBB Forum Software的方法

在Ubuntu 18.04/16.04上安装nodeBB Forum Software的方法

2019-02-23 21:31:40作者:叶云稿源:云网牛站

本文介绍在Ubuntu 18.04/16.04系统上安装nodeBB Forum Software的方法,设置NodeBB时可以选择Redis或MongoDB数据库,同时安装还需要Node.js。

 

一、安装Node.js

Node.js是一个快速发展的平台,它驱动NodeBB,在Ubuntu和Debian系统上,你可以从NodeSource存储库安装Node.js:

$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

$ sudo apt-get install gcc g++ make

$ sudo apt-get install -y nodejs

你应该在npm安装版本8的Node.js,验证版本使用:

$ node -v

v8.11.3

$ npm -v

5.6.0

参考:在Ubuntu 18.04系统中安装Node.js 10的方法

 

二、在Ubuntu 18.04上安装MongoDB数据库

MongoDB是NodeBB的默认数据库,通过导入包管理系统使用的公钥来启动安装:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

添加MongoDB存储库:

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list

更新apt包索引并安装MongoDB服务器:

$ sudo apt-get update

$ sudo apt-get install -y mongodb-org

启动MongoDB服务:

$ systemctl start mongod.service

$ systemctl enable mongod.service

验证MongoDB的安装,应该有3.6版本:

$ mongod --version

db version v3.6.5

git version: a20ecd3e3a174162052ff99913bc2ca9a839d618

OpenSSL version: OpenSSL 1.0.2n

allocator: tcmalloc

modules: none

build environment:

distmod: ubuntu1604

distarch: x86_64

target_arch: x86_64

 

三、配置MongoDB

MongoDB附带一个用于一般管理的Shell mongo,MongoDB的默认安装侦听端口27017,可在本地访问,使用以下方法访问shell:

$ mongo

上传到admin内置数据库:

> use admin

switched to db admin

创建管理用户:

> db.createUser( { user: "admin", pwd: "adminpassword", roles: [ { role: "readWriteAnyDatabase", db: "admin" }, { role: "userAdminAnyDatabase", db: "admin" } ] } )

一旦启用授权,此用户的范围限定为databaseadmin以管理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" } ] } )

permissionreadWrite允许NodeBB存储和检索来自databasenodebb的数据。

permissionclusterMonitor为查询数据库服务器统计信息提供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

>

 

四、在Ubuntu 18.04上安装NodeBB

确保安装了git,运行:

$ sudo apt-get install -y git

Clone NodeBB的稳定分支,比如将NodeBB存储库从v1.9.x分支克隆到目录nodebb,当然也可以安装v1.11.1等版本:

$ git clone -b v1.9.x 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有一个用于设置NodeBB的命令行实用程序,我们将使用它来设置NodeBB,这将从npm安装模块,然后进入设置实用程序:

$ ./nodebb setup

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>

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]]<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) 

info: [database] Checking database indices.

info: [database] Checking database indices done!

Configuration Saved OK

Populating database with default configs, if not already set...

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

warn: No administrators have been detected, running initial user setup

Administrator username admin

Administrator email address admin@domain.com

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

 

五、安装和配置Nginx

NodeBB默认在端口4567上运行,我们将配置Nginx来代理对它的请求。

安装nginx:

$ sudo apt-get install nginx

参考:在Ubuntu 18.04 Server中安装LEMP的方法[Nginx、MariaDB、PHP7.2]

配置nginx,创建nginx配置文件:

$ sudo vim /etc/nginx/conf.d/nodebb.conf

然后添加内容:

server {

listen 80;

server_name forum.example.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

 

六、访问NodeBB Web界面

到目前为止,你应该已经在Ubuntu 18.04/16.04服务器上成功安装了NodeBB,你应该能够访问http://forum.example.com并与你的论坛进行互动:

在Ubuntu 18.04/16.04上安装nodeBB Forum Software的方法

要访问管理信息中心,请改用http://forum.example.com/admin:

在Ubuntu 18.04/16.04上安装nodeBB Forum Software的方法

在Ubuntu 18.04/16.04上安装nodeBB Forum Software的方法

 

相关主题

为什么现在的Linux论坛交流的人少了

精选文章
热门文章