1 MongoDB Several startup methods start the MongoDB service there are two ways, the foreground start or daemon mode start, the former will need to keep the current session cannot be closed, the latter can be used as the system fork Process execution, The path below is the actual address of the MONGODB deployment.
1. The simplest way to start, the foreground start, only specify the data directory, and use the default 27107 port, the CLI can be used directly./mongo with native MongoDB, usually only for temporary development testing.
1 |
. /mongod --dbpath= /path/mongodb |
2. Start the binding fixed IP address, port, this MONGO when the connection Mongod need to specify the IP and port.
1 |
. /mongo 10.10.10.10:12345 |
3. Daemon running in the background, simply add "&" after the command.
1 |
. /mongod --dbpath= /path/mongodb --bind_ip=10.10.10.10 --port=12345 & |
Or, you must specify the path to log when you use the--fork parameter that comes with Mongod.
1 |
. /mongod --dbpath= /path/mongodb --fork= true logpath= /path/mongod .log |
4. (recommended) Save the configuration in the form of a configuration file.
1 port=12345 2 bind_ip=10.10.10.10 3 logpath=/path/mongod.log 4 Pidfilepath =/path/mongod.pid 5 logappend=true 6 fork=true
The configuration file is then introduced when Mongod is started:./mongod-f/path/mongod.conf
The following is a detailed description of the common parameters for Mongod startup:
Parameters |
Description |
Example of taking values |
DBPath |
MongoDB Data File storage path |
/data/mongodb |
LogPath |
Log path for Mongod |
/var/log/mongodb/mongodb.log |
Logappend |
Log using append instead of overwrite |
True |
Bind_ip |
The bound IP |
10.10.10.10 |
Port |
The bound port |
27107 |
Journal |
The write operation first writes "Journal", which is a data security setting, specifically referencing the official documentation. |
True |
5 MongoDB boot up
Add the following code at the end of the/etc/rc.local file
#add MongoDB Service
rm-rf/data/mongodb_data/* &&/usr/local/mongodb/bin/mongod--dbpath=/data/mongdb_data/--logpath=/data/ Mongdb_log/mongodb.log--logappend &
2 Close MONGODB1 foreground operation: If--fork is not used, the front exit terminal can be closed directly. In this way, MongoDB will do its own cleanup and exit, write the data that is not well written, and eventually close the data file. It is important to note that this process continues until all operations are completed. 2 running in the background: if you use--fork to run the MONGDB service in the background, you need to shut down by sending a shutdownserver () message to the server.
1. General Command:
$./mongod
> Use admin
> Db.shutdownserver ()
Note that this command is only allowed locally, or a certified client 2, if this is a master-slave replication cluster, after the 1.9.1 version, follow the steps below to close
Check for data update time from MongoDB
If all the time difference from MongoDB and master is more than 10, this will not close MongoDB (in this case, we can configure the Timeoutsecs way to let the data from MongoDB to complete the update)
If there is a time difference from MongoDB to the primary service within 10 seconds, then the master server will shut down and wait for the update from MongoDB to complete and close. 3. If there is no up-to-date from MongoDB and you want to force the service to close, you can add force:true by adding the following command:
> Db.admincommand ({shutdown:1, force:true})
>//or
> Db.shutdownserver ({force:true}) 4, specify a specific time-out to shut down the server, the command ibid. plus a timeoutsec: parameter
> Db.admincommand (shutdown:1, Force:true, Timeoutsec:5)
>//or
> Db.shutdownserver ({force:true, timeoutsec:5})
Several ways to start MongoDB