In this article, I would like to guide how we install a MongoDb instance on Ubuntu virtual machine that you have installed.
- You must install an Ubuntu OS virtual machine on VWareWorkstation application or any box supports you create a virtual machine.
- Putty client that can connect to the virtual machine.
- Ubuntu OS must be 12.04 or 14.04 LTS version
Step 1: Connect to the virtual machine through Putty
Step 2: Register the MongoDB packages with Ubuntu
sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv EA312927
Step 3: Create list of folder to store mongodb such as data files and log files
echo “deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
Step 4: Update some packages before installing
sudo apt-get update
Step 5: Install MongoDB
sudo apt-get install -y mongodb-org
Connect to MongoDB
By default, a MongoDB instance named mongod runs on 27017 port and IP is 127.0.0.1 or localhost
Step 1: Verify MongoDB instance status
sudo service mongod status
If status is stop/waiting, we need to start
Step 2: Start a MongoDB service
sudo service mongd start
Step 3: Stop a MongoDB service
sudo service mongd stop
Step 4: connect to MongoDB. By default, you will access test database.
Now, you’re ready to work on MongoDB.
Modify IP Address of MongDB instance
In case you want to connect to the MongoDB instance what you have installed from other client machines, you need to modify the IP address of the machine that is running the MongoDB instance instead of default value 127.0.0.1
Step 1: login with root user
Step 2: open mongod.conf file. There is the configuration file which mongod service uses it whenever it is started.
Step 3: go to line bind_ip and edit the value. In this case, bind_ip is changed 192.168.137.40 instead of 127.0.0.1 as default
Step 4: Cltr+X -> Y -> Cltr+A+M