Before we know the Mongod start command to specify some parameters to start the service, this section we configure the configuration file configuration of these parameters load configuration.
./bin/mongod--config./conf/mongodb.conf (or./bin/mongod-f./conf/mongodb.conf)
The configuration (mongod.conf) parameters are described below.
1. Basic Configuration
#verbose: Log information redundancy. False by default. Improve internal reporting standard output or log files to the LogPath configuration.
To enable verbose or enable verbosity with the VVVV parameter verbose = True #启动verbose冗长信息, it has a higher level of vv~vvvvv,v, and the more detailed the information is logged in the log file. VVVV = True #port: port. Default 27017,MONGODB default service TCP port, listening for client connections. If the port setting is less than 1024, such as 1021, you need root permission to start, can not use the MongoDB account to start port = 27017 #bind_ip: Bind address. By default 127.0.0.1, only local connections are allowed. The process binds and listens for application connections from this address.
If you need to connect to another server, you need to comment out this or change the IP address to a single comma-delimited list of multiple IP addresses. Bind_ip = 127.0.0.1 #maxConns: Maximum number of connections. Default value: Depends on the system (that is, the Ulimit and file descriptor) limits. MongoDB does not restrict its own connections. When the setting is greater than the system limit, it is not valid, whichever is the system limit. This is useful for clients to create many "tables" that allow the connection to time out without closing the table. Set the value above the size of the connection pool and the total number of connections to prevent spikes in the connection.
Note: You cannot set this value to greater than 20000. Maxconns = #objcheck: Force validation of client requests. The default setting of 2.4 for Objcheck becomes true, and the default is false in earlier versions of Objcheck. Because it forces validation of client requests, ensure that the client never inserts invalid files into the database. For objects with nested documents, there is a little performance impact.
Set Noobjcheck off. Objcheck = True #noobjcheck = False #logpath: Specifies the log file that will hold all of the log records, diagnostic information. Unless otherwise specified, Mongod outputs all log information to standard output.
If Logappend is not specified, the log will overwrite the operation if it is restarted. Logpath=/home/mongo/mongodb-2.6.8/logs/mongodb.log #logappend: Write log mode: set to True for append. The default is overwrite.
If this setting is not specified, MongoDB will overwrite the existing log file at startup. Logappend=true #syslog: Log output isThe syslog system sent to the host, not the standard output to LogPath specifies the log file. Syslog and LogPath can not be used together, will be error: Syslog = True #pidfilepath: Process ID, no specified when the start time there is no PID file.
Default defaults. Pidfilepath =/home/mongo/mongodb-2.6.8/data/mongo.pid #keyFile: Specifies the path to the key file where the authentication information is stored.
Default defaults. KeyFile =/home/mongo/mongodb-2.6.8/data/keyfile #nounixsocket: Socket file, default is False, there is a build socket file.
When set to True, the socket file is not generated. Nounixsocket = False #unixSocketPrefix: Socket file path, default/tmp Unixsocketprefix =/home/mongo/mongodb-2.6.8/tmp #fork: Whether the background is running, Set the daemon mode to true to start the process running in the background.
False by default. Fork = True #auth: User authentication, False by default. No authentication is required. When set to true, access to the database requires Auth authentication, and when there are no users in the database, it is not necessary to verify or operate. Until the first user is created, then the action requires validation. For example: Through the Db.adduser (' sa ', ' sa ') under the Admin library to create a super-user, only under the Admin library authentication is complete: Ab.auth (' sa ', ' sa ') to go to another library operation, 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 Connection Admin #mongo-UAA-PAA Test #aa account Connection Test auth = True #noauth: Users are not allowed to recognize Certificate, default True Noauth = True #cpu: Set to True will force MongoDB to report CPU utilization and IO waits every 4s, write log information to standard output or log file.
The default is False. CPU = True #dbpath: Data storage directory. Default:/data/db/dbpath=/home/mongo/mongodb-2.6.8/data/#diaglog: Create a very detailed troubleshooting andDiagnostic logging for various errors. Default 0. Set to 1 to generate a diaglog. log file at the beginning of the DBPath directory, set not equal to 0, and the log will flush once every minute. The resulting log can be viewed with Mongosniff and, when reset to 0, stops writing to the file, but Mongod continues to keep the file open even if it is no longer written to the data file.
If you want to rename, move or delete diagnostic logs, you must close the Mongod instance completely. 0 off. No logging. #关闭.
No records. #1 Log write operations. #写操作 #2 Log read operations. #读操作 #3 Log Both read and write operations. #读写操作 #7 Log Write and some read operations. #写和一些读操作 #directoryperdb: Set to True to modify the data directory Storage mode, and the files for each database are stored in different folders dbpath the specified directory. With this option, MongoDB can be configured to store data on different disk devices to increase write throughput or disk capacity. The default is False. If the parameter is turned on in a database that is running for a period of time, the original data will disappear (the comment parameter will be returned).
Because the data catalog is different, unless you migrate the existing data files to the database directory generated by DIRECTORYPERDB, you need to decide whether to open them after planning. Directoryperdb = ture #journal: Log, (redo log, see here and here for more information). Default value: (on 64-bit system) true.
Default value: (32-bit system) false.
#设置为true, the action log is enabled to ensure write persistence and data consistency, and the journal directory is created under the DBPath directory. #设置为false to prevent log persistence, there is no need for overhead.
In order to reduce the impact of logs used on disk, you can enable nojournal and set to true.
#注意: Disabling the log on a 64-bit system must use a nojournal. Journal = False #nojournal: Disable log, default value: (on 64 bit system) false.
Default value: (32-bit system) true.
#设置nojournal为true关闭日志, 64-bit, 2.0-version MongoDB by default is enabled for journal logging. NojournAl = True #journalCommitInterval: Brush write commit mechanism, default is 30ms or 100ms. Lower values will consume more disk performance.
This option accepts values between 2 and 300 milliseconds: #如果单块设备提供日志和数据文件, the default journal commit interval is 100 milliseconds.
#如果不同的块设备提供的日志和数据文件, the default journal submission interval is 30 milliseconds.
Journalcommitinterval = #ipv6: IPv6 is supported, false by default.
IPv6 = True #jsonp: Whether to allow JSONP access through an HTTP interface, false by default. Jsonp = True #nohttpinterface: Disables HTTP interface, which is the 28017 port-enabled service.
Default false, supported. Nohttpinterface = False #noprealloc: Pre-allocation mode. Default false: Use pre-allocation to ensure stable write performance, pre-allocation is performed in the background, and each pre-allocated file is populated with 0. This allows MongoDB to always keep extra space and free data files, thus avoiding the congestion caused by the allocation of disk space due to the rapid growth of data.
Setting noprealloc= True to disable pre-allocated data files can shorten the startup time, but during normal operation it can cause significant performance degradation. Noprealloc = False #noscripting: Whether the scripting engine is forbidden. The default is false: not forbidden. Ture: Forbidden, if set to true: "Server-side JavaScript execution is disabled" noscripting = True #notablescan: Prohibit table scan operation For Default false: Not forbidden, ture: Prohibit, prohibit if performing a table scan will appear: "Table scans not allowed" Notablescan = True #nssize: The default size of the file (that is, NS) of the namespace, default 16M, Maximum 2G. The file (that is, NS) for all newly created default size namespaces. This option does not affect the size of the existing namespace file. The default value is 16M bytes and the maximum size is 2 GB.
Let the small database not waste too much disk space, while the big data on the disk to have continuous space. nssize = #profile: Database analysis level settings. Record some operational performance to standard output or the specified LogPathIn the log file, default 0: Off. #0 off.
No analysis. #1 Open.
Only slow operations are included. #2 Open.
Includes all operations. #控制 Profiling switches and Levels: 2, the first is directly in the startup parameters directly set or start MongoDB with the –profile= level, the information is stored in the generated system.profile. The second is to configure the client in real time with the Db.setprofilinglevel (level) command, whose information is stored in the generated system.profile. By default, the Mongod analysis is disabled. Database analysis can affect the performance of a database because the parser must record and handle all database operations.
So you can use dynamic modification when you need it. Profile = 2 #slowms: Records the time of the slow query for profiling, which is 100 milliseconds by default.
specifically ibid. SLOWMS = #quota: Quota, false by default. Whether to turn on the limit for configuring the maximum number of files per database.
When True, Quotafiles is used to configure the maximum number of files. Quota = True #quotaFiles: Number of quotas. The limit on the number of data files per database. This option requires quota to true.
The default is 8. Quotafiles = 8 #rest: Default false, set to true to make a simple rest API. Set to True, when on, the MongoDB default will open an HTTP protocol port to provide rest service (NOHTTPINTERFACE=FALSE), this port is your server port plus 1000, or 28017, The default HTTP port is the Database Status page, (when enabled, commands in the commands line of the Web page can be ordered in).
MongoDB comes with rest, does not support add, delete, change, but also does not support authorization authentication. Rest = True #repair: Fix database operation, default is False. When set to True, repair all databases after startup, it is best to set this option on the command line rather than in the configuration file or control script. Repair on startup, need to close journal. And when you start, with the control file specified parameters and the configuration file specified parameters in the way of repair, (repair information see log), you need to disable the repair parameter to enable MongoDB. Note: When Mongod is repaired, all database files need to be rewritten.
If the repair cannot be run under the same account, you will need to run Chown to modify the database file permissions. Repair = True #repairpath: Fix the path, default is the _tmp directory under the DBPath path. Repairpath = _tmp #smallfiles: Whether to use a smaller default file. 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 restricts them to 512M, also reduces the size of log files and restricts them to 128M.
If the database is large, holding a small amount of data will cause MongoDB to create many files that can affect performance. Smallfiles = True #syncdelay: Writes data to the log frequency, through Fsync operation data. The default is 60 seconds. The default is yes, no setting is required. The log file (journal files) is not affected. Warning: If set to 0,syncdelay, the memory-mapped file will not be synchronized to disk.
Do not set this value on the production system. Syncdelay = #sysinfo: System information, false by default. Set to True,mongod will diagnose the system about the size of the page, the number of physical pages, available physical?? The number of pages is output to standard output. When the SysInfo parameter is turned on, only the above information will be printed and the MONGODB program will not start.
So to turn off this parameter, you can turn on MongoDB. SysInfo = False #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. Affects database operations and updates metadata.
In most cases, you do not need to set this value. Upgrade = False #traceExceptions: Whether internal diagnostics are used.
False by default.
Traceexceptions = False #quiet: Quiet mode. Quiet = True #setParameter: A new parameter of 2.4 that specifies the startup option configuration. To set multiple options, specify it with a setparameter option. Format: Setparameter = <parameter>=<value> set syncdelay:setparameter in config file =
syncdelay= 55,notablescan = True,journalcommitinterval = 50,traceexceptions = True
2. Copy option (Replication options)
Replset: Use this setting to configure the replica set. Specify a replica set name as a parameter, and all hosts must have the same name as the same replica set.
Oplogsize: Specifies the maximum size of the replication operation log (OPLOG). Mongod creates a oplog size based on the maximum amount of free space. For 64-bit systems, Oplog is typically 5% of the available disk space.
Once Mongod creates Oplog for the first time, changing the oplogsize will not affect the oplog size.
Fastsync: The default is False. Under replica set, set to true to enable from the Library Replication Service from a dbpath, the DBPath database is a snapshot of the main library and can be used to quickly enable synchronization, otherwise Mongod will attempt to perform the initial synchronization. Note: If the data is not fully synchronized, Mongod specifies that Fastsync is turned on, secondary or slave is not in sync with the master permanently, which can cause significant consistency issues.
The new parameter that appears in the replindexprefetch:2.2 version, which defaults to all. The values that can be set are: all, none, and _id_only. Can only be used in replica sets (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 only loads the _id index. Specifies _id_ or none to prevent any index of mongod from being loaded into memory.
3. Settings related to master-slave replication
#master: The default is False, and when set to true, configures the current instance as the primary instance.
master = True
#slave: The default is False when set to true to configure the current instance as slave instance.
slave = True
#source: The default is empty and the format is:
4. Shard Cluster Settings
Configsvr #设置是否是配置服务, default port 27019, default directory/data/configdb
Shardsvr #设置是否分片, default port 27018
Configuration Example: conf/mongod.conf
#port Port number
port=23000
#dbpath Database Store file directory
dbpath=/home/mongo/mongodb-2.6.8/data
#logpath log Path
Logpath=/home/mongo/mongodb-2.6.8/logs/mongodb.log
#logappend log Append form false: Restart overwrite file
logappend=true
#fork background start
fork=true
#设置日志级别
#0-off performance analysis, test environment can be opened, the production environment shutdown, has a great impact on performance;
#1-turn on the slow query log and execute statements that are longer than 100 milliseconds
#2-turn on all operation logs
profile=1
Start:./bin/mongod-f conf/mongod.conf