"Go" MongoDB configuration file description

Source: Internet
Author: User
Tags auth syslog server port

There are 2 ways to start MongoDB, one is to directly specify the configuration parameters, and the other is to specify the configuration file. Here we first introduce the configuration file, the startup method is as follows:

mongod --config /etc/mongodb.conf
The configuration is as follows:

verbose: Log information is redundant. The default is false. Increase the standard output of internal reports or log to the log file of the logpath configuration. To enable verbose or enable verbosity use vvvv parameters, such as:

verbose = true
vvvv = true
ps: start verbose verbose information, its level is vv ~ vvvvv, the more v the higher the level, the more detailed the information recorded in the log file

port: port. The default is 27017, the default service TCP port of MongoDB, listening for client connections. If the port setting is less than 1024, such as 1021, you need root permission to start, you can not start with the mongodb account, (ordinary account can not get up even if it is 27017) Otherwise, an error is reported: [mongo --port = 1021 connection]

ERROR: listen (): bind () failed errno: 13 Permission denied for socket: 127.0.0.1:1021
port = 27017
bind_ip: bind address. The default is 127.0.0.1, which can only be connected locally. The process binds and listens for application connections from this address. If you need to connect to other servers, you need to comment out this or change the IP to the machine address, such as 192.168.200.201 [other servers use mongo --host = 192.168.200.201 to connect], you can use a comma-separated list to bind Multiple IP addresses.

bind_ip = 127.0.0.1
maxConns: Maximum number of connections. Default value: depends on the system (ie ulimit and file descriptor) limits. MongoDB does not limit its own connections. When the setting is greater than the system limit, it is invalid, and the system limit shall prevail. This is useful when the client creates many "tables", allowing connections to time out without closing the "tables". Set this value higher than the size of the connection pool and the total number of connections to prevent connections during spikes. Note: The value cannot be set greater than 20000.

maxConns = 100
objcheck: Force verification of client requests. The default setting for 2.4 is that objcheck becomes true, and in earlier versions objcheck defaults to false. Because it forces verification of client requests, it ensures that clients never insert invalid files into the database. For objects with nested documents, there is a little performance impact. Set noobjcheck off.

objcheck = true
#noobjcheck = false
noobjcheck: Same as above, false is disabled by default.

#noobjcheck = false
logpath: Specifies the log file, which will save all log records and diagnostic information. Unless otherwise specified, mongod outputs all log information to standard output. If logappend is not specified, the log will be overwritten upon restart.

logpath = / var / log / mongodb / mongodb.log
logappend: write log mode: set to true to append. The default is overwrite. If this setting is not specified, MongoDB will overwrite the existing log files at startup.

logappend = true
syslog: The log output is sent to the syslog system of the host, instead of the standard output to the logpath specified log file. syslog and logpath cannot be used together, and an error will be reported:

Cant use both a logpath and syslog
syslog = true
pidfilepath: process ID, if there is no specified, there is no PID file at startup. Default default.

pidfilepath = /var/run/mongo.pid
keyFile: Specify the path of the key file that stores authentication information. Default default. See details: "

Replica Set Security "and" Replica Set Administration. "

keyFile = / srv / mongodb / keyfile
nounixsocket: socket file, the default is false, and socket files are generated. When set to true, no socket file will be generated.

nounixsocket = false
unixSocketPrefix: Socket file path, default / tmp

unixSocketPrefix = / tmp
fork: Whether to run in the background, set to true to start the daemon mode in which the process runs in the background. The default is false.

fork = true
auth: User authentication, default false. No authentication is required. When set to true, auth authentication is required to enter the database. When there are no users in the database, you can operate without authentication. Until the first user is created, subsequent operations require authentication.

auth = true
For example: create a super user under the admin library through db.addUser ('sa', 'sa'), only authenticated under the admin library: ab.auth ('sa', 'sa') Go to another library to operate, can not be verified in other libraries. To connect to the database, you also need to specify the library:

mongo -usa -psa admin #sa account to connect to admin
mongo -uaa -paa test #aa account connection test
noauth: Disable user authentication, the default is true. Same as above

noauth = true
cpu: set to true will force mongodb to report cpu utilization and io wait every 4s and write log information to standard output or log file. The default is false.

cpu = true
Open the log will appear:

Mon Jun 10 10: 21: 42.241 [snapshotthread] cpu: elapsed: 4000 writelock: 0%
dbpath: data storage directory. Default: / data / db /

dbpath = / var / lib / mongodb
 diaglog: Create a very detailed troubleshooting and diagnostic log record of various errors. The default is 0. Set to 1, in order to generate a log file starting with diaglog. In the dbpath directory, his values are as follows:

Value Setting
0 off. No logging. #Off. No record.
1 Log write operations. #Write operations
2 Log read operations. # 读 操作
3 Log both read and write operations. #Read and write operations
7 Log write and some read operations. #Write and some read operations
If the setting is not equal to 0, the log will be flushed every minute:

Mon Jun 10 11: 16: 17.504 [DataFileSync] flushing diag log
Mon Jun 10 11: 17: 17.442 [DataFileSync] flushing diag log
The generated logs can be viewed with mongosniff: if mongosniff [similar to tcpdump's specific TCP / IP network traffic as a MongoDB] has errors and specific usage, please see here, before executing: apt-get install libpcap-dev

[email protected]: / var / lib / mongodb # mongosniff --source DIAGLOG diaglog.51b542a9
Note: When reset to 0, writing to the file will stop, but mongod still keeps opening the file, even if it no longer writes to the data file. If you want to rename, move or delete diagnostic logs, you must shut down the mongod instance completely.

diaglog = 3
directoryperdb: Set to true to modify the data directory storage mode. The files of each database are stored in different folders in the directory specified by DBPATH. With this option, MongoDB can be configured to store data on different disk devices to improve write throughput or disk capacity. The default is false.
Note: If this parameter is turned on in a database that has been running for a period of time, the original data will disappear (note the parameter will return) Because the data directories are different, unless you migrate the existing data files to the database directory generated by directoryperdb, such as:
[email protected]: / var / lib / mongodb # mv test. * test /
Migrate the test data file to the database test directory generated by directoryperdb. Therefore, it is necessary to determine whether to open it after planning.

directoryperdb = ture
Original data structure:
journal
mongod.lock
local.0
local.1
local.ns
test.0
test.1
test.ns

Open directoryperdb, and migrate the data file to the relevant data directory structure:

journal
mongod.lock
local / local.0
local / local.1
local / local.ns
test / test.0
test / test.1
test / test.ns
journal: log, (redo log, please see here and here for more introduction)
Default value: (On 64-bit systems) true.
Default value: (32-bit system) false.
Set to true to enable operation logs to ensure write durability and data consistency. The journal directory will be created under the dbpath directory.
Set to false to prevent log persistence without overhead. To reduce the impact of the logs used on the disk, you can enable nojournal and set it to true.
Note: Disable logging on 64-bit systems must use the one with nojournal.

# journal = true
journal = false
32-bit OS:

Tue Jun 11 12: 17: 09.628 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
Tue Jun 11 12: 17: 09.628 [initandlisten] ** 32 bit builds are limited to less than 2GB of data (or less with --journal).
64-bit OS:

Tue Jun 11 12:29:34 [initandlisten] journal dir = / var / lib / mongodb / journal
Tue Jun 11 12:29:34 [initandlisten] recover: no journal files present, no recovery needed
nojournal: disable logging
Default value: (On 64-bit system) false.
Default value: (32-bit system) true.
Set nojournal to true to turn off logging, 64-bit, mongodb after version 2.0 enables journal logging by default.

nojournal = true
journalCommitInterval: Flash submission mechanism, the default is 30ms or 100ms. Lower values will consume disk performance more.
This option accepts values between 2 and 300 milliseconds:
If a single device provides logs and data files, the default diary submission interval is 100 milliseconds.
If logs and data files are provided by different block devices, the default time interval for diary submission is 30 milliseconds.

journalCommitInterval = 100
ipv6: Whether to support ipv6, the default is false.

jsonp: Whether to allow JSONP access through an HTTP interface, the default is false.

nohttpinterface: Whether to prohibit the http interface, that is, the service enabled on port 28017. Default false, support.

nohttpinterface = false
noprealloc: pre-allocation method.
Default false: pre-allocation is used to ensure the stability of write performance, pre-allocation is performed in the background, and each pre-allocated file is filled with 0. This will allow MongoDB to always maintain additional space and free data files, thereby avoiding the blockage caused by the disk space allocation caused by the rapid growth of data.
Setting noprealloc = true to disable pre-allocated data files will shorten the startup time, but during normal operation, it may cause significant performance degradation.

noprealloc = false
noscripting: Whether to disable the script engine. The default is false: not prohibited. ture: prohibited
If set to true: it will appear when running some scripts:

JavaScript execution failed: group command failed: {"ok": 0, "errmsg": "server-side JavaScript execution is disabled"}
#noscripting = true <====> noscripting = false
notablescan: whether to prohibit table scan operations. Default false: not prohibited, ture: prohibited

Prohibited if you perform a table scan will appear:

error: {"$ err": "table scans not allowed: test.emp", "code": 10111}
The settings can be modified dynamically:

db.adminCommand ({setParameter: 1, notablescan: false})
#notablescan = true <====> notablescan = false
nssize: The default size of the namespace file (ie NS), default 16M, maximum 2G.
All newly created files of the default size namespace (ie NS). This option does not affect the file size of the existing namespace. The default value is 16M bytes and the maximum size is 2 GB. Let small databases not waste too much disk space, while allowing big data to have continuous space on disk.

-rwxrwxrwx 1 mongodb zhoujy 16M June 11 14:44 test.0
-rwxrwxrwx 1 mongodb zhoujy 32M June 1 21:36 test.1
-rwxrwxrwx 1 mongodb zhoujy 16M June 11 14:44 test.ns
drwxr-xr-x 2 root root 4.0K June 10 11:57 _tmp
nssize = 16
profile: Database analysis level setting. Record some operation performance to the standard output or the log file of the specified logpath, the default is 0: off.

Level Setting
0 off. No analysis.
1 open. Only slow operations are included.
2 open. Including all operations.
Switches and levels to control Profiling: 2 types
The first is to directly set in the startup parameters or add –profile = level when starting MongoDB, and the information is saved in the generated system.profile.

profile = 2
The second is to use the db.setProfilingLevel (level) command on the client to configure in real time, and the information is saved in the generated system.profile.

[initandlisten] creating profile collection: local.system.profile
> db.setProfilingLevel (2)
{"was": 0, "slowms": 100, "ok": 1}
> db.getProfilingStatus ()
{"was": 2, "slowms": 100}
By default, mongod disables analysis. Database analysis can affect the performance of the database because the analyzer must record and process all database operations. So just use dynamic modification when needed.

slowms: Records the time of slow queries for profile analysis. The default is 100 milliseconds. The same as above.

slowms = 200
> db.getProfilingStatus ()
{"was": 2, "slowms": 200}
quota: quota, default false. Whether to enable the limit to configure the maximum number of files in each database. When true, use quotaFiles to configure the maximum number of files.

quota = true
quotaFiles: the number of quotas. Limit the number of data files per database. This option requires quota to be true. The default is 8.

quotaFiles = 8
rest: Default is false, set to true to make a simple REST API.

rest = true
Set to true, after opening, MongoDB will open an HTTP protocol port by default to provide REST services (nohttpinterface = false), this port is your Server port plus 1000, which is 28017, the default HTTP port is the database status page, After opening, the commands in the Commands line of the web page can be clicked in). MongoDB's built-in REST does not support addition, deletion, or modification, nor does it support authorization authentication.
See here and here for details.
repair: repair database operation, the default is false.
When set to true, all databases are repaired after startup. It is best to set this option on the command line, not in the configuration file or control script. Such as:
Command line repair:

> db.repairDatabase (‘xxx‘)
{"ok": 1}
> db.repairDatabase ()
{"ok": 1}
Repair at startup:

repair = true
[email protected]: / var / log / mongodb # mongod --repair
Repair at startup, you need to close the journal, otherwise an error will be reported:

Ca n‘t specify both --journal and --repair options.
And at startup, after repairing by specifying the parameters in the control file and the parameters specified in the configuration file (see the log for repair information), you need to disable the repair parameter to enable mongodb.
Note: When mongod is repaired, all database files need to be rewritten. If you cannot run repair under the same account, you need to run chown to modify the permissions of the database file.

repairpath: repair path, the default is the _tmp directory under the dbpath path.

drwxr-xr-x 2 root root 4.0K June 11 20:23 _tmp
smallfiles: Whether to use smaller default files. The default is false, not used.
Set to true to use a smaller default data file size. Smallfiles reduces the initial size of data files and limits them to 512M. It also reduces the size of log files and limits them to 128M.
If the database is large and each holds a small amount of data, mongodb will create many files, which will affect performance.

smallfiles = true
syncdelay: The frequency of flashing data to the log, and operating the data through fsync. The default is 60 seconds.

syncdelay = 60
The default is fine, no setting is required. Will not affect journal files

Warning: If set to 0, SYNCDELAY will not synchronize to the memory mapped file on disk. On production systems, do not set this value.

sysinfo: system information, default false.

Set to true, mongod will diagnose the system related page size, number of physical pages, and the number of available physical pages will be output to standard output.

Tue Jun 11 21: 07: 15.031 sysinfo:
Tue Jun 11 21: 07: 15.035 page size: 4096
Tue Jun 11 21: 07: 15.035 _SC_PHYS_PAGES: 256318
Tue Jun 11 21: 07: 15.035 _SC_AVPHYS_PAGES: 19895
When the sysinfo parameter is turned on, only the above information will be printed, and the mongodb program will not be started. So you must turn off this parameter to start mongodb.

upgrade: upgrade. The default is false.
When set to true, specify DBPATH to upgrade the data format files on the disk to the latest version. Will affect database operations and update metadata. In most cases, this value does not need to be set.

traceExceptions: Whether to use internal diagnostics. The default is false.

traceExceptions = false
quiet: Quiet mode.

quiet = true
setParameter: new parameter of 2.4, specifying the startup option configuration. If you want to set multiple options, use a setParameter option to specify, you can see the parameters of setParameter here, please see here for details
Declare that setParameter is set in this file, using the following format:

setParameter = <parameter> = <value>
If syncdelay is set in the configuration file:

setParameter = syncdelay = 55, notablescan = true, journalCommitInterval = 50, traceExceptions = true
Replication Options
replSet: Use this setting to configure the replica set. Specify a copy set name as the parameter, all hosts must have the same name as the same copy set.

oplogSize: The maximum size of the specified copy operation log (OPLOG). The size of an OPLOG created by mongod is based on the maximum amount of free space. For 64-bit systems, OPLOG is usually 5% of available disk space.
Once mongod creates OPLOG for the first time, changing oplogSize will not affect the size of OPLOG.

fastsync: The default is false. Under the replica set, set to true to enable the slave replication service from a dbpath. The database of the dbpath is a snapshot of the master database and can be used to quickly enable synchronization, otherwise mongod will try to perform the initial synchronization. Note: If the data is not fully synchronized, mongod specifies fastsync is turned on, and the secondary or slave is permanently out of sync with the master, which may cause significant consistency problems.

replIndexPrefetch: New parameters appearing in version 2.2, the default is all. The values that can be set are: all, none, and _id_only. Can only be used in a replica set (replSet). By default, members of the secondary replica set will load all indexes into memory (related to operations prior to OPLOG). You can modify this behavior so that secondary will only load the _id index. Specify _id_ or none to prevent any index of mongod from loading into memory.

Master / Slave Replication: Master-slave replication related settings

master: The default is false. When set to true, the current instance is configured as the master instance.

master = true
slave: The default is false. When set to true, the current instance is configured as a slave instance.

slave = true
source: The default is empty, the format is: <host> <: port>. Used for replication of slave instances: Specifying this option when setting slave will make slave replication specify the master instance

source = 127.0.0.1:30001
only: The default is empty. It is used to select a database to copy from the options.

only = abc #Only synchronize abc collection (library)
slavedelay: Set the delay time of the slave library to synchronize the master library, used for slave settings, the default is 0.

slavedelay = 60 # delay 60s to synchronize master data
autoresync: The default is false, used for slave settings. Whether to automatically resynchronize. Set to true, if it is more than 10 seconds behind the master, it will force the slave to automatically resynchronize. If oplogSize is too small, there may be a problem with this setting. If the OPLOG size is not enough to store the difference between the master's changed state and the slave's changed state, forced resynchronization in this case is not necessary. When the autoresync option is set to false, there will never be more than 1 automatic resynchronization in 10 minutes.

autoresync = false
[Switch] MongoDB configuration file description 

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.