NoSQL: MongoDB

Installation

by ross at 07:58:21 on March 8, 2015

Install the port

# cd /usr/ports/databases/mongodb
# make install clean

Add to /etc/rc.conf:

mongod_enable="YES"
mongod_dbpath="/home/mongodb"

The second line is optional. It allows you to have DB data in a directory other than default /var/db/mongodb.

Start Mongo:

# service mongod start

If the DB dir does not exist it will be created on first run.

Secure installation

Start Mongo by running mongo command and enter the following (change "mypassword" to your password):

use admin
db.createUser(
  {
    user: "root",
    pwd: "mypassword",
    roles: [ { role: "root", db: "admin" } ]
  }
)

Now edit /usr/local/etc/mongodb.conf, add the line:

auth=true

Restart Mongo:

# service mongod restart

From now on users will have to authorize. In order to connect to Mongo as an administrator (i.e. user "root" you've just created):

> mongo -u root -p --authenticationDatabase admin

Log rotation

In order to enable log rotation add to /etc/newsyslog.conf the following line:

/home/mongodb/mongod.log    mongodb:mongodb 640  7     *   [email protected]  BJG /home/mongodb/mongod.lock 30

In the example above Mongo dbdir is /home/mongodb.

Restart syslog:

# service newsyslog restart

 

Comments