Several startup methods of mongodb

 

1 Several startup methods of mongodb

  There are two ways to start the Mongodb service: foreground startup or Daemon startup. The former requires that the current session cannot be closed, and the latter can be executed as the fork process of the system. The path below is the actual address of the mongodb deployment.
 

 1. The easiest way to start is to start in the foreground, only specify the data directory, and use the default port 27107. You can directly use ./mongo to connect to the local mongodb under the cli, which is generally only used for temporary development and testing.

1
. /mongod  --dbpath= /path/mongodb

2. Start to bind a fixed IP address and port, so mongo needs to specify the IP and port when connecting to mongod.

 

1
. /mongo  10.10.10.10:12345 

 

 3. The daemon runs in the background, simply add "&" after the command.

 

1
. /mongod  --dbpath= /path/mongodb  --bind_ip=10.10.10.10 --port=12345 & 

Or use the --fork parameter that comes with mongod, in which case the log path must be specified.

1
. /mongod  --dbpath= /path/mongodb  --fork= true  logpath= /path/mongod .log 

   4. (Recommended) Save the configuration as a configuration file.

copy code
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  
copy code

Then import the configuration file when starting mongod: ./mongod -f /path/mongod.conf  

The following is a detailed description of common parameters for mongod startup:
parameter illustrate Value example
dbpath mongodb data file storage path /data/mongodb
logpath mongod log path /var/log/mongodb/mongodb.log
logappend log uses append instead of overwrite true
bind_ip bind IP 10.10.10.10
port bind port 27107
journal The write operation first writes the "journal", which is a data security setting. Please refer to the official documentation for details. true

5 MongoDB startup

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 mongodb

1 Foreground run:

If --fork is not used, the terminal can be closed directly from the foreground.
In this way, Mongodb will clean up and exit by itself, write the unwritten data, and finally close the data file.
Note that this process continues until all operations are complete.
 

2 run in the background:

If --fork is used to run the mongdb service in the background, it must be shut down by sending a shutdownServer() message to the server.
 
1. Common command:
$ ./mongod
> use admin
> db.shutdownServer() It
should be noted that this command is only allowed locally, or an authenticated client
2. If this is a master-slave replication cluster, after version 1.9.1, the following steps will be followed to close it
. Check the data update time
of the slave Mongodb. close mongodb
(In this case, we can configure timeoutSecs to complete the data update from Mongodb)
If one of the slave Mongodb and the master service time difference is within 10 seconds, then the master server will shut down and wait for the update from Mongodb Done and close.
 
3. If there is no up-to-date from Mongodb and you want to force shut down the service, you can add force:true; the command is as follows:
> db.adminCommand({shutdown : 1, force : true})
> //or
> db. shutdownServer({force : true})
 
4. Specify a specific timeout to shut down the server. The command is the same as above, plus a timeoutsec: parameter
> db.adminCommand(shutdown : 1, force : true, timeoutsec : 5)
> //or
> db.shutdownServer({force : true , timeoutsec : 5})

1 Several startup methods of mongodb

  There are two ways to start the Mongodb service: foreground startup or Daemon startup. The former requires that the current session cannot be closed, and the latter can be executed as the fork process of the system. The path below is the actual address of the mongodb deployment.
 

 1. The easiest way to start is to start in the foreground, only specify the data directory, and use the default port 27107. You can directly use ./mongo to connect to the local mongodb under the cli, which is generally only used for temporary development and testing.

1
. /mongod  --dbpath= /path/mongodb

2. Start to bind a fixed IP address and port, so mongo needs to specify the IP and port when connecting to mongod.

 

1
. /mongo  10.10.10.10:12345 

 

 3. The daemon runs in the background, simply add "&" after the command.

 

1
. /mongod  --dbpath= /path/mongodb  --bind_ip=10.10.10.10 --port=12345 & 

Or use the --fork parameter that comes with mongod, in which case the log path must be specified.

1
. /mongod  --dbpath= /path/mongodb  --fork= true  logpath= /path/mongod .log 

   4. (Recommended) Save the configuration as a configuration file.

copy code
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  
copy code

Then import the configuration file when starting mongod: ./mongod -f /path/mongod.conf  

The following is a detailed description of common parameters for mongod startup:
parameter illustrate Value example
dbpath mongodb data file storage path /data/mongodb
logpath mongod log path /var/log/mongodb/mongodb.log
logappend log uses append instead of overwrite true
bind_ip bind IP 10.10.10.10
port bind port 27107
journal The write operation first writes the "journal", which is a data security setting. Please refer to the official documentation for details. true

5 MongoDB startup

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 mongodb

1 Foreground run:

If --fork is not used, the terminal can be closed directly from the foreground.
In this way, Mongodb will clean up and exit by itself, write the unwritten data, and finally close the data file.
Note that this process continues until all operations are complete.
 

2 run in the background:

If --fork is used to run the mongdb service in the background, it must be shut down by sending a shutdownServer() message to the server.
 
1. Common command:
$ ./mongod
> use admin
> db.shutdownServer() It
should be noted that this command is only allowed locally, or an authenticated client
2. If this is a master-slave replication cluster, after version 1.9.1, the following steps will be followed to close it
. Check the data update time
of the slave Mongodb. close mongodb
(In this case, we can configure timeoutSecs to complete the data update from Mongodb)
If one of the slave Mongodb and the master service time difference is within 10 seconds, then the master server will shut down and wait for the update from Mongodb Done and close.
 
3. If there is no up-to-date from Mongodb and you want to force shut down the service, you can add force:true; the command is as follows:
> db.adminCommand({shutdown : 1, force : true})
> //or
> db. shutdownServer({force : true})
 
4. Specify a specific timeout to shut down the server. The command is the same as above, plus a timeoutsec: parameter
> db.adminCommand(shutdown : 1, force : true, timeoutsec : 5)
> //or
> db.shutdownServer({force : true , timeoutsec : 5})

1 Several startup methods of mongodb

  There are two ways to start the Mongodb service: foreground startup or Daemon startup. The former requires that the current session cannot be closed, and the latter can be executed as the fork process of the system. The path below is the actual address of the mongodb deployment.
 

 1. The easiest way to start is to start in the foreground, only specify the data directory, and use the default port 27107. You can directly use ./mongo to connect to the local mongodb under the cli, which is generally only used for temporary development and testing.

1
. /mongod  --dbpath= /path/mongodb

2. Start to bind a fixed IP address and port, so mongo needs to specify the IP and port when connecting to mongod.

 

1
. /mongo  10.10.10.10:12345 

 

 3. The daemon runs in the background, simply add "&" after the command.

 

1
. /mongod  --dbpath= /path/mongodb  --bind_ip=10.10.10.10 --port=12345 & 

Or use the --fork parameter that comes with mongod, in which case the log path must be specified.

1
. /mongod  --dbpath= /path/mongodb  --fork= true  logpath= /path/mongod .log 

   4. (Recommended) Save the configuration as a configuration file.

copy code
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  
copy code

Then import the configuration file when starting mongod: ./mongod -f /path/mongod.conf  

The following is a detailed description of common parameters for mongod startup:
parameter illustrate Value example
dbpath mongodb data file storage path /data/mongodb
logpath mongod log path /var/log/mongodb/mongodb.log
logappend log uses append instead of overwrite true
bind_ip bind IP 10.10.10.10
port bind port 27107
journal The write operation first writes the "journal", which is a data security setting. Please refer to the official documentation for details. true

5 MongoDB startup

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 mongodb

1 Foreground run:

If --fork is not used, the terminal can be closed directly from the foreground.
In this way, Mongodb will clean up and exit by itself, write the unwritten data, and finally close the data file.
Note that this process continues until all operations are complete.
 

2 run in the background:

If --fork is used to run the mongdb service in the background, it must be shut down by sending a shutdownServer() message to the server.
 
1. Common command:
$ ./mongod
> use admin
> db.shutdownServer() It
should be noted that this command is only allowed locally, or an authenticated client
2. If this is a master-slave replication cluster, after version 1.9.1, the following steps will be followed to close it
. Check the data update time
of the slave Mongodb. close mongodb
(In this case, we can configure timeoutSecs to complete the data update from Mongodb)
If one of the slave Mongodb and the master service time difference is within 10 seconds, then the master server will shut down and wait for the update from Mongodb Done and close.
 
3. If there is no up-to-date from Mongodb and you want to force shut down the service, you can add force:true; the command is as follows:
> db.adminCommand({shutdown : 1, force : true})
> //or
> db. shutdownServer({force : true})
 
4. Specify a specific timeout to shut down the server. The command is the same as above, plus a timeoutsec: parameter
> db.adminCommand(shutdown : 1, force : true, timeoutsec : 5)
> //or
> db.shutdownServer({force : true , timeoutsec : 5})

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325327348&siteId=291194637