1: Start and stop MongoDB
1) Start the execution mongod from the command line, start the MongoDB server, Mongod has a lot of configurable boot options, you can use
Mongod--help See all options
--dbpath:Specify the data directory, the default is/data/db, each mongod process requires a separate data directory, add 3 Mongod instances, you must have 3 separate data directories. When Mongod is started, the Mongod.lock file is created in the data directory. This file is used to prevent other mongod processes from using the data directory. If you have a mongd boot, and then start another mongod, if you use a directory that has just started Mongod, you will get an error:
- -06t16:09.703+0800in98file: mongodb/0706/mongod.lock Resource temporarily unavailable. is a Mongod instance already running?, terminating
--port:Specifies the port number that the server listens on. The default port number is 27017, if you run more than one mongod, you must specify a different port number if a 27017 of the ports are already in use, then if you start the second Mongod, if you specify 27017, you will get an error:
- -06t16::07.215+0800in for0.0. 0.0:27017
--fork:Run MongoDB as a daemon, create a service process, equivalent to nohup ... &
Nohup mongodb/bin/mongod--dbpath mongodb/0706 &
And
Mongodb/bin/mongod--dbpath mongodb/0706
The same effect
--logpath:Specifies the path of the output log, not the output to the command line. If the folder has write permissions, it is created when the file does not exist. It will already have the file overwritten, clearing all the original log records. If you want to keep the original log, you also need to use
--logappend
--config:Specify a configuration file to load various options not specified by the command line
--directoryperdb:
Use this parameter to store each database in a separate directory for example, if I create a new two database, a folder with the same database name will be created automatically in the Data directory.
When you start the database, MongoDB writes a file to the Startup_log collection of the local database, which contains the version of MongoDB, the system on which it is based, and so on.
>Use local switched to DB local>Db.startup_log.findOne () {"_id":"vst2-1499343744092", "hostname":"Vst2", "StartTime": Isodate ("2017-07-06t12:22:24z"), "starttimelocal":"Thu Jul 6 20:22:24.092", "CmdLine" : { "Storage" : { "DbPath":"mongodb/0707", "Directoryperdb":true } }, "PID": Numberlong (15613), "Buildinfo" : { "version":"3.4.5", "gitversion":"520b8f3092c48d934f0cd78ab5f40fe594f96863", "Modules" : [ ], "Allocator":"Tcmalloc", "Javascriptengine":"Mozjs", "SysInfo":"deprecated", "Versionarray" : [ 3, 4, 5, 0 ], "OpenSSL" : { "Running":"OpenSSL 1.0.1f 6 Jan", "compiled":"OpenSSL 1.0.1f 6 Jan" }, "buildenvironment" : { "Distmod":"ubuntu1404", "Distarch":"x86_64", "cc":"/OPT/MONGODBTOOLCHAIN/V2/BIN/GCC:GCC (gcc) 5.4.0", "Ccflags":"-fno-omit-frame-pointer-fno-strict-aliasing-ggdb-pthread-wall-wsign-compare-wno-unknown-pragmas- Winvalid-pch-werror-o2-wno-unused-local-typedefs-wno-unused-function-wno-deprecated-declarations- WNO-UNUSED-BUT-SET-VARIABLE-WNO-MISSING-BRACES-FSTACK-PROTECTOR-STRONG-FNO-BUILTIN-MEMCMP", "cxx":"/opt/mongodbtoolchain/v2/bin/g++: g++ (GCC) 5.4.0", "Cxxflags":"-woverloaded-virtual-wno-maybe-uninitialized-std=c++11", "Linkflags":"-pthread-wl,-z,now-rdynamic-wl,--fatal-warnings-fstack-protector-strong-fuse-ld=gold-wl,--build-id-wl,-z, NOEXECSTACK-WL,--Warn-execstack-wl,-z,relro", "Target_arch":"x86_64", "Target_os":"Linux" }, "bits": -, "Debug":false, "maxbsonobjectsize":16777216, "Storageengines" : [ "Devnull", "ephemeralfortest", "Mmapv1", "Wiredtiger" ] } }
By default, a basic HTTP server is also started when you start Mongod, which listens for a port number that is 1000 larger than the port number of the primary service. This service provides an HTTP interface to view some basic information about MongoDB. This information can also be viewed through the shell. For example, you start the default port 27017, then the browser opens http://10.0.0.13:28017 but you may not open it, because the default management interface is closed, so at the time of startup with the open management interface parameters
--httpinterface,
mongodb/bin/mongod--dbpath mongodb/0706--fork--logpath 0706.log-- Httpinterface
When you go in, it's like, say your parameters are not open, so when you start to add
--rest parametersPlus the parameter restarts, you can see that there is more information 2): Configuration file MongoDB supports reading the configuration file from a file. Specifies that the configuration file can be used-
F and
--config options
2: Stop MongoDBMethod One: View the process, using the KILL command;
cannot use kill-9
Method Two: Go in the client, use the shutdown command
> Use admin;switched to DB admin> db.shutdownserver (); server should is down ...
When you run the shutdown command on the primary node (primary), the server waits for the backup node to catch up with the primary node before it shuts down to maintain synchronization. This minimizes the likelihood of rollback, but the shutdown operation has the possibility of failure. If no backup nodes are successfully synchronized in a few seconds, the shutdown operation fails and the primary node does not stop running.
3: LogWhen starting Mongod, you can specify the level of the log (-V,-VV,-VVV,-VVVV,-VVVVV) or execute command modifications at the shell command line
Mongodb/bin/mongod--dbpath mongodb/0707
The larger the log level, the more verbose the output log to 5 o'clock, when Mongod records almost all operations in the log, including what is processed by each request. MongoDB default records take more than 100 milliseconds of query information. If the 100 millisecond is not suitable for the requirement, it can be changed by the Setprofilinglevel command, which indicates a message that records the query time more than 500 milliseconds
> Db.setprofilinglevel (1,+) "was"0" slowms"OK"1 }
If you want log splitting, such as storing by day, there are two ways
Method One: execute the
KILL-USR1 process number periodically every day, so that you can see that each time the KILL-USR1 process number is executed, a log file is regenerated
method Two: Execute in the shell line of MongoDB, each execution will produce a new log file
> Db.admincommand ({"logRotate":1}) "OK " 1 }
For the split log to take effect, you must start using the
--logpath, then you can write a shell or Python script according to your needs, and then crontab into a timed task
MongoDB start-Up and stop