Step X Step : Install and Configure MongoDB in Ubuntu.

Hi There,

Few months ago i have posted a Step X Step reference to Install and configure MongoDB on Windows Operation System. now i am doing the same but to Install and Configure MongoDB on Linux Server (am Using UBUNTU 14.04 LT version).

I. Lets Be Root Users

sudo -s

II. Prepare your System with Latest Updates (do this before any installation of any kind)

sudo apt-get update
sudo apt-get upgrade

note that apt-get update (Used to re-synchronize the package index files from their sources) and apt-upgrade (Used to install the newest versions of all packages currently installed on the system from the sources enumerated in/etc/apt/sources.list) [Reference Here for more details]

III. Import the public key used by the package management system.[Reference For more details]

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

IIII. Create a list file for MongoDB. [Reference For more details]

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

V. Re-synchronize the package index files

sudo apt-get update

VI. Install the latest stable version of MongoDB

sudo apt-get install mongodb-org

At this point we done and we have mongo Installed at the server configured to port 27017 and accept only requests from local host.

Now Lets discover the mongod Config file and see how we can change it to enable remote access to MongoDB.

First : Issue the following comand on the Terminal as Root (sudo -s makes you root)

vim /etc/mongod.conf

Note that “vim” is a popular text editor based off of the venerable vi editor, if you don’t have it, and mostly you will have it , install it with the command

sudo apt-get install vim

Second : the vim will open the mongod.conf file inside your terminal, here we have two lines to Focus.

Line 1: #Port = 27017

This is the default port, and by default commented by ‘#’ remove the ‘#’ and change it and you will change the port that mongo listen to.

Line 2: bind_ip = 127.0.0.1

This line means that the mongodb engine just accept requests from localhost, comment the line with ‘#’ and you will make mongo accept requests from any IPs, or write the IP of interests, note that you can add more than one IP with ‘,’ separations.

To make any of the above changes, use the arrows in your keyboard up and down to the line of ineterst and use the ‘x’ to delete character and type what ever you want.

After that Typr [ESC] then [:w] then [:q]

:w  (will save the changes)

:q (will exit vim and get back to the treminal)

Finally : Lets Open the port 27017 to Accept requests, do this by the following.

Note: If you are using AZURE VM or Google Compute engine, the following steps are not necessary as you just need to open the Port in the FireWall Rule or EndPoints Manager.

For Any IPs:

iptables -A OUTPUT -p tcp --dport 27017 -j ACCEPT
iptables -A INPUT -p tcp --dport 27017 -j ACCEPT

For Specific IP:

iptables -A INPUT -s <ip-address> -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -d <ip-address> -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT

and the last thing if you have the UFW enabled , you will need to open the port in the firewall

sudo ufw akllow 27017
sudo ufw akllow 27017/tcp
Advertisements

7 thoughts on “Step X Step : Install and Configure MongoDB in Ubuntu.

  1. It’s the ƅst time to make some plans for the future andd it іs time to be happy.
    I hаve reаzd this post and if Ⅰ could I wish to suggest you some interesting things oor adᴠice.
    Maybe you could write next articles rеferrihg to this article.

    I wish to read more things about it!

    Like

  2. Nice post. I learn some thing challenging on distinct blogs daily.
    It will always be stimulating to read content of great writers like you.
    I’d choose to use some content in my small weblog if you do not mind.
    Of course I’ll provide a link on your own internet weblog.
    Many thanks for sharing.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s