Address: http://www.mongodb.org/display/DOCS/Windows+Service
On Windows, cmdd.exe supports local installation and operation of Windows Services.
Service commands
Service-related Commands include:
JS Code
- Mongod -- install
- Mongod -- service
- Mongod -- remove
- Mongod -- reinstall
You can also pass the following options to-install and-reinstall.
JS Code
- -- Servicename {Arg}
- -- Serviceuser {Arg}
- -- Servicepassword {Arg}
The-install and-Remove options install Mongo as services and remove Mongo. The -- service option is used to enable the Service. -- Reinstall will try to remove the service and then install it. If the service has not been installed, -- reinstall is also valid.
If the service is running, -- remove and-reinstall both stop it.
To change the service name, use-servicename. -Serviceuser and-servicepassword are used no matter whether Mongo is run as a local, domain, or local SYSTEM account.
With the command line passed along with -installto any node of mongod.exe, the service will be used to configure the running of mongod.exe. See the following example (these parameters are not required to run mongod as a Service ):
JS Code
- Mongod -- logpath D: \ Mongo \ logs -- logappend -- dbpath D: \ Mongo \ data -- directoryperdb -- install
This causes a service called Mongo to run the following command:
Mongo code
- Mongod -- logpath D: \ Mongo \ logs -- logappend -- dbpath D: \ Mongo \ data -- directoryperdb
Installed on win7
To install the service on win7, you must ensure that you are running as an administrator. To do this, open the menu and click "cmd.exe" in the search box ". Right-click the command line program that appears and select "Run as administrator ".
In this case, you can install MongoDB as a service through-install as described above.
Use mongos as a Windows Service
Currently (the minimum version is 1.8), mongos does not support direct installation for Windows Services. However, by using Windows Resource Kit (Click here to download), you can configure to enable mongos when the Windows Host starts.
1. Assume that your mongos configuration file is c: \ MongoDB \ mongos. conf, And you have tested it.
2. Run cmd.exe with the administrator ID.
3. Install srvany.exe as a service, as shown in the following figure:
C: \ Program Files \ Windows resource kits \ tools> "C: \ Program Files \ Windows Resource
CMD code
- Kits \ tools \ instsrv.exe "mongos" C: \ Program Files \ Windows resource kits \ tools \ srvany.exe"
The output is similar to this:
CMD code
- 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.
10.open regedit.exe.
11. Find the subkey
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ mongos
12. Right-click mongos, select new> item, and enter parameters.
13. Select parameters.
14. Right-click the window on the right, select new> string value, and enter application.
15. Change the applicationvalue to the full path of cmds.exe, for example, C: \ MongoDB \ bin \ cmds.exe.
16. Right-click again, choose new> string value, and enter appparameters.
17. Modify the value to mongos parameters, for example, -- config c: \ MongoDB \ mongos. conf.
18. Use Net start mongos to check whether the service can be enabled.