1 Several startup methods of mongodb
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.
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
Then import the configuration file when starting mongod: ./mongod -f /path/mongod.conf
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:
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.$ ./mongod
> use admin
> db.shutdownServer() It
should be noted that this command is only allowed locally, or an authenticated client
. Check the data update time
of the slave Mongodb. close 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.
> db.adminCommand({shutdown : 1, force : true})
> //or
> db. shutdownServer({force : true})
> db.adminCommand(shutdown : 1, force : true, timeoutsec : 5)
> //or
> db.shutdownServer({force : true , timeoutsec : 5})
1 Several startup methods of mongodb
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.
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
Then import the configuration file when starting mongod: ./mongod -f /path/mongod.conf
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:
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.$ ./mongod
> use admin
> db.shutdownServer() It
should be noted that this command is only allowed locally, or an authenticated client
. Check the data update time
of the slave Mongodb. close 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.
> db.adminCommand({shutdown : 1, force : true})
> //or
> db. shutdownServer({force : true})
> db.adminCommand(shutdown : 1, force : true, timeoutsec : 5)
> //or
> db.shutdownServer({force : true , timeoutsec : 5})
1 Several startup methods of mongodb
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.
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
Then import the configuration file when starting mongod: ./mongod -f /path/mongod.conf
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:
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.$ ./mongod
> use admin
> db.shutdownServer() It
should be noted that this command is only allowed locally, or an authenticated client
. Check the data update time
of the slave Mongodb. close 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.
> db.adminCommand({shutdown : 1, force : true})
> //or
> db. shutdownServer({force : true})
> db.adminCommand(shutdown : 1, force : true, timeoutsec : 5)
> //or
> db.shutdownServer({force : true , timeoutsec : 5})