Windows C:\> "C:\Program Files\MongoDB\Server\4.0\bin\mongod.exe" The command “ rs.slaveOk()” this is so you allow to read from the slave by default this is not enabled.To start MongoDB, run the following command in a terminal. If everything worked you should see the following: Go to your server two or three and open a mongo shell by double clicking on the “mongo” file and run the following three commands: Step 12: Check if the slaves have data (on server two or three) Now if everything did work as intended all this should have been replicated to your servers mongodb02 and mongodb03 so lets test it! Step 11: Create a test collection with some data on the master (only on server one)Īs you can see “show dbs” did show you have a database ulyaoth, “show collections” show you have the collection Data and “db.Data.find()” did show that the Data collections contains the information “ulyaothguides”. You should see something like this if everything is correct:Ĭongratulations you now have successfully installed mongodb on windows and you have set it up in a replication :)! Now lets test that the replication works by creating a database on the master (mongodb01). Step 10: Test your configuration is working.
(Please be aware if you cannot reach the names “mongodb02” or “mongodb03” you have to use the full ip address of the server or add it to your hosts file) While being in the mongo shell type the following commands: Step 9: Create the replica set in the mongo shell. Go to “C:\Program Files\MongoDB\Server\3.0\bin” and double click on “mongo” a terminal window should open that looks like this: Step 8: Go into the MongoDB shell (only on server one) Just restart the server and MongoDB should automatically start so it is a good test that the previous commands worked. Step 7: Start MongoDB (on all three servers) If you ever wish to delete the service you can do so with the following command: This should create a service for MongoDB if you did it correct, it should look like this: Sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.0\bin\mongod.exe\" -service -config=\"C:\ulyaoth\mongodb\config\mongod.yaml\"" DisplayName= "MongoDB 3.0 Standard" start= "auto" Open a Command Prompt and type the following: Step 6: Create a service that will auto start MongoDB (on all three servers) Once added then save the file as “mongod.yaml” in the directory:
Path: "C:/ulyaoth/mongodb/data/log/mongod.log" Open a notepad and add the following information: Step 5: Create a MongoDB config file (on all three servers) If everything looks as above press on OK to close the firewall configuration window. On this window click on “Allow an app or feature trough Windows Firewall” your window will change and click on this window on “Allow another app.” and fill everything in as below.
You should now see your Windows Firewall like this: Go to your “Control Panel” and then click on “Network and Internet” once there click on “Network and Sharing Center” and then on the left side at the bottom click on “Windows Firewall”. Step 4: Fix the Windows firewall (on all three servers). Step 3: Create a database and log directory (on all three servers) Remember you have to do this on all three your servers. You should now have finished the installation so simpely press “Finish”. On the window above just press “Install” to start the installation.
Press you wish to install the “Complete” version on the picture above.
Read the license and then tick the box you accept the license and press next on the picture above. Just follow the pictures below to install MongoDB, you have to do this on all three servers. Įven it does say Windows 2008 it does work perfect on Windows 2012! MongoDB provides windows installer packages so simply download their msi file from their website. Step 1: Download MongoDB (on all three servers)
They all have to be in the same workgroup or in the same domain, if they are not then you have to add all the servers in your hosts file so mongodb knows how to connect to them. I used for this setup the following three servers that have Windows 2012 r2 Standard edition installed. In this guide I will show some simple steps of how to setup a mongodb installation in a replication on Windows Server.