Setting up MongoDB Server as a system for easy start and stop
It's happening today. After installing the next MongoDB service locally, after installation, the configuration file is created for the database service to indicate where the database raw files are stored, then the MONGO server is started, and then a non-shun is found. The EXE that starts the server executes will leave a CMD window, this really is: , why not a system service running in the background?
decided to make MONGO server set as system service This thing, first is to check the relevant information how to put an EXE program configured as a Windows system services, the middle also found the use of "SC", really took a big detour Ah!!
Below is a description of installing MongoDB under Windows and configuring MongoDB Services (Windows 10);
1. Download the MSI installation file and install it, Download
2. For ease of operation, this is done after installation, and the bin directory under the MONGO installation directory is configured into the environment variable.
3. Create the MONGO initialization configuration file, which specifies the location of the database file and log file storage, I put the configuration file in the "E:\mongodb\mongod.cfg" file content as follows,
systemLog: destination: file path: E:\mongodb\data\log\mongod.logstorage: dbPath: E:\mongodb\data\db
4. Ready to do this, then we can execute the mongod command to register the system's MongoDB service, here we use the system administrator to open a command line terminal ("cmd.exe"), execute the following command;
mongod --config "E:\mongodb\mongod.cfg" --install
5. Then you can view the system's list of services, run "services.msc", open the System Services management interface to find the "MongoDB" service, verify that the above operation has successfully injected the system MongoDB service;
6. Start the service
1). Method One, the service Management page opened in the previous step to find the MongoDB service and start;
2). Method Two, go back to the command line, execute net start MongoDB;
The same approach is true for closing services! net stop MongoDB;
7. Finally we connect the next MongoDB server through the MONGO shell (MONGO the default is to turn off authorization authentication, as long as the connection to the port can be connected to the data service)!
mongo
In this case, we successfully created the MongoDB service under Windows, so we don't have to see the annoying command service terminal.
PS: In this case, after starting the service, there will only be a MONGO server on this machine, (that is, there can only be one server entity on this host, I think this should be normal), there are some other special needs, such as we want to build a MONGO server Cluster, that way the system service can only provide us with one server entity, then we can execute multiple mongod ("Mongod-f mongod.conf", each individual server entity needs a profile, Separate the respective database files and logs in different directories) command to start multiple command terminals, so that each command terminal corresponding to a MONGO server, you can make up our database cluster of haha
Set up MongoDB system service under Windows