Wednesday 1 February 2012

install and run mongodb as a windows service


On windows mongod.exe has native support for installing and running as a windows service.

Service Related Commands

The service related commands are:
mongod --install
mongod --service
mongod --remove
mongod --reinstall
You may also pass the following options to --install and --reinstall
--serviceName {arg}
--serviceUser {arg}
--servicePassword {arg}
The --install and --remove options install and remove the mongo daemon as a windows service respectively. The --service option starts the service. --reinstall will attempt to remove the service, and then install it. If the service is not already installed, --reinstall will still work.
Both --remove and --reinstall will stop the service if it is currently running.
To change the name of the service use --serviceName. To make mongo execute as a local or domain user, as opposed to the Local System account, use --serviceUser and --servicePassword.
Whatever other arguments you pass to mongod.exe on the command line alongside --install are the arguments that the service is configured to execute mongod.exe with. Take for example the following command line (these arguments are not required to run mongod as a service):
mongod --logpath d:\mongo\logs\logfilename.log --logappend --dbpath d:\mongo\data --directoryperdb --install
This will cause a service to be created with service name "MongoDB" and display name "Mongo DB" that will execute the following command:
mongod --logpath d:\mongo\logs\logfilename.log --logappend --dbpath d:\mongo\data --directoryperdb --service
If your file specification includes spaces, put quotes around the file specification.
mongod --logpath "d:\my mongo\logs\my log file name.log" --logappend --dbpath "d:\my mongo\data" --directoryperdb --install

Installing on Windows 7

If installing on Windows 7, you need to make sure that you're running as an administrator. To do this, open the start menu, and in the search box enter "cmd.exe." When the executable appears, right-click on it and choose "Run as administrator."
At this point, you can install MongoDB as a service with the --install option as described above.

mongos as a Windows service

For the moment (at least through 1.8.x), mongos does not yet directly support being installed as a Windows service. However, using the Windows Resource Kit available here, you can configure a Windows host to start mongos at system startup. (Tested on a Windows 7 system, with MongoDB 1.8.1):
  1. Assume your mongos config file is at C:\MongoDB\mongos.conf, and
    that you've tested that it works.
  2. Start cmd.exe as an administrator.
  3. Install srvany.exe as a service, like this: 
    C:\Program Files\Windows Resource Kits\Tools>"C:\Program Files\Windows Resource
    Kits\Tools\instsrv.exe" mongos "C:\Program Files\Windows Resource Kits\Tools\srvany.exe"
    The output looks like this: 
    The service was successfuly added\!
    
    Make sure that you go into the Control Panel and use
    the Services applet to change the Account Name and
    Password that this newly installed service will use
    for its Security Context.
    
  4. Start regedit.exe
  5. Find the subkey
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\mongos
  6. Right click on mongos, select New > Key. Name the key Parameters.
  7. Select the Parameters key.
  8. Right click in the right window. Select New > String Value. Name
    the new value Application.
  9. Modify Application's value to be the full path to mongos.exe
    (e.g., c:\mongodb\bin\mongos.exe)
  10. Right click in the right window again. Select New > String Value.
    Name the new value AppParameters.
  11. Modify AppParameters's value to be the arguments to mongos (e.g.,
    --config C:\mongodb\mongos.conf)
  12. To verify that the service can be started, try NET START mongos.

1 comment:

  1. Unable to Install MongoDB on Windows? Contact to MongoDB Technical Support | Cognegic
    In the event that you are the amateur on MongoDB then doubtlessly you don't know how to introduce MongoDB on Windows. In any case, with our few of the means, you can without much of a stretch introduce MongoDB on Windows. To introduce, in the first place, you need to download the MongoDB from the official site. From that point onward, audit the MongoDB envelope. At that point, arrangement records and runs MongoDB server. Presently associate with MongoDB by mongo.exe. To wrap things up, you need to include MongoDB as an administration with the goal that MongoDB will begin naturally. For any question or issue, you can reach to our specialists through MongoDB Online Support and Support for MongoDB Database Software.
    For More Info: https://cognegicsystems.com/
    Contact Number: 1-800-450-8670
    Email Address- info@cognegicsystems.com
    Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801

    ReplyDelete