Installation steps of MongoDB on Linux CentOs

Installation steps of MongoDB on Linux CentOs

Posted by Andy on 2015-03-28 07:11:14.0


Hi Andy ,

Below are the steps to install MongoDB on Linux.

Solution : Installation steps of MongoDB on Linux CentOs


Step 1 : Create a new user . Installing packages as the root user is discouraged. Refer this link for more details .
 A new user can be added using the command :  adduser 
You can follow up with setting the password using the command : passwd   as the following screenshot shows.

 
[[email protected] home]# adduser mongoadmin
[[email protected] home]# ls -l
total 4
drwx------. 2 mongoadmin mongoadmin 4096 May 15 22:00 mongoadmin
[[email protected] home]# passwd mongoadmin
Changing password for user mongoadmin.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[[email protected] home]#


Step 2 : Grant permissions to the new user. For this , you need to edit the sudoers file . Look for root and edit the file as per the following screenshot
 
vi /etc/sudoers
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
mongoadmin ALL=(ALL) NOPASSWD: ALL

Step 3: 
/etc/yum.repos.d/mongodb-org-3.0.repo

[mongodb-org-3.0]
name=MongoDB Repository
baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/
gpgcheck=0
enabled=1

 
Step 3: Install MongoDB using yum package manager . The following screenshot shows the command and the output.
[[email protected] ~]$ sudo yum install -y mongodb-org
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mongodb-org.x86_64 0:3.0.3-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================
 Package                  Arch                Version                  Repository                    Size
==========================================================================================================
Installing:
 mongodb-org              x86_64              3.0.3-1.el6              mongodb-org-3.0              4.6 k

Transaction Summary
==========================================================================================================
Install       1 Package(s)

Total download size: 4.6 k
Installed size: 0
Downloading Packages:
mongodb-org-3.0.3-1.el6.x86_64.rpm                                                 | 4.6 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mongodb-org-3.0.3-1.el6.x86_64                                                         1/1
  Verifying  : mongodb-org-3.0.3-1.el6.x86_64                                                         1/1

Installed:
  mongodb-org.x86_64 0:3.0.3-1.el6

Complete!
[[email protected] ~]$

Step 4: opening the 27017 port of linux cetnos so that server can be access from remote machine.
[[email protected] mongoadmin]# sudo iptables -A INPUT -p tcp --dport 27017 -j ACCEPT
[[email protected] mongoadmin]# sudo iptables -A OUTPUT -p tcp --dport 27017 -j ACCEPT
[[email protected] mongoadmin]# sudo iptables save
Bad argument `save'
Try `iptables -h' or 'iptables --help' for more information.
[[email protected] mongoadmin]# sudo service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[[email protected] mongoadmin]# sudo service iptables restart
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]
 
Step 4 : The yum package manager installs the service on the server automatically. Start the MongoDB service by issuing the command as shown below
 
[[email protected] ~]$ sudo service mongod start
Starting mongod:                                           [  OK  ]
[[email protected] ~]$
 
2015-05-15T22:35:32.127+0530 I JOURNAL  [initandlisten] journal dir=/var/lib/mongo/journal
2015-05-15T22:35:32.128+0530 I JOURNAL  [initandlisten] recover : no journal files present, no recovery needed
2015-05-15T22:35:32.229+0530 I JOURNAL  [durability] Durability thread started
2015-05-15T22:35:32.229+0530 I JOURNAL  [journal writer] Journal writer thread started
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten] MongoDB starting : pid=1928 port=27017 dbpath=/var/lib/mongo 64-bit host=analytics.infinitysn.com
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten]
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten]
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten]
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 1024 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.
2015-05-15T22:35:32.318+0530 I CONTROL  [initandlisten]
2015-05-15T22:35:32.318+0530 I CONTROL  [initandlisten] db version v3.0.3
2015-05-15T22:35:32.318+0530 I CONTROL  [initandlisten] git version: b40106b36eecd1b4407eb1ad1af6bc60593c6105
2015-05-15T22:35:32.318+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2015-05-15T22:35:32.318+0530 I CONTROL  [initandlisten] build info: Linux ip-10-182-86-231 2.6.32-220.el6.x86_64 #1 SMP Wed Nov 9 08:03:13 EST 2011 x86_64 BOOST_LIB_VERSION=1_49
2015-05-15T22:35:32.318+0530 I CONTROL  [initandlisten] allocator: tcmalloc
2015-05-15T22:35:32.318+0530 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1" }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/var/lib/mongo" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2015-05-15T22:35:32.347+0530 I NETWORK  [initandlisten] waiting for connections on port 27017


Step 5 : Duplicate session . The new session acts as your client for MongoDB server. Type mongo to establish connection as shown below 

[[email protected] ~]$ mongo
MongoDB shell version: 3.0.3
connecting to: test
Server has startup warnings:
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten]
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten]
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten]
2015-05-15T22:35:32.317+0530 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 1024 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.
2015-05-15T22:35:32.318+0530 I CONTROL  [initandlisten]
>
Sterp 8
> use admin
switched to db admin


Note : It is helpful to view the information logged against each command . You can duplicate another session and open the log file to view the logs against your commands .The log file is stored at /var/log/mongodb/mongod.log by default . Use the following command to achieve this.
 
 sudo tail -f /var/log/mongodb/mongod.log


MongoDB is now installed on Linux CentOs ! Hope this helped.

Cheers!!


Good Luck !!

Posted by Navdeep on 2015-05-15 11:12:36.0