Start and Stop the mongodb database.

Source: Internet
Author: User
Tags sigint signal stop script

Start and Stop the mongodb database.
The start and stop of the zookeeper database is the most basic operation of the database and the prerequisite for the database to provide services and be connected to and managed. There are some differences between the start and stop methods of different databases, but there are also some similarities. The Start and Stop methods are also related to the database process.
In the oracle database, the start and stop of the database are divided into three processes. The normal start method is to execute the startup command in sqlplus to start, or shutdown the immediate command to close the database; in some special cases, the database is forced to be shut down by shutdown abort or kill background processes;
In a MySQL database, the database is started by running the mysqld or mysqld_safe command and the configuration file. When you close the database, run the command mysqladmin and shutdown to shut it down; by verifying that the kill process is the same as the shutdown command, you can also disable mysql through the kill process;

To start and stop a MongoDB database, you can use the following method:
Start MongoDBGo to MongoDB installation directory # cd mongodb-linux-x86_64-2. *. * execute the following command to start MongoDB # ./Bin/mongod -- port 33334 -- fork -- logpath data/log/mongodb. log -- dbpath data/dbThe startup parameters are described as follows: -- port Start port number -- fork is started in daemon mode -- logpath mongodb log output path -- dbpath mongodb data file path other options can be run to view :. /bin/mongod -- help
Operation Demonstration:Write the MongoDB Startup File: vim start. sh script content is as follows: cd mongodb-linux-x86_64-2 .*.*
./Bin/mongod -- port 33334 -- fork -- logpath data/log/mongodb. log -- dbpath data/db
Stop script start: chmod + x start. sh. /start. sh execution results show start sucessful, indicating that mongod is started successfully. You can confirm the MongoDB startup process in the following two ways: Confirm process: $ ps-axu | grep mongo validation log: cd/data/logtail-f mongodb. log

Stop MongoDB process safelySend a signal to the MongoDB process to stop MongoDB. If you want to stop MongoDB safely, there are two signals: sigint signal, or how the sigterm signal stops: $Kill-2 8888Where 8888 is the mongod process number, which can be obtained through ps-axu | grep mongo;-2 indicates that the sigint signal is sent to the mongod process $Kill-4 8888Where 8888 is the mongod process number, which can be obtained through ps-axu | grep mongo;-4 indicates that the sigterm signal is sent to the mongod process.
In the above two ways, how to stop the secure mongod process from receiving the sigint or sigterm signal will do some processing: Close all open connections; force refresh the memory data to the disk; the current operation is completed ;.... Stop Security
In addition to the above two stop methods for processes, there is also a safe stop method using the mongod command shutdown:>Use admin;-- Use the administrator database>Db. shutdownServer ();
Unsafe stop methods include:: $ Kill-9 8888 where 8888 is the mongod process number, which can be obtained through ps-axu | grep mongo;-9 indicates that the sigkill signal is sent to the mongod process, and MongoDB stops directly, no relevant processing will be performed; the database is closed directly; data loss; data files are damaged; the database is repaired (high cost and risky)
From the above analysis, we can see that the MongoDB startup process is similar to that of other databases. It mainly checks the consistency of database files and generally does not pose too many risks, as long as the database can be started properly; to stop MongoDB, run the shutdown command in the mongo tool to stop it. Alternatively, you can use kill-2 after querying the MongoDB process number, kill-4 implements the same security stop mode. If kill-9 is used for MongoDB, it is an insecure stop mode, which may cause various problems; the difference between secure stop and unsafe stop is that after the secure Stop command is issued, the database performs a series of operations in the background to ensure that the database is eventually shut down in a consistent manner; however, if it is an insecure stop, the database process does not exist directly, and the database will no longer perform a series of operations in the background to ensure consistency close. At the next startup, various problems may occur.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.