
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
[10gen] name=10gen Repository baseurl=http://downloads.mongodb.org/distros/centos/5.4/os/x86_64/ gpgcheck=0
[10gen] name=10gen Repository baseurl=http://downloads.mongodb.org/distros/fedora/13/os/x86_64/ gpgcheck=0
[10gen] name=10gen Repository baseurl=http://downloads.mongodb.org/distros/fedora/12/os/x86_64/ gpgcheck=0
[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-serverInstall unstable version of MongoDB
yum install mongo-unstable mongo-unstable-serverInstall snapshot version of MongoDB
yum install mongo-snapshot mongo-snapshot-server2. 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:
- 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...
- 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...
- 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...
- 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...
- 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...
I followed these instructions exactly, no errors or warnings from any of the commands, but the file /etc/sysconfig/mongod was never created. Do I need to create it manually? If so, what should the contents be? Thanks.
Hi Mark,
The /etc/sysconfig/mongod file should not be created.
You possibly mean or try to find /etc/sysconfig/iptables, /etc/mongod.conf or /etc/init.d/mongod file?
@JR/Mark The issue he referes to is this:
[root@main ~]# service mongod start
/etc/init.d/mongod: line 24: /etc/sysconfig/mongod: No such file or directory
Starting mongod: warning: some regex utf8 things will not work. pcre build doesn’t have –enable-unicode-properties
forked process: 13626
all output going to: /var/log/mongo/mongod.log
[root@main ~]# [ OK ]
Though it seems to start okay.
/etc/init.d/mongod: line 25: /etc/sysconfig/mongod: No such file or directory
Starting mongod: runuser: user mongod does not exist
same
/etc/init.d/mongod: line 25: /etc/sysconfig/mongod: No such file or directory
Starting mongod: runuser: user mongod does not exist
get this error on service mongod start
PLEASE HELP?
Hi,
Everybody with following problem:
Old repositories caused this problem (they worked nice with 1.2.x versions, but not with 1.4.x versions and now this guide installs 1.6.x version), I updated this guide to use MongoDB own repositories and now I tested this new installation method on different systems and it worked smoothly.
So if you have old packages installed then simply remove them, with following command:
And then follow this guide.