Install Mongodb

  • Post author:
  • Post category:Apps

From mongodb.org
From if-not-true-then-false.com
From php.net

To install mongodb, add the appropriate repo information below for your distribution version (x86_64 or i686) to /etc/yum.repos.d/10gen.repo:

vim /etc/yum.repos.d/10gen.repo

add


[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0

or

[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0

then run

yum update && yum install mongo-10gen mongo-10gen-server

Check the basic mongodb configuration settings before starting MongoDB (default settings are usually good)


vim /etc/mongod.conf

logpath=/var/log/mongo/mongod.log
port=27017
dbpath=/var/lib/mongo

Start the service
service mongod start

Start the service on boot
chkconfig --levels 235 mongod on

Now, lets test the server. Start it with the ‘mongo’ command
mongo

Save, Update and Find Some Test Data on MongoDB

> use test
switched to db test
> db.foo.find()
> db.foo.save({a: 1})
> db.foo.find()
{ "_id" : ObjectId("4b8ed53c4f450867bb35a1a9"), "a" : 1 }
> db.foo.update( {a: 1}, {a: 5})
> db.foo.find()
{ "_id" : ObjectId("4b8ed53c4f450867bb35a1a9"), "a" : 5 }

Now, let’s oOpen MongoDB Port (27017) in Iptables

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT
service iptables save
service iptables restart

Let’s also add the port to csf in /etc/csf/csf.conf

# Allow incoming TCP ports
TCP_IN = 27017

To install the php extension:
pecl install mongo

Then add the following line to your php.ini file:
extension=mongo.so

Now, verify that the mongo port is open and listening
lsof -i |grep 27017

That’s it!

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....