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.
1. Install MongoDB on Fedora 17/16/15/14/13/12, CentOS 6.3/5.8 and Red Hat (RHEL) 6.3/5.8
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 Fedora 17/16/15/14/13/12, CentOS 6.3/5.8 and Red Hat (RHEL) 6.3/5.8 on i686 (32-bit)
service mongod start
## OR ##/etc/init.d/mongod start
2.4 Start MongoDB on boot
chkconfig --levels235 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 INPUT -m state --state NEW -m tcp -p tcp --dport27017-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
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.
[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 ]
/etc/init.d/mongod: line 25: /etc/sysconfig/mongod: No such file or directory
Starting mongod: runuser: user mongod does not exist
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:
Thanks so much for this guide. I was really stuggling to install mongodb on centos5.5 until I followed these instruction. Amazing! Works great! Persistent connection that autostarts on server reboot – fantastic!
Only one thing – on the last step (4.2) I get this:
Flushing firewall rules: [ OK ] Setting chains to policy ACCEPT: mangle filter nat [ OK ] Unloading iptables modules: [ OK ] Applying iptables firewall rules: iptables-restore: line 1 failed [FAILED]
Is this a problem? I added the line exactly as shown “-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 27017 -j ACCEPT”
Thanks for this guide. It was very helpful. Just one thing.. I run whm/cpanel on my server and mongodb was throwing errors about memory all over the place. I managed to sort this by disabling “Shell Fork Bomb Protection”.
I was wondering if there is a way to enable fork bomb protection and keep mongo happy?
I’m not sure is it possible to use “Shell Fork Bomb Protection” simultaneously with MongoDB, but maybe you could use /etc/security/limits.conf file to limit certain users or groups processes, like following:
<domain><type><item><value>
someuser hard nproc 20@somegroup hard nproc 15
you might want to modify your /etc/init.d/mongod script as follows, to avoid mongod not being able to start if you have a different dbpath location in your config file:
add these two lines towards the top of the /etc/init.d/mongod file:
MONGO_DBPATH=`grep ‘^dbpath’ /etc/mongod.conf | cut -d’=’ -f2` # get dbpath from config
MONGO_LOCKFILE=”$MONGO_DBPATH/mongod.lock”
Good Afternoon, when I used your instruction then after I restart mongod or check status I got this message. See below
[root@ip-10-174-15-18 ~]# service mongod status
cut: the delimiter must be a single character
Try `cut –help’ for more information.
[root@ip-10-174-15-18 ~]# /etc/init.d/mongod start
cut: the delimiter must be a single character
Try `cut –help’ for more information.
Starting mongod: [ OK ]
forked process: 22975
@colin you need to ensure that you add the chain on top of it on /etc/sysconfig/iptables config file.
like this :
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
...
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT
COMMIT
Thank you for this guide. Works for me on CENTOS 6. I did not use your iptables command, as this is only accessed from the local host, so I can not confirm that working, but it looks sane.
mongoDB調査メモ | tonbyブログ - [...] Howto Install MongoDB on CentOS Linux and Red Hat (RHEL) Linux http://www.if-not-true-then-false.com/2010/03/howto-install-mongodb-on-centos-linux-and-red-hat-rhel... [...]
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:
yum remove mongo mongo-serverAnd then follow this guide.
tks
Thanks so much for this guide. I was really stuggling to install mongodb on centos5.5 until I followed these instruction. Amazing! Works great! Persistent connection that autostarts on server reboot – fantastic!
Only one thing – on the last step (4.2) I get this:
Flushing firewall rules: [ OK ]Setting chains to policy ACCEPT: mangle filter nat [ OK ]Unloading iptables modules: [ OK ]Applying iptables firewall rules: iptables-restore: line 1 failed [FAILED]Is this a problem? I added the line exactly as shown “-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 27017 -j ACCEPT”
Thanks
Thanks for this guide. It was very helpful. Just one thing.. I run whm/cpanel on my server and mongodb was throwing errors about memory all over the place. I managed to sort this by disabling “Shell Fork Bomb Protection”.
I was wondering if there is a way to enable fork bomb protection and keep mongo happy?
Hi Marc,
I’m not sure is it possible to use “Shell Fork Bomb Protection” simultaneously with MongoDB, but maybe you could use /etc/security/limits.conf file to limit certain users or groups processes, like following:
you might want to modify your /etc/init.d/mongod script as follows, to avoid mongod not being able to start if you have a different dbpath location in your config file:
add these two lines towards the top of the /etc/init.d/mongod file:
MONGO_DBPATH=`grep ‘^dbpath’ /etc/mongod.conf | cut -d’=’ -f2` # get dbpath from config
MONGO_LOCKFILE=”$MONGO_DBPATH/mongod.lock”
replace the line containing “killproc” with:
killproc -p $MONGO_LOCKFILE -t30 -TERM /usr/bin/mongod
hi tilo,
Good Afternoon, when I used your instruction then after I restart mongod or check status I got this message. See below
[root@ip-10-174-15-18 ~]# service mongod status
cut: the delimiter must be a single character
Try `cut –help’ for more information.
[root@ip-10-174-15-18 ~]# /etc/init.d/mongod start
cut: the delimiter must be a single character
Try `cut –help’ for more information.
Starting mongod: [ OK ]
forked process: 22975
please help thanks a lot..
Hi Karl,
I’m not Tilo and if you check Tilo’s comment time, I think that he’s not answering your question very soon.
But yes, I’m not huge fan of custom hacks to init scripts, but I think that you just have “wrong” single quotes on you config, it should be:
Hi, i’m getting this error:
MongoDB shell version: 1.8.1
connecting to: 87.106.244.253:27017/test
Thu May 19 15:36:29 Error: couldn’t connect to server 87.106.244.253:27017 shell/mongo.js:81
exception: connect failed
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPTThis configuration is not working in my fedora 15. Someone clue what the problem is?
Hi Roberto,
Could you post your /etc/sysconfig/iptables file content?
Please make sure the “accept” line is before “commit” line **AND** all “reject” lines.
@colin you need to ensure that you add the chain on top of it on /etc/sysconfig/iptables config file.
like this :
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
...
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT
COMMIT
Thank you for this guide. Works for me on CENTOS 6. I did not use your iptables command, as this is only accessed from the local host, so I can not confirm that working, but it looks sane.
Thanks!
thks again
Thanks! Everything worked perfectly for me on CentOS 6.2.
Nice post, helped my setup thanks.