The first part of this article is copied from http://www.if-not-true-then-false.com/2010/install-mongodb-on-fedora-centos-red-hat-rhel/ since we will not reinvent the wheels 🙂
What is MongoDB?
MongoDB (from “humongous”) is a scalable, high-performance, open source, schema-free, document-oriented database. Written in C++. MongoDB bridges the gap between key-value stores (which are fast and highly scalable) and traditional RDBMS systems (which provide structured schemas and powerful queries).
MongoDB is very interesting document-oriented database, because it has really awesome features:
- Document-oriented storage (the simplicity and power of JSON-like data schemas)
- Dynamic queries
- Full index support, extending to inner-objects and embedded arrays
- Query profiling
- Fast, in-place updates
- Efficient storage of binary data large objects (e.g. photos and videos)
- Replication and fail-over support
- Auto-sharding for cloud-level scalability
- MapReduce for complex aggregation
- Commercial Support, Training, and Consulting
This guide shows howto install MongoDB 2.0.6 on Fedora 17/16/15/14/13/12, CentOS 6.3/6.2/6.1/6/5.8 and Red Hat (RHEL) 6.3/6.2/6.1/6/5.8. Using MongoDB own YUM repositories. Fedora / CentOS / Red Hat (RHEL) RPM packages are currently available for x86 (32-bit) and x86_64 (64-bit) architectures.
Install MongoDB on Fedora 17/16/15/14/13/12, CentOS 6.3/5.8 and Red Hat (RHEL) 6.3/5.8
Switch to root user
su - ## OR ## sudo -i
Add and enable 10gen MongoDB repository: Select suitable repo for your system and add one of following to /etc/yum.repos.d/10gen-mongodb.repo
- Mongodb-repo for Fedora 17/16/15/14/13/12, CentOS 6.3/5.8 and Red Hat (RHEL) 6.3/5.8 on i686 (32-bit)
[10gen] name=10gen Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686 gpgcheck=0
- Mongodb-repo for Fedora 17/15/14/13/12, CentOS 6.3/5.8 and Red Hat (RHEL) 6.3/5.8 on x86_64 (64-bit)
[10gen] name=10gen Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64 gpgcheck=0
- Mongodb-repo for Fedora 17/16/15/14/13/12, CentOS 6.3/5.8 and Red Hat (RHEL) 6.3/5.8 on i686 (32-bit)
Install mongo server and mongo client packages
yum install mongo-10gen mongo-10gen-server
Configure MongoDB Database Server
Edit /etc/mongod.conf file:
nano -w /etc/mongod.conf
Check and set basic settings, before starting MongoDB (default settings are good)
logpath=/var/log/mongo/mongod.log port=27017 dbpath=/var/lib/mongo
Start MongoDB service:
service mongod start ## OR ## /etc/init.d/mongod start
Start MongoDB on boot
chkconfig --levels 235 mongod on
Test MongoDB Server
Open MongoDB Command Line Client
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 }
Open MongoDB Port (27017) on Iptables Firewall (as root user again)
Edit /etc/sysconfig/iptables file:
nano -w /etc/sysconfig/iptables
Add following line before COMMIT:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT
Restart Iptables Firewall:
service iptables restart ## OR ## /etc/init.d/iptables restart
Test remote connection:
mongo server:port/database ## Example ## mongo localhost:27017/test
Install PHP MongoDB Driver
Check that the PEAR and PECL are working with the following commands:
[root@webserver ~]# pear version PEAR Version: 1.9.4 PHP Version: 5.3.3 Zend Engine Version: 2.3.0 Running on: Linux webserver.younetco.com 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 [root@webserver ~]# pecl version PEAR Version: 1.9.4 PHP Version: 5.3.3 Zend Engine Version: 2.3.0 Running on: Linux webserver.younetco.com 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 [root@webserver ~]#
Check that Mongo Database Driver found:
pecl search mongo
Install Mongo Database Driver with following command:
pecl install mongo
- If you get:
sh: phpize: command not found ERROR: `phpize' failed
, install php-devel package:
yum install php-devel
- If you get
configure: error: in `/var/tmp/pear-build-rooteHkukU/mongo-1.3.4': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details. ERROR: `/var/tmp/mongo/configure' failed
, install gcc:
yum install gcc
- If you get:
Add extension=mongo.so to php.ini (we normally create a new file in configuration inclusion path):
## vi /etc/php.d/mongo.ini ## Add the following lines # MongoDB Driver extension=mongo.so
Restart Web Server (as root):
## Example ## /etc/init.d/apache2 restart ## OR ## /etc/init.d/httpd restart
- In order to program with MongoDB, we can use some libraries such as Shanty Mongo