This is our final post on the Azure VM series! Here we learn how to configure MongoDB on an Azure VM
Ø Installing and Configuring MongoDB on Windows Azure Virtual machine
1. Taking into consideration that the steps are followed based on the earlier tutorial of creating a Windows Azure Virtual Machines and logging in with the Remote Desktop Procedure and you can see the screen as below.
2. Let us start installing the MongoDB. Open Internet Explorer and go the MongoDB website which is www.mongodb.org/ and click on downloads to download the setup files as shown in the screen below.
3. Install the latest production release from the list of available downloads which is specific to our environment which is a 64bit windows operating system and save it on to the server desktop as shown in the screen below.
4. Now extract the downloaded zip file and place it an appropriate folder using which we need to run the scripts from the command prompt to install the database as shown in the screen below.
5. Now create 2 folders one for the MongoDB Data and other for the MongoDB logs in a folder which is accessible in any of the drives available. Here we will create with the C: Drive as shown in the screen below.
6. Open Command Prompt and run the below scripts which will create the database as shown in the screen.
C:\Users\Administrator\Desktop\MongoDB\bin>mongod logpath C:\Logs\mongolog.log –logappend –dbpath C:\Data\ –install
Executing this script will install mongodb windows service which makes all the logs files to be moved to the log folder and the data to the data folder when the MongoDB is up and running
7. Now to start the MongoDB windows service.
8. To start the MongoDB open a Command Prompt windows again and enter the below script, it will open the MongoDB administrative Shell as shown in the screen below.
9. User Below scripts to connect to specific database and to create user for database.
Now this DB is available locally to the machine but to access it outside we need to have set of configuration.
Ø Access MongoDB remotely
We have seen how to install and configure the MongoDB on to a Windows Azure Virtual Machine and access it locally within the server. Now we will see how to configure the end points and get the access to the outside environment by setting the appropriate end points.
1. Let us start with setting up the inbound rules, to do that click on Start and go to Administrative Settings and select Windows Firewall with Advanced Security as shown in the screen below.
2. Click in the Inbound Rules and create a new Rule as shown in the screen below. We can see a wizard where we need to configure the Inbound Rules that are allowed to connect to the database.
3. We can see a Wizard opens and have the option to select a Program or a port that are to be configured. We can select a particular program level rule to configure or we can configure it based on the port. Let us do it by Port, to do that select PORT option and click on Next to proceed further as shown in the screen below.
4. We need to set the Port on which the MongoDB listens to. MongoDB uses the port 27017 port which is over the TCP protocol that is used by the database. So select TCP and enter the port 27017 and click on Next as shown in the screen below.
5. Next screen provides option to how the connection to be secured. Select Allow Connection option from the list and click on Next button as shown in the screen below.
6. We can see next a list of options to which the rule should apply, since by default it applies to the entire options click on Next directly without changing any option as shown in the screen below.
7. Now we are the final stage, specify a valid name to the port like MongoDBPort or something which best describes the requirement of the port configured and click on Finish as shown in the screen below.
8. We can see the port is configured and a new Rule is added which is listed in the list of available rules as shown in the screen below.
9. So we are done with enabling a port where the MongoDB listens to the server, next is to configure the Endpoints which can be done from the Management Portal. Login to the Management portal and go to the Virtual Machine environment and select the virtual machine where we are going to configure the end point as shown in the screen below.
10. At the bottom menu click on Add Endpoint option which basically provides a screen to add the end point to which we have configured the port in the server as shown in the screen below.
11. Enter the port which we configured in the server (27017) by providing the required fields as shown in the screen below and click on Finish to add the end point to the virtual machine.
Now we have made a port where the MongoDB is accessible from the server. So essentially all the rules are provided to access the port through which we can access the Database.
Hope this series helped make your MongoDB on Azure migration easier! Let us know your experiences with MongoDB hosted on VMs vis-à-vis hosting providers like MongoLabs!