The MongoDB replica set tutorial should be easy enough to implement on a Windows (server) machine, but how do we run our replica set members as MongoDB windows services, having them start up automatically or manage them with the Windows SCM (Service Control Manager)?
Suggestions to seed multiple hosts in one command didn’t work for me and several other options did not bear much fruit. Especially running mongod —install with the —serverName option did not work out as the new service instance will be named like the first, leading to a conflict and failure of the command.
So the best path might be to forego the 10gen suggested Windows service installation and use the sc.exe utility instead to create the service instance like so:
sc.exe create "Mongo DB 1" binPath= "c:\mongodb\bin\mongod.exe --service --dbpath c:\data\r0 --logpath c:\log\mongodb.log --replSet my_replica_set --port 27017 --rest"sc.exe create "Mongo DB 2" binPath= "c:\mongodb\bin\mongod.exe --service --dbpath c:\data\r1 --logpath c:\log\mongodb.log --replSet my_replica_set --port 27018 --rest"sc.exe create "Mongo DB 3" binPath= "c:\mongodb\bin\mongod.exe --service --dbpath c:\data\r2 --logpath c:\log\mongodb.log --replSet my_replica_set --port 27019 --rest"
Be sure to check adjusts your paths and urls, duh. To edit these commands you can check and edit the HKLM\System\CurrentControlSet\Services\<Mongo Service Name> key, especially its ImagePath parameter. The —rest parameter in the commands above lets you check your replica set configuration by navigating to http://localhost:28017/_replSet
This technique will also be handy when implemeting sharding. Things may get better with 1.7+ versions of MongoDB.
Hope it helps.
Recent Comments