MongoDB Study Notes (management basics)

Source: Internet
Author: User
Tags mongodb server pkill

1. Start and Stop MongoDB:

Run mongod to start the MongoDB server. Mongod has many configurable options. We can use mongod -- help to view all options. Here we only introduce some main options:
-- Dbpath:
By default, the data directory of the database is/data/DB. For Windows, if the current executable file is on disk D, the default data directory is D: \ data \ dB. We can use this option for service Program Re-specify the data directory. If the current host runs multiple sdks, you must specify different Data Directories for each service program, because after mongod is started successfully, a mongod is created under the Data Directory. lock file, which is used to prevent other mongod process data from the data directory. For example:
Mongod -- dbpath = D:/data2/DB

-- Port
The default port is 27017 by default. When multiple sdks run simultaneously on the same host, you must specify different listening ports for them. For example:
D -- Port = 29017

-- Fork
Run MongoDB as a daemon.

-- Logpath
Specify the log output path instead of the command line. If you have the write permission on the folder, the system creates it when the file does not exist. It overwrites existing files and clears all original log records. To retain the original log, you also need to use the -- logappend option. For example:
/> Mongod -- logpath = D: \ logdata \ mylog. Log
All output going to: D: \ logdata \ mylog. Log
Note that the logdata directory must be manually created in the previous example. Otherwise, mongod fails to start.

-- Config
Specifies the configuration file to load various options not specified by the command line. For example:
Mongod -- Config = D: \ mydb. conf
The sample content of the configuration file is as follows:
Port = 29017
Fork = true # Here, the well number indicates the comments part. For the fork command line option, you need to use True to enable it.
Logpath = D: \ mylog \ dB. Log

Generally, we want to gracefully disable the MongoDB server. If the service runs on the frontend, press Ctrl + C. If it is in the background, you can use the SIGINT and sigterm signals to notify the service program to prepare to exit. After receiving the signal, the server will properly arrange the data and status saving before exiting, for example: normally close the current connection and refresh the cached data to the disk. After all these tasks are completed, the server stops normally. For example:
/> Pkill mongod
/> Pkill-2 mongod
Do not directly execute the following command:
/> Pkill-9 mongod
This signal will force the MongoDB server to exit immediately.
In addition to the above methods, we can also use the Mongo client tool to notify the server to exit normally, such:
> Use Admin
Switched to DB Admin
> DB. shutdownserver ()

2. Server Status Monitoring:

C: \ mine \ thirdparty \ MongoDB \ bin> mongostat
Connected to: 127.0.0.1
Insert query update Delete getmore command flushes mapped vsize ......
0 0 0 0 1 0 m 100 m ......
0 0 0 0 1 0 m 100 m ......
0 0 0 0 1 0 m 100 m ......
0 0 0 0 1 0 m 100 m ......
0 0 0 0 1 0 m 100 m ......
0 0 0 0 1 0 m 100 m ......
0 0 0 0 1 0 m 100 m ......
0 0 0 0 1 0 m 100 m ......

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.