Mongo DB and PHP-Mongo

22 Jan

Installing from Yum repository

  • vi /etc/yum.repos.d/10gen.repo
  • Add the following text to the 10gen.repo file
    • For 64bit CentOS
      [10gen]
      name=10gen Repository
      baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/ gpgcheck=0

       

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

       

  • yum remove mongo-stable mongo-stable-server mongo-stable-debuginfo
  • yum install mongo-10gen mongo-10gen-server mongo-10gen-debuginfo

Manual RPM install

{note:title=Alert}

Skip these steps if your Yum install was successful

{note}

Do a RPM uninstall of 32 bit
  • cd /tmp
  • rpm -U mongo-10gen-2.0.1-mongodb_1.i686.rpm
  • rpm -U mongo-10gen-server-2.0.1-mongodb_1.i686.rpm
Do a RPM uninstall of 64 bit
  • cd /tmp
  • rpm -U mongo-10gen-2.0.1-mongodb_1.x86_64.rpm
  • rpm -U mongo-10gen-server-2.0.1-mongodb_1.x86_64.rpm
Install 32 bit
Install 64 bit

Setup MongoDB service management on CentOS

  • This will automatically start/stop on system startup/shutdown
    • chkconfig mongod on

Start MongoDB

  • mkdir -p /data/db/
  • /usr/bin/mongod –journal
    => –journal needs to be manually defined on 32 bit systems and is automatically defined on 64 bit systems.

Test mongo command line client (In New Terminal Window)

  • mongo –help
  • mongo
    • Connects to localhost by default

Mongo QuickStart Tutorial

Setting up Shards

mkdir /data/db/mastera /data/db/masterb

/usr/bin/mongod –master –shardsvr –dbpath /data/db/mastera –port 10000

/usr/bin/mongod –master –shardsvr –dbpath /data/db/masterb –port 10001

mkdir /data/db/config

/usr/bin/mongod –configsvr –dbpath /data/db/config –port 20000 > /tmp/config.log &

cat /tmp/config.log

/usr/bin/mongos –configdb localhost:20000 > /tmp/config.log &

cat /tmp/config.log

Setting up Master/Slave

mkdir /data/db/slave0 /data/db/slave1 /data/db/slave2 /data/db/slave3

/usr/bin/mongod –slave –source localhost:10000 –dbpath /data/db/slave0/ –port 10002

/usr/bin/mongod –slave –source localhost:10000 –dbpath /data/db/slave1/ –port 10003

/usr/bin/mongod –slave –source localhost:10001 –dbpath /data/db/slave2/ –port 10004

/usr/bin/mongod –slave –source localhost:10001 –dbpath /data/db/slave3/ –port 10005

Install and Configure php-mongo

  • pecl install mongo
    • php mongo is installed in /usr/lib/php/modules/mongo.so
  • echo “extension=mongo.so” > /etc/php.d/mongo.ini
  • service httpd restart

PHP Mongo Tutorial

References

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: