Web Projects Consulting

Setting Up MongoDB on Fedora with Basic Security Options

MongoDB is a popular NoSQL database solution with growing popularity over professional and non-professional users. Blah. Now to setting all up.

MongoDB in Fedora repo will not work with authentication and segfault, get it and install from MongoDB site.

sudo vim /etc/yum.repos.d/mongo.repo

Cut and paste the below:

name=10gen Repository

Install MongoDB:

sudo yum install mongo-10gen mongo-10gen-server

Edit the default config file.

sudo vim /etc/mongod.conf

Find and edit:

bind_ip =
port = 27017

Create a very basic service:

sudo gedit /etc/init.d/mongod

Cut and paste:

#! /bin/sh

<h1>chkconfig: 345 20 80</h1>

<h1>description: mongod daemon</h1>

<h1>processname: mongod</h1>


set -e

case &quot;$1&quot; in
$N -f /etc/mongod.conf --journal
echo &quot;Usage: $N {start|stop|restart|force-reload}&quot; &gt;&amp;2exit 1

exit 0

Run service:

sudo service mongod start
sudo chkconfig --levels 235 mongod on

Check if all ok:

[user@localhost ~]$ mongo
MongoDB shell version: 2.0.2
connecting to:
> db.help()
DB methods:
        db.addUser(username, password[, readOnly=false])
        db.auth(username, password)
# ... blah

Or visit in browser: //localhost:28017 (we are going to close that later).

You can stop the above service from mongo console:

use admin
//when using auth, launch:
//db.auth(username, password)
// or
db.adminCommand({shutdown : 1, force : true})
// or
db.shutdownServer({force : true})
// or
db.adminCommand({shutdown : 1, timeoutSecs : 5})

Add possibility for PHP to connect to it and restart web server:

sudo pecl install mongo
sudo service httpd restart


[user@localhost ~]$ php -m |grep -i mongo

Add more security:

[user@localhost ~]$ mongo
MongoDB shell version: 2.0.2
connecting to:
> use admin
switched to db admin

Edit the config again:

sudo vim /etc/mongod.conf

Find and edit:

noauth = false
auth = true
nohttpinterface = true

Stop and start the server again as described above.

Get and install some web admin tool into a folder on your web server, for instance //code.google.com/p/rock-php/wiki/rock_mongo. To connect, edit the config.php file from this package with the following values:

# uncomment
$MONGO["servers"][$i]["mongo_db"]                 = "local";
$MONGO["servers"][$i]["mongo_user"]               = "USER_FROM_ABOVE";
$MONGO["servers"][$i]["mongo_pass"]               = "PASSWORD_FROM_ABOVE";
$MONGO["servers"][$i]["mongo_auth"]               = true;
# comment
#$MONGO["servers"][$i]["control_auth"]            = true;
#$MONGO["servers"][$i]["control_users"]["admin"]  = "admin";

DISCLAIMER: tested for Fedora 15 only and might require more security fixes.

RockMongo with auth in Fedora 15


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.