MongoDB Open and close

Source: Internet
Author: User

MongoDB's Open  

Default startup:

$./mongodb Default data save path:/data/db/default port: 27017 To Modify the default path:  --dbpath$./mongdb--dbpath/mongodb/point the data storage location to a directory of your own/mongodb/ To Modify the default port:--port$./mongdb--port 20111 Change the service port to 20111, this is for security, using the default port is easy to be found by some malicious people to tamper with To start the background service:--fork in the background to open the MONGDB service in the use of this mode to pay attention to two points: 1, the function only after 1.1 version can be used. 2, in addition, this way in the background to start, if the start of the time like--dbpath when using the--logpath output log when the log output directory to create their own. such as: $./mongod--fork--logpath/var/log/mongodb.log--logappend Parsing finally--logappend, creating the log in an additional way prevents the previous log from being deleted MongoDB off: Front desk operation:If the--fork is not used, the front exit terminal can be turned off 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. running in the background:If you use--fork to run the MONGDB service in the background, you should close it by sending a shutdownserver () message to the server. 1, Ordinary 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 will be followed by the following steps 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 shutdown service, you can add force:true by adding the command as follows:> Db.admincommand ({shutdown:1, force:true}) >//or > Db.shutdownserver ({force:true}) 4, specify the shutdown server for a specific time-out, same as the command, plus a timeoutsec: Parameters > Db.admincommand (shutdown:1, Force:true, Timeoutsec:5) >//or> db.shutdownserver ({force:true, timeoutsec:5})

MongoDB boot upAdd 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 &

MongoDB Open and close

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.