MongoDB Open and close

Source: Internet
Author: User
Tags mongodb

Click to open the link


the opening of the MongoDB
Default startup:
$./mongodb
Default data Save path:/data/db/default port: 27017
To Modify the default path:
--dbpath $./mongdb--dbpath/mongodb/points The data storage location to a directory of its own/mongodb/
To Modify the default port:
--port $./mongdb--port 20111 modifies the service port to 20111, which is for security, and uses the default port easily to be found by malicious people.
To start the background service:
--fork in the background to open the MONGDB service in this way to start with the attention of two points: 1, the function is only after 1.1 version can be used. 2, another way to start in the background, if the start of the time like--dbpath use--logpath output log when the log output directory to create their own. such as: $./mongod--fork--logpath/var/log/mongodb.log--logappend parse the last--logappend, create the log in an append way to prevent the previous log from being deleted

MongoDB shutdown:
Front Run:
If the--fork is not used, the front end can exit the terminal shutdown. In this way, MongoDB will do a clean exit by itself, write the unfinished data and eventually close the data file. Note that this process lasts until all operations are completed.
Background run:
If you use--fork to run the MONGDB service in the background, you should close by sending a shutdownserver () message to the server.
1. General Order: $./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, the 1.9.1 version will be followed by the following steps to turn off checking data update from MongoDB If all the time difference from MongoDB and master is over 10, this time does not close MongoDB (in this case, We can configure Timeoutsecs to get updates from MongoDB, if one of them has a time difference from the MongoDB to the main service in 10 seconds, then the primary server shuts down and waits for the update from MongoDB to complete and close. 3. If there is no up-to-date from MongoDB and you want to force off the service, you can add force:true by adding the command as follows: > Db.admincommand ({shutdown:1, force:true}) >//or &G T Db.shutdownserver ({force:true})
4, specify a specific timeout time of the shutdown server, the command ibid., plus a timeoutsec: Parameters > Db.admincommand (shutdown:1, Force:true, Timeoutsec:5) >//or > Db.shutdownserver ({force:true, timeoutsec:5})


MongoDB Boot
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 &


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.