MongoDB

如果你担心使用 Redis 会内存耗尽,或者想要论坛更容易扩展,你可以使用 MongoDB 做 NodeBB 的数据库。This tutorial assumes you know how to SSH into your server and have root access.

These instructions are for Ubuntu. Adjust them accordingly for your distro.

Note: If you have to add sudo to any command, do so. No one is going to hold it against you ;)

第 1 步:安装 MongoDB

需要最新版的 MongoDB (或者至少高于包管理器的版本)。安装步骤可以参阅 MongoDB 手册)。

第 2 步:安装 node.js

和 MongoDB 一样,需要, the latest and greatest node.js is required (or at least greater than the package manager), so I’m leaving this to the official wiki. The instructions to install can be found on Joyent.

Note: NPM is installed along with node.js, so there is no need to install it separately

第 3 步: 安装基础软件

Enter the following into the terminal to install the base software required to run NodeBB:

  1. # apt-get install git build-essential imagemagick

第 4 步: 克隆代码库

Enter the following into the terminal, replacing /path/to/nodebb/install/location to where you would like NodeBB to be installed.

  1. $ cd /path/to/nodebb/install/location
  2. $ git clone git://github.com/NodeBB/NodeBB.git nodebb

第 5 步: 安装 NodeBB 依赖的软件

Go into the newly created nodebb directory and install the required dependencies by entering the following.

  1. $ cd nodebb
  2. $ npm install

第 6 步: 添加新数据库

进入 MongoDB 命令行,输入:

  1. $ mongo

添加数据库,命名为 nodebb,输入:

  1. > use nodebb

添加访问 nodebb 数据库的用户,输入:

  1. > db.createUser( { user: "nodebb",
  2. ... pwd: "<输入密码>",
  3. ... roles: [ "readWrite" ] } )

提示: 角色 readWrite 将制定数据库的读或写任何集合(collection)的权限付给用户。

第 7 步: 配置 MongoDB

修改 /etc/mongodb.conf

  1. # nano /etc/mongodb.conf

启用认证,取消注释 auth = true。然后重启 MongoDB。

  1. # service mongodb restart

第 8 步: 配置 NodeBB

Make sure you are in your NodeBB root folder. If not, just type:

  1. $ cd /path/to/nodebb

To setup the app, type:

  1. $ node app --setup
  • Change the hostname to your domain name.
  • Accept the defaults by pressing enter until it asks you what database you want to use. Type mongo in that field.
  • Accept the default port, unless you changed it in the previous steps.
  • Change your username to nodebb, unless you set it to another username.
  • Enter in the password you made in step 5.
  • Change the database to nodebb, unless you named it something else.

Continue with the installation, following the instructions the installer provides you.

Step 9: Starting the App

To start the app, run:

  1. $ node app

Now visit yourdomainorip.com:4567 and your NodeBB installation should be running.

NodeBB can also be started with helper programs, such as supervisor or forever. You can also use nginx as a reverse proxy).