• 没啥好说,更新慢

从零使用Ubuntu安装NodeBB

NodeBB 每天学 来源:原创 7个月前 (03-08) 745次浏览

跟着我不踩坑,一步步安装好NodeBB!

想要一键安装?

Nodebb最新Centos、Ubuntu一键安装脚本

介绍 Nodebb的安装实在是太折腾了,我当初折腾了好几天才安装完毕,所以想搞个自动安装脚本,也方便以后迁移数据的时候快速部署新的服务器,而且Nodebb迁移数据只需要备份数据库就行了,别的东西都不是很重要。 这个脚本能一键安装Nodebb,什么叫一键?直接帮你一步安装好Nodebb(./nodeb […]

安装环境

我使用的是Vmware虚拟机,Ubuntu镜像是从网易拿的ubuntu-18.04.4-desktop-amd64.iso的。如果你是VPS之类的创建机器的时候用Ubuntu18的镜像就可以了。

如果你的服务器在国内,推荐修改镜像为阿里云的,不然速度会很慢,修改镜像很简单,百度可以搜到。

更新软件

进入机器,首先要更新软件,因为我用的不是root用户,所以指令一般都要加上sudo开头

sudo apt-get update

通过包管理器

然后手动安装好curl,这个不是自带的:

sudo apt-get install curl

使用 Nodejs 的快速配置脚本

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

安装Nodejs

sudo apt-get install -y nodejs

检查Nodejs是否安装成功(可跳过)

zhang@zhang-virtual-machine:~$ node -v
v12.16.1

安装Yarn(可选)

yarn.tar.gz这个文件服务器在国外,下载速度很慢,所以我不做了,只提供文档给的方法。

sudo curl -o- -L https://yarnpkg.com/install.sh | sudo bash
sudo curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
sudo echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
yarn -v

安装mongodb

这一步如果跟着中文文档做可能出现问题,所以直接拿官网的方法来安装:

wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -

如果上面出错了,用下面的方法:

sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -

整好仓库:

sudo echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
zhang@zhang-virtual-machine:~$ sudo apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease                                                                                                                  
Hit:3 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease                                                                                                                
Hit:4 http://mirrors.aliyun.com/ubuntu bionic-security InRelease                                                                                                                 
Ign:5 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 InRelease                                                                               
Get:6 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 Release [3,953 B]
Get:7 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 Release.gpg [801 B]
Get:8 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2/multiverse amd64 Packages [4,077 B]
Get:9 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2/multiverse arm64 Packages [4,063 B]
Hit:10 https://deb.nodesource.com/node_12.x bionic InRelease
Fetched 12.9 kB in 3s (3,826 B/s)
Reading package lists... Done

# 安装mongodb

sudo apt-get install -y mongodb-org

测试下有没有安装好:

zhang@zhang-virtual-machine:~$ sudo systemctl start mongod
zhang@zhang-virtual-machine:~$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-03-08 11:39:41 CST; 6s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 6944 (mongod)
   CGroup: /system.slice/mongod.service
           └─6944 /usr/bin/mongod --config /etc/mongod.conf

3月 08 11:39:41 zhang-virtual-machine systemd[1]: Started MongoDB Database Server.

显示了active,证明安装好了

配置mongo数据库

zhang@zhang-virtual-machine:~$ mongo
MongoDB shell version v4.2.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("75b5824d-ce2a-467c-bfc0-5e5e1e1c4b11") }
MongoDB server version: 4.2.3
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
	http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2020-03-08T11:39:41.415+0800 I  STORAGE  [initandlisten] 
2020-03-08T11:39:41.415+0800 I  STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-03-08T11:39:41.415+0800 I  STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-03-08T11:39:42.530+0800 I  CONTROL  [initandlisten] 
2020-03-08T11:39:42.530+0800 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-03-08T11:39:42.530+0800 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2020-03-08T11:39:42.530+0800 I  CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

> 

首先要创建数据库,数据库名我就用nodebb了:

> use nodebb
switched to db nodebb

创建数据库用户,因为我是本地调式,密码用简单的:

>  db.createUser( { user: "nodebb", pwd: "123456", roles: [ "readWrite" ] } )
Successfully added user: { "user" : "nodebb", "roles" : [ "readWrite" ] }

如果要在NodeBB的管理控制面板(高级→数据库)中查看数据库统计信息,请键入以下命令:

>  db.grantRolesToUser("nodebb",[{ role: "clusterMonitor", db: "admin" }]);

打开数据库的权限认证:

# 安装vim,自带的vi用不来
sudo apt-get install vim  -y

# 别忘记加sudo了,用的不是root用户
sudo vim /etc/mongod.conf

# 改成下面这样
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

# 修改了这里
security:
   authorization: enabled
#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

然后重启mongod:

 sudo systemctl restart mongod

安装NodeBB,最后一步!

安装Git等,输入后会有很长的返回值:

sudo apt install -y git build-essential

然后我去/home目录下克隆nodebb并且创建名为nodebb目录(如果服务器在国内,比如我,那又得等一段时间了):

zhang@zhang-virtual-machine:~$ cd /home
zhang@zhang-virtual-machine:/home$ sudo git clone -b v1.13.x https://github.com/NodeBB/NodeBB.git nodebb
Cloning into 'nodebb'...

然后进入nodebb目录里面,安装nodebb,大部分选项直接回车就可以了,安装好还会提示你输入默认的用户名和密码,用来管理论坛:

zhang@zhang-virtual-machine:/home/nodebb$ sudo ./nodebb setup
2020-03-08T04:01:05.798Z [1974] - info: NodeBB Setup Triggered via Command Line

Welcome to NodeBB v1.13.2!

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) 
Please enter a NodeBB secret (65984807-93cf-4914-8fb5-0e04c2007b90) 
Would you like to submit anonymous plugin usage to nbbpm? (yes) 
Which database to use (mongo) 
2020-03-08T04:01:08.056Z [1974] - 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) 
Host port of your MongoDB instance (27017) 
MongoDB username nodebb
Password of your MongoDB database 
MongoDB database name (nodebb) 
(node:1974) DeprecationWarning: The option `autoReconnect` is incompatible with the unified topology, please read more by visiting http://bit.ly/2D8WfT6
(node:1974) DeprecationWarning: The option `reconnectTries` is incompatible with the unified topology, please read more by visiting http://bit.ly/2D8WfT6
(node:1974) DeprecationWarning: The option `reconnectInterval` is incompatible with the unified topology, please read more by visiting http://bit.ly/2D8WfT6
2020-03-08T04:01:14.409Z [1974] - info: [database] Checking database indices.
2020-03-08T04:01:14.444Z [1974] - info: [database] Checking database indices done!
2020-03-08T04:01:15.504Z [1974] - verbose: [minifier] utilizing a maximum of 0 additional threads
Configuration Saved OK
Populating database with default configs, if not already set...

# 省略一大部分没用的输出

Administrator username admin
Administrator email address 1013370209@qq.com
Password 
Confirm Password 

# 省略一大部分没用的输出

Creating welcome post!

# 省略一大部分没用的输出

Enabling default plugins
2020-03-08T04:01:41.009Z [1974] - info: [install/defaultPlugins] customDefaults
2020-03-08T04:01:41.010Z [1974] - info: [install/enableDefaultPlugins] activating default plugins {"0":"nodebb-plugin-composer-default","1":"nodebb-plugin-markdown","2":"nodebb-plugin-mentions","3":"nodebb-widget-essentials","4":"nodebb-rewards-essentials","5":"nodebb-plugin-soundpack-default","6":"nodebb-plugin-emoji","7":"nodebb-plugin-emoji-android"}

Parsing upgrade scripts... 
# 省略一大部分没用的输出
Schema update complete!


# 省略一大部分没用的输出
     ====================================================================================================

NodeBB Setup Completed. Run "./nodebb start" to manually start your NodeBB server.

安装完成

最后启动论坛,看看效果

zhang@zhang-virtual-machine:/home/nodebb$ sudo ./nodebb start

Starting NodeBB
  "./nodebb stop" to stop the NodeBB server
  "./nodebb log" to view server output
  "./nodebb help" for more commands

默认端口是4567,如果想用80端口可以用nginx之类的反向代理
在Ubuntu系统下NodeBB安装成功


每天学 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:从零使用Ubuntu安装NodeBB
赞(4)
分享到: 更多 (0)

为了阻止垃圾和反动评论,您必须才能发表评论,使用功能只需要1分钟注册好账号!