Start and stop of MongoDB database

Source: Internet
Author: User
Tags sigint signal

Starting and stopping the database is the most basic operation of the database, and it is also a precondition for the database to provide service and be connected to management. There are some differences in the way the database starts and stops, but there are similarities, and startup and shutdown are bound to be related to the database process.


In the Oracle database, the start and stop of the database are divided into three processes, the normal starting method is to execute the startup command in Sqlplus, or shutdown immediate command to close the database;

In some special cases, the database is forced to be closed by shutdown abort or kill daemon;


In the MySQL database, the startup of the database is also started by mysqld or MYSQLD_SAFE command plus configuration file, closed with the command of the Mysqladmin tool plus shutdown option to close the MySQL database normally;

By confirming that the kill process is the same as the shutdown command, the shutdown of MySQL can also be achieved by means of the kill process;



For the start and stop of MongoDB database, the following methods can be studied:


Start MongoDB

Go to the 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/db

Instructions for starting the relevant parameters are as follows:

--port Boot port number

--fork start up in daemon mode

--logpath MongoDB Log Output path

--dbpath MongoDB Data File path

Additional options to perform the command view:./bin/mongod--help


Operation Demo:

To write a MongoDB startup file:

The VIM start.sh script reads as follows:

CD Mongodb-linux-x86_64-2.*.*

./bin/mongod--port 33334--fork--logpath data/log/mongodb.log--dbpath data/db

To stop the script from starting:

chmod +x start.sh

./start.sh

The execution results appear in Start sucessful, which indicates that the MongoDB boot process can be confirmed in the following two ways: Mongod start-up is complete.

Confirmation Process:

$ Ps-axu | grep MONGO

Confirmation log:

Cd/data/log

Tail-f Mongodb.log



Secure Stop MongoDB Process

Send a signal to the MONGODB process to stop MongoDB, if you want to safely stop can have two kinds of signals: SIGINT signal, or sigterm signal

How to stop:

$ kill-2 8888

Where 8888 is the Mongod process number, which can be obtained through Ps-axu |grep MONGO;

-2 means sending SIGINT signal to the Mongod process

$ kill-4 8888

Where 8888 is the Mongod process number, which can be obtained through Ps-axu |grep MONGO;

-4 means sending sigterm signal to the Mongod process



Top 2 ways to stop security

Mongod process receives SIGINT signal or sigterm signal, will do some processing:

Close all open connections;

Forcing the memory data to be flushed to disk;

The execution of the current operation is complete;

。。。。

Safe stop


In addition to the above two methods of stopping directly against the process, there is a safe stop mode using the Mongod command shutdown:

>  Use admin; --Using the Administrator database

> db.shutdownserver ();


Unsafe to stop the way there are :

$ kill-9 8888

Where 8888 is the Mongod process number, which can be obtained through Ps-axu |grep MONGO;

9 means to send the sigkill signal to the mongod process, MongoDB directly stop, will not do some related processing;

database is closed directly;

Data loss;

Data file corruption;

Repair Database (high cost, risk)


Through the above analysis can be seen, MongoDB startup process and other databases are similar, mainly to verify the consistency of database files, generally there is not too much risk, as long as the database can start normally;

For MongoDB stop, you can safely stop by the shutdown command in the MONGO tool, or you can use kill-2,kill-4 two ways to achieve the same security stop mode after querying to the MongoDB process number;

If kill-9 is used for MongoDB, it is an unsafe way to stop, which may cause various problems;

The difference between safe stop and unsafe stop is that the security stops after the Stop command is issued, the database will perform a series of operations in the background to ensure that the database is finally consistent close;

But if it is not safe to stop, then the database process directly did not, the database will not do a series of operations in the background to ensure consistency shutdown, the next time you start, there may be a variety of problems.



Start and stop of MongoDB database

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.