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 shut down the database, in some special cases, through the shutdown Abort or kill the background process to force the database to shut down;
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 MongoDBGo to the MongoDB installation directory # CDMongodb-linux-x86_64-2.*.*Execute the following command to start mongodb#
./bin/mongod --port 33334--fork--logpath data/log/mongodb.log--dbpath data/db The start-up parameters are described as follows:--port boot port number--fork boot--logpath mongodb log output path--dbpath MongoDB data file path Other options can be executed by 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.shThe execution results appear start sucessful, indicating that the Mongod start is complete, you can confirm the MongoDB boot process in the following two ways: Confirmation process: $ Ps-axu | grep MONGO Confirmation log: Cd/data/logtail-f Mongodb.log
Secure Stop MongoDB processSend a signal to the MONGODB process to stop MongoDB, if you want to safely stop can have two signals: SIGINT signal, or how to stop the sigterm signal: $
kill-2 8888 Where 8888 is the Mongod process number, which can be obtained through Ps-axu |grep MONGO, 2 means sending a mongod signal to the SIGINT process $
kill-4 8888Where 8888 is the Mongod process number, which can be obtained through Ps-axu |grep MONGO, 4 means sending a mongod signal to the sigterm process
The above 2 ways to stop the security Mongod process received SIGINT signal or sigterm signal, will do some processing: Close all open connections, the memory data forced to flush to disk, 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, the process number can be obtained through Ps-axu |grep MONGO, 9 means sending a mongod signal to the Sigkill process, MongoDB stops directly and does not do some related processing; the database shuts down directly; Data loss, data file corruption, database repair (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 implement the same safe stop mode after querying to the MongoDB process number, which is an unsafe way to stop if you use kill-9 with MongoDB , which may cause problems, and the difference between safety stop and unsafe stop is that the security stops after the Stop command is issued, the database in the background will be a series of operations to ensure that the database is eventually a consistent shutdown, but if it is not safe to stop, the database process directly does not, the database will not do a series of operating in the background To ensure that the consistency is closed, the next time you start, you may have a variety of problems.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Start and stop of MongoDB database