Install MongoDB 1.6.0 on Fedora 13, CentOS 5.5, Red Hat (RHEL) 5.5

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 1.6.0 on Fedora 13/12/11, CentOS 5.4/5.5 and Red Hat (RHEL) 5.4/5.5. Using MongoDB own YUM repositories. CentOS / Red Hat (RHEL) RPM packages are currently available for x86 (32-bit) and x86_64 (64-bit) architectures. Fedora RPM packages are currently available only for x86_64 (64-bit) architecture. With this method it is possible to install the following revisions stable, unstable, and snapshot.

1. Install MongoDB on Fedora 13/12/11, CentOS 5.4/5.5 and Red Hat (RHEL) 5.4/5.5

1.1 Change to root User

su -
## OR ##
sudo -i

1.2 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 CentOS 5.4/5.5 and Red Hat (RHEL) 5.4/5.5 on x86 (32-bit)
[10gen]
name=10gen Repository
baseurl=http://downloads.mongodb.org/distros/centos/5.4/os/i386/
gpgcheck=0
Mongodb-repo for CentOS 5.4/5.5 and Red Hat (RHEL) 5.4/5.5 on x86_64 (64-bit)
[10gen]
name=10gen Repository
baseurl=http://downloads.mongodb.org/distros/centos/5.4/os/x86_64/
gpgcheck=0
Mongodb-repo for Fedora 13 on x86_64 (64-bit)
[10gen]
name=10gen Repository
baseurl=http://downloads.mongodb.org/distros/fedora/13/os/x86_64/
gpgcheck=0
Mongodb-repo for Fedora 12 on x86_64 (64-bit)
[10gen]
name=10gen Repository
baseurl=http://downloads.mongodb.org/distros/fedora/12/os/x86_64/
gpgcheck=0
Mongodb-repo for Fedora 11 on x86_64 (64-bit)
[10gen]
name=10gen Repository
baseurl=http://downloads.mongodb.org/distros/fedora/11/os/x86_64/
gpgcheck=0

1.3 Install mongo server and mongo client packages

Install stable version of MongoDB

yum install mongo-stable mongo-stable-server

Install unstable version of MongoDB

yum install mongo-unstable mongo-unstable-server

Install snapshot version of MongoDB

yum install mongo-snapshot mongo-snapshot-server

2. Configure MongoDB Database Server

2.1 Edit /etc/mongod.conf file:

nano -w /etc/mongod.conf

2.2 Check and set basic settings, before starting MongoDB (default settings are good)

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

2.3 Fix /var/lib/mongo directory permissions

chown -R mongod:mongod /var/lib/mongo/

2.4 Start MongoDB Server

service mongod start
## OR ##
/etc/init.d/mongod start

2.5 Start MongoDB on boot

chkconfig --levels 235 mongod on

3. Test MongoDB Server

3.1 Open MongoDB Command Line Client

mongo

3.2 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 }

4. Open MongoDB Port (27017) on Iptables Firewall (as root user again)

Edit /etc/sysconfig/iptables file:

nano -w /etc/sysconfig/iptables

4.1 Add following line before COMMIT:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT

4.2 Restart Iptables Firewall:

service iptables restart
## OR ##
/etc/init.d/iptables restart

Note: Open MongoDB port only if you have enabled authentication or operating trusted environment.

4.3 Test remote connection

mongo server:port/database
## Example ##
mongo 10.0.10.45:27017/test

Related posts:

  1. Install Apache (httpd) and PHP 5.3.3 on Fedora 13, CentOS/RHEL 5.5/6 This guide shows howto install Apache HTTP Server (httpd) with PHP 5.3.3 and following modules: PEAR PDO MySQL PostgreSQL Memcache...
  2. Install VirtualBox 3.2.8 on Fedora 13, CentOS 5.5, Red Hat (RHEL) 5.5/6 VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. VirtualBox is a general-purpose...
  3. Install Memcached (Memcache) on CentOS 5.5, Fedora 13, Red Hat (RHEL) 5.5 Memcached is a high-performance, distributed memory object caching system, generic in nature, but originally intended for use in speeding up...
  4. Install Adobe Flash Player 10.1 on Fedora 13, CentOS 5.5, Red Hat (RHEL) 5.5 This is guide, howto install Adobe Flash Player Plugin version 10.1 with YUM on Fedora 12, Fedora 13, CentOS Linux...
  5. LAMP on Fedora 13, CentOS/Red Hat (RHEL) 5.5/6 – (Linux, Apache, MySQL, PHP) LAMP (Linux, Apache, MySQL, PHP) server is very powerful server setup behind any website or web based service. This guide...

About the Author

Hi, I'm JR and the Founder of if not true then false. I am a software developer, and I have over ten years experience in programming. I'm big fan of Linux and Open Source. And normally I use just Linux environments. - You can follow me on Twitter at @zuissi