Jan 032012
 

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

<br />
[10gen]<br />
name=10gen Repository<br />
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64<br />
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)

<br />
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

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

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

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

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

<br />
# Allow incoming TCP ports<br />
TCP_IN = 27017<br />

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!

Share This!
 Posted by at 6:20 pm

Sorry, the comment form is closed at this time.