How to setup MongoDB

Download and install

$ curl http://downloads.mongodb.org/linux/mongodb-linux-i686-1.6.1.tgz > mongo.tgz
$ tar xzf mongo.tgz

Create a data directory

# create default data directory
$ mkdir -p /data/db/
# Grant permission for user-xxx which is the user to run mongodb process
$ chown user-xxx /data/db

Run MongoDB

$ ./mongodb-xxxxxxx/bin/mongod

You should run it with --dbpath parameter like below if data directory is not /data/db/

$ ./mongodb-xxxxxxx/bin/mongod --dbpath=/mnt/ebs/data/mongodb

Add database users

$ ./mongodb-xxxxxxx/bin/mongo
# add a admin user 
> use admin
> db.addUser("admin", "adminpassword")
# add user for poweredsites database
> use poweredsites
> db.addUser("felinx", "felinx")

# show users
> db.system.users.find()

For detail information please refer to the official documentation:

http://www.mongodb.org/display/DOCS/Quickstart+Unix http://www.mongodb.org/display/DOCS/Security+and+Authentication

Felinx Lee   August 27, 2010
Comments blog comments powered by Disqus