In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. The startup of Mongod
1.1.Boot options for Mongod
Mongod has many configurable options. Run mongod-- help on the command line to see all the options. The common options are as follows:
The serial number option means that 1--dbpath specifies the data directory, and the default value is / data/db (C:\ data\ db under Windows). Each mongod process requires a separate data directory, so if you have three instances of mongod, you must have a separate data directory. When mongod starts, a mongod.lock file is created in the data directory, which is used to prevent other mongod processes from using the data directory, which contains the pid number of the mongod thread. 2--port specifies the port number that the server listens to. The default port number is 27017, which is not used by other processes. If you are running multiple mongod processes, you should give each process that specifies a different port number 3--fork to run Mongod as a daemon, and create the server process 4--logpath to specify the log output path, rather than output to the command line, if you have write permission to the folder. The system creates a file when it does not exist. It will overwrite the existing files, clear all the original log records, and use the-- logappend option if you want to keep the original logs.
5--config specifies the configuration file and loads various options that are not specified on the command line. 6--httpinterface enables http interface
Example 1: view the process
[root@gflinux102 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/mongodb.log
[root@gflinux102 data] # cat mongod.lock
3620
[root@gflinux102 data] #
Example 2: check the port number
[root@gflinux102 data] # netstat-ntlp | grep 27017
[root@gflinux102 data] # netstat-ntlp | grep 10001
Tcp 00 0.0.0.0 10001 0.0.0.015 * LISTEN 3620/mongod
[root@gflinux102 data] #
Root@gflinux102 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 32 bit MongoDB binary.
2015-02-10T14:05:14.531+0800 [initandlisten] * 32 bit builds are limited to less than 2GB of data (or less with-- journal).
2015-02-10T14:05:14.531+0800 [initandlisten] * * Note that journaling defaults to off for 32 bit and is currently off.
2015-02-10T14:05:14.531+0800 [initandlisten] * * See http://dochub.mongodb.org/core/32bit
Startup example:
[root@gflinux102 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 have journaling enabled by default. Please use-- journal if you want durability.
2015-02-10T14:05:14.517+0800
Under 32bit, mongod can only process 2Gb data, so pay attention to the machines that use 64bit in production.
Configuration file for 1.2MongoDB
MongoDB supports getting configuration information from files. This is used when you need a lot of configuration or when you want to automate operations and maintenance, and specify that the configuration file can be configured with the-f or-- config option.
[root@gflinux102 logs] # mongod-- help | grep "- f"
-f [--config] arg configuration file specifying additional options
[root@gflinux102 logs] #
Example:
Mongod-config ~ / .mongodb.conf
The configuration file template is as follows, note that this is manually edited:
[root@gflinux102 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 have journaling enabled by default. Please use-- journal if you want durability.
2015-02-10T15:06:28.200+0800
About to fork child process, waiting until server is ready for connections.
Forked process: 3854
Child process started successfully, parent exiting
[root@gflinux102 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 value of the switch options such as-- fork on the command line should be set to true.
1.3.stop MongoDB
1.3.1 the foreground process is running in an interrupt
If the server process runs on the terminal as a foreground process, CTL-C directly.
1.3.2kill kills
[root@gflinux102 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 look at pid like this:
[root@gflinux102 bin] # cat / opt/mongo/data/mongod.lock
3854
Kill process:
[root@gflinux102 bin] # kill `cat / opt/mongo/data/ mongod.lock` (SIGTERM)
[root@gflinux102 bin] # kill-2 `cat / opt/mongo/data/ mongod.lock` (SIGINT)
When mongod receives SIGINT or SIGTERM, it exits safely, that is, it waits until the currently running operation or file pre-allocation is completed (it will take some time), closes all open connections, flushes the cached data to disk, and finally stops.
[prohibit]: never send SIGKILL (kill-9) to a running mongodb, which will cause the database to shut down directly and may damage the data file.
1.3.3 use the shutdown command
Use the shutdown command, {"shutdown": 1}. This is to be used in an admin database, and shell provides helper functions to simplify the process.
[root@gflinux102 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 32 bit MongoDB binary.
2015-02-10T15:37:43.973+0800 [initandlisten] * 32 bit builds are limited to less than 2GB of data (or less with-- journal).
2015-02-10T15:37:43.973+0800 [initandlisten] * * Note that journaling defaults to off for 32 bit 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 be 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 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
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.