MongoDB start-Up and stop

Source: Internet
Author: User
Tags dochub

1, the start of Mongod

1.1. Mongod Startup options

Mongod has a number of configurable options, run Mongod--help on the command line to see all the options, and the common options are as follows:


Serial number Options Meaning
1 --dbpath Specifies the data directory, the default value is/data/db (Windows is C:\data\db). Each mongod process requires a separate data directory, so if you have 3 instances of Mongod, you must have a separate data directory. When Mongod is started, the Mongod.lock file is created in the data directory, which is used to prevent other mongod processes from using the data directory, and its file content is the PID number of the Mongod thread.
2 --port Specify the port number that the server listens on, the default port number is 27017, is not the other process of the use of the ports, if you run multiple Mongod process, you have to specify a different port number for each
3 --fork Run Mongod as a daemon to create a server process
4 --logpath Specifies the log output path, not the output to the command line, which is created when the file does not exist if the folder has write permissions. It overwrites existing files, clears all the original log records, and uses the--logappend option if you want to keep the original log.
5 --config Specifies a configuration file that loads various options that are not specified by the command line.
6 --httpinterface Enable HTTP interface



Example 1: Viewing a process

[Email protected] data]# ps-ef|grep-v grep |grep Mongod

Root 3620 2132 0 14:05 pts/1 00:00:00 mongod--port 10001--dbpath/opt/mongo/data/--logpath/opt/mongo/logs/mo Ngodb.log

[email protected] data]# cat Mongod.lock

3620

[Email protected] data]#

Example two: Viewing port numbers

[Email protected] data]# Netstat-ntlp|grep 27017

[Email protected] data]# Netstat-ntlp|grep 10001

TCP 0 0 0.0.0.0:10001 0.0.0.0:* LISTEN 3620/mongod

[Email protected] data]#

[Email protected] logs]# more Mongodb.log

2015-02-10t14:05:14.531+0800 [Initandlisten] MongoDB starting:pid=3620 port=10001 dbpath=/opt/mongo/data/32-bit Host =gflinux102

2015-02-10t14:05:14.531+0800 [Initandlisten]

2015-02-10t14:05:14.531+0800 [Initandlisten] * * Note:this is a A-bit MongoDB binary.

2015-02-10t14:05:14.531+0800 [Initandlisten] * * [Builds bit] is limited to less than 2GB of data (or less with--j ournal).

2015-02-10t14:05:14.531+0800 [Initandlisten] * * Note that the journaling defaults to off for the and is currently off .

2015-02-10t14:05:14.531+0800 [Initandlisten] * * See Http://dochub.mongodb.org/core/32bit

startup example:

[Email protected] bin]# mongod--port 10001--dbpath/opt/mongo/data/--logpath/opt/mongo/logs/mongodb.log

2015-02-10t14:05:14.516+0800

2015-02-10t14:05:14.517+0800 warning:32-bit servers don ' t has journaling enabled by default. Please use the--journal if you want durability.

2015-02-10t14:05:14.517+0800

At 32bit, Mongod can only process 2Gb of data, noting the production of the machine to use 64bit.

Configuration file for 1.2MongoDB

MongoDB supports obtaining configuration information from a file. This is used when there is a lot of configuration required or to automate operations, specifying that the configuration file can be used with the-F or--config option.

[Email protected] logs]# Mongod--help|grep "-F"

-F [--config] arg configuration file specifying additional options

[Email protected] logs]#

Example:

Mongod--config ~/.mongodb.conf

The profile template is as follows, note that this is manually edited:

[Email protected] bin]# mongod-f/opt/mongo/data/mongod.conf

2015-02-10t15:06:28.199+0800

2015-02-10t15:06:28.200+0800 warning:32-bit servers don ' t has journaling enabled by default. Please use the--journal if you want durability.

2015-02-10t15:06:28.200+0800

About-to-fork child process, waiting until server was ready for connections.

Forked process:3854

Child process started successfully, parent exiting

[Email protected] data]# VI mongod.conf

# Start MongoDB as a daemon on port 10001

Port = 10001

Fork = True

Logappend = True

DBPath =/opt/mongo/data

LogPath =/opt/mongo/logs/mongodb.log

Note: The switch options on the command line, such as--fork, have the value set to true.

1.3. Stop MongoDB

1.3.1 Foreground process running on interrupt

If the server process runs as a foreground process in the terminal, direct ctl-c.

1.3.2kill kills

[Email protected] bin]# ps-ef|grep-v grep |grep Mongod

Root 3854 1 0 15:06? 00:00:00 mongod-f/opt/mongo/data/mongod.conf

Or view the PID in this way:

[Email protected] bin]# Cat/opt/mongo/data/mongod.lock

3854

Kill Process:

[[email protected] bin]# kill ' Cat/opt/mongo/data/mongod.lock ' (SIGTERM)

[Email protected] bin]# kill-2 ' Cat/opt/mongo/data/mongod.lock ' (SIGINT)

When Mongod receives SIGINT or SIGTERM, it will safely exit, which will wait until the operation is currently running or the file is pre-allocated (it will take some time), close all open connections, flush the cached data to disk, and finally stop.

"Forbidden": Do not send Sigkill (kill-9) to a running MongoDB, which will cause the database to shut down directly and may corrupt the data file.

1.3.3 using the Shutdown command

Using the shutdown command, {"Shutdown": 1}. This is to be used under the Admin database, and the Shell provides helper functions to simplify the process.

[Email protected] bin]# MONGO localhost:10001

MongoDB Shell version:2.6.6

Connecting To:localhost:10001/test

Server has startup warnings:

2015-02-10t15:37:43.973+0800 [Initandlisten]

2015-02-10t15:37:43.973+0800 [Initandlisten] * * Note:this is a A-bit MongoDB binary.

2015-02-10t15:37:43.973+0800 [Initandlisten] * * [Builds bit] is limited to less than 2GB of data (or less with--j ournal).

2015-02-10t15:37:43.973+0800 [Initandlisten] * * Note that the journaling defaults to off for the and is currently off .

2015-02-10t15:37:43.973+0800 [Initandlisten] * * See Http://dochub.mongodb.org/core/32bit

2015-02-10t15:37:43.973+0800 [Initandlisten]

> Show DBS

Admin (empty)

Local 0.078GB

> Use admin

Switched to DB admin

> Db.shutdownserver ()

2015-02-10t15:39:04.616+0800 Dbclientcursor::init Call () failed

Server should is down ...

2015-02-10t15:39:04.624+0800 trying reconnect to localhost:10001 (127.0.0.1) failed

2015-02-10t15:39:04.626+0800 warning:failed to connect to 127.0.0.1:10001, reason:errno:111 Connection refused

2015-02-10t15:39:04.627+0800 Reconnect localhost:10001 (127.0.0.1) failed failed couldn ' t connect to server localhost : 10001 (127.0.0.1), connection attempt failed



MongoDB start-Up and stop

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.