In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
What is the configuration of MongoDB database? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Detailed configuration instructions for MongoDB database
There are two ways to start MongoDB
Specify configuration parameters directly
Specify the profile.
Launched by the configuration file as follows: mongod-- config / your_path/mongodb.conf
The configuration is as follows:
Verbose: log information is redundant. Default false. Improve internal reporting standard output or log to logpath configuration log files. To enable verbose or enable verbosity, use the vvvv parameter, such as:
Verbose = truevvvv = true
[note]: start the verbose message of verbose. The more vv~vvvvv,v, the higher the level, and the more detailed the information recorded in the log file.
Port: Port. The default service TCP port of 27017 MongoDB listens for client connections. If the port setting is less than 1024, such as 1021, root permission is required to start, and cannot be started with a mongodb account. (an ordinary account cannot be started even if it is 27017), otherwise an error will be reported: [mongo-- port=1021 connection]
ERROR: listen (): bind () failed errno:13 Permission denied for socket: 127.0.0.1:1021port = 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 IP to the local address, such as 192.168.200.201 [other servers connect with mongo-- host=192.168.200.201], you can bind multiple IP addresses with a comma-separated list.
Bind_ip = 127.0.0.1
MaxConns: maximum number of connections. Default value: depends on the system (that is, the ulimit and file descriptor) limitations. MongoDB does not restrict its own connections. When the setting is greater than the system limit, it is invalid, subject to the system limit. This is useful when the client creates many "tables" that allow the connection to time out without closing the "table". Set this value to a size higher than the connection pool and the total number of connections to prevent connections at peak times.
MaxConns = 100
Note: this value cannot be set greater than 20000.
Objcheck: forces authentication of client requests. The default setting of2.4 is that objcheck becomes true, and objcheckdefaults to false in earlier versions. Because it forces client requests to be validated, ensure that clients never insert invalid files into the database. For objects with nested documents, there is a slight performance impact. Set noobjcheck to be turned off.
Objcheck = true#noobjcheck = falsenoobjcheck: same as above, false is turned off by default. # noobjcheck = false
Logpath: specify a log file that will hold all log records and diagnostic information. Unless otherwise specified, mongod outputs all log information to standard output. If no logappend is specified, the log will be overwritten if it is restarted.
Logpath=/var/log/mongodb/mongodb.loglog
Append: the mode of logging: set to true to append. The default is override. If this setting is not specified, the existing log file will be overwritten by MongoDB at startup.
Logappend=true
Syslog: log output is sent to the host's syslog system, rather than standard output to the log file specified by logpath. If syslog and logpath cannot be used together, an error will be reported:
Cant use both a logpath and syslogsyslog = true
Pidfilepath: process ID. If not specified, there will be no PID file at startup. Default. Default.
Pidfilepath = / var/run/mongo.pid
KeyFile: specifies the path to the key file where authentication information is stored. Default. Default. For more information, please see Replica Set Security "and" Replica Set Administration.
KeyFile = / srv/mongodb/keyfile
Nounixsocket: socket file, default is false, socket file is generated. When set to true, no socket file is generated.
Nounixsocket = false
UnixSocketPrefix: socket file path, default / tmp
UnixSocketPrefix = / tmp
Fork: whether to run in the background, set to the daemon mode in which the true startup process runs in the background. Default false.
Fork = true
Auth: user authentication. Default is false. No certification is required. When set to true, auth authentication is required to enter the database. When there is no user in the database, authentication is not required to operate. Operations need to be validated until the first user is created.
Auth = true
For example, if you create a super user under the admin library through db.addUser ('sa','sa'), you can only authenticate ab.auth (' sa','sa') under the admin library before you can operate in other libraries and cannot be verified in other libraries. In this way, you also need to specify the library to connect to the database:
Mongo-u sa-p sa admin # sa account connection adminmongo-u aa-p aa test # aa account connection test
Noauth: user authentication is prohibited. Default is true. Same as above
Noauth = true
Cpu: setting to true forces mongodb to report cpu utilization and io wait every 4s, writing log information to standard output or log files. The default is false.
Cpu = true
When the log is enabled, it will appear:
Mon Jun 10 10 cpu 21 cpu 42.241 [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 of various errors. The default is 0. Set to 1 to generate a diaglog in the dbpath directory. The log file at the beginning, his value is as follows:
ValueSetting0off. No logging. # close. There's no record. 1Log write operations. # write operation 2Log read operations. # read operation 3Log both read and write operations. # read and write operation 7Log write and some read operations. # write and some read operations
If the setting is not equal to 0, the log will flush once per minute:
Mon Jun 10 11:16:17.504 [DataFileSync] flushing diag logMon Jun 10 11:17:17.442 [DataFileSync] flushing diag log
The resulting log can be viewed with mongosniff: if there is an error and specific usage of mongosniff [specific TCP/IP network traffic similar to tcpdump as a MongoDB], please see here and execute: apt-get install libpcap-dev before.
Root@m3:/var/lib/mongodb# mongosniff-source DIAGLOG diaglog.51b542a9
Note: when reset to 0, writing to the file is stopped, but mongod continues to open the file, even if it no longer writes to the data file. If you want to rename, move or delete diagnostic logs, you must completely shut down the mongod instance.
Diaglog = 3
Directoryperdb: set to true, modify the data directory storage mode, and the files for each database are stored in a different folder in the directory specified by DBPATH. Using this option, you can configure MongoDB to store data on different disk devices to increase write throughput or disk capacity. The default is false.
Note: if you turn on this parameter in a database that has been running for a period of time, it will cause the original data to disappear (the comment parameter will come back). Because the data directories are different, unless you migrate the existing data files to the database directory generated by directoryperdb, such as:
Root@m3:/var/lib/mongodb# mv test.* test/
Migrate the test data file to the database test directory generated by directoryperdb. So you need to decide whether to turn it on or not after planning.
Directoryperdb = ture
Original data structure:
Journalmongod.locklocal.0local.1local.nstest.0test.1test.ns
The structure after opening directoryperdb and migrating the data files to the relevant data directory:
Journalmongod.locklocal/local.0local/local.1local/local.nstest/test.0test/test.1test/test.ns
Journal: log
Default value: (on 64-bit systems) true.
Default value: (32-bit system) false.
Set to true, enable operation logging to ensure write persistence and data consistency, and create a journal directory under the dbpath directory.
Set to false to prevent log persistence without overhead. To reduce the impact of logs used on disk, you can enable nojournal and set it to true. Note: to disable logging on a 64-bit system, you must use the with nojournal.
# journal=truejournal=false
32-bit OS:
Tue Jun 11 12 NOTE 17 This is a 32 bit MongoDB binary.Tue Jun 11 12 bit MongoDB binary.Tue Jun 17 This is a 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/journalTue Jun 11 12:29:34 [initandlisten] recover: no journal files present, no recovery needed
Nojournal: disable log defaults: (on 64-bit systems) false. Default value: (32-bit system) true. Set nojournal to true to disable logging, 64-bit. Journal logging is enabled by default for mongodb after version 2.0.
Nojournal=true
JournalCommitInterval: brush write submission mechanism. Default is 30ms or 100ms. A lower value consumes more disk performance. This option accepts values between 2 and 300 milliseconds:
If a single device provides logs and data files, the default journal submission interval is 100 milliseconds.
If different block devices provide log and data files, the default journal submission interval is 30 milliseconds.
JournalCommitInterval=100
Ipv6: whether ipv6 is supported or not. Default is false.
Jsonp: whether to allow JSONP access through a HTTP interface, default false.
Nohttpinterface: whether to disable the http interface, that is, the service enabled on port 28017. Default false, supported.
Nohttpinterface = false
Noprealloc: the way of pre-allocation. Default false: use pre-allocation to ensure stable write performance, pre-allocation takes place in the background, and each pre-allocated file is populated with 0. This allows MongoDB to keep extra space and free data files all the time, thus avoiding the blocking caused by the allocation of disk space caused by excessive data growth.
Setting noprealloc= true to disable pre-allocated data files reduces startup time, but may result in significant performance degradation during normal operation.
Noprealloc = false
Noscripting: whether to disable scripting engines. The default is false: no prohibition. Ture: disable if set to true: appears 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 disable table scan operation. Default false: no, ture: forbidden. If a table scan is performed, it will appear:
Error: {"$err": "table scans not allowed:test.emp", "code": 10111}
You can modify settings dynamically:
Db.adminCommand ({setParameter:1, notablescan:false}) # notablescan = true notablescan = false
Nssize: the default size of the file for the namespace (that is, NS), with a default of 16m and a maximum of 2G. Files for all newly created default size namespaces (that is, 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 the small database not waste too much disk space, and at the same time let big data have continuous space on the 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.nsdrwxr-xr-x 2 root root 4.0K June 10 11:57 _ tmpnssize = 16
Profile: database analysis level setting. Record some operational performance to the standard output or the specified logpath log file, the default is 0: off.
Level setting 0 off no analysis. 1 open only includes slow operation. 2 Open includes all operations.
Control Profi [ling] switches and levels: 2
The first is to set it directly in the startup parameters or to add the-profile= level when starting MongoDB, whose information is saved in the generated system.profile.
Profile = 2
The second is to use the db.setProfilingLevel command on the client side for real-time configuration, and its 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, profiling is disabled for mongod. Database analysis can affect database performance because the parser must record and process all database operations. So just use dynamic modification when needed.
Slowms: the time to record slow queries for profile analysis. The default is 100ms. Ditto.
Slowms = 200 > db.getProfilingStatus () {"was": 2, "slowms": 200}
Quota: quota. Default is false. Whether to turn on the limit of configuring the maximum number of files per database. When true, use quotaFiles to configure the maximum number of files.
Quota = true
QuotaFiles: the number of quotas. The limit on the number of data files per database. This option requires that quota be true. The default is 8.
QuotaFiles = 8
Rest: the default false, set to true, makes a simple REST API.
Rest = true
Set to true. When enabled, a port of HTTP protocol is opened in MongoDB to provide REST service (nohttpinterface = false). This port is your Server port plus 1000, that is, 28017. The default HTTP port is the database status page (when enabled, all commands in the Commands line of the web page can be clicked in). The REST that comes with mongodb does not support adding, deleting or changing, nor does it support permission authentication.
Repair: repair database operations. Default is false.
When set to true, repair all databases after startup, preferably 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
Root@m3:/var/log/mongodb# mongod-repair
Repair at startup. Journal needs to be closed, otherwise an error will be reported:
Can't specify both-journal and-repair options.
And when starting, after repairing the parameters specified in the control file and the parameters specified in the configuration file (see 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 the 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 a smaller default file. The default is false, which is not used. Set to true, using 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, it will cause mongodb to create a lot of files, which will affect performance.
Smallfiles = true
Syncdelay: how often the data is brushed to the log and manipulated through fsync. The default is 60 seconds.
Syncdelay = 60
It is OK by default and does not need to be set. Will not affect the log file (journal files) > warning: if set to 0 ~ # SYNCDELAY, it will not be synchronized to the memory-mapped file on disk. Do not set this value on the production system. Sysinfo: system information, default false. Setting to true,mongod will diagnose the system about the page size, the number of physical pages available, and the number of physical pages available for 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 enabled, only the above information will be printed and the mongodb program will not be started. So you need to turn this parameter off before you can enable mongodb. Upgrade: upgrade. The default is false. When set to true, specify DBPATH to upgrade the data format of the file on disk to the latest version. It will affect database operations and update metadata. In most cases, you do not need to set this value. TraceExceptions: whether to use internal diagnostics. Default false.
TraceExceptions = false
Quiet: quiet mode.
Quiet = true
The new parameter of setParameter:2.4, which specifies the configuration of startup options. If you want to set multiple options, you can specify them with a setParameter option. SetParameter is set in this file, using the following format:
SetParameter = =
For example, set syncdelay in the configuration file:
SetParameter = syncdelay= 55 Notablescan = true,journalCommitInterval = 50 recorder traceExceptions = true
Replication Options replication option 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: the maximum size of the specified replication operation log (OPLOG). Mongod creates an OPLOG based on the maximum amount of space available. For 64-bit systems, OPLOG is usually 5% of the available disk space. Once mongod creates an OPLOG for the first time, changing the oplogSize will not affect the size of the OPLOG. Fastsync: the default is false. Under the replica set, set to true to enable the slave library replication service from a dbpath whose database is a snapshot of the master library and can be used to quickly enable synchronization, otherwise the mongod will attempt to perform the initial synchronization. Note: if the data is not fully synchronized mongod specifies that fastsync is turned on and secondary or slave is permanently out of sync with the master which can lead to significant consistency problems. The new parameter that appears in the replIndexPrefetch:2.2 version. The default is all. The values that can be set are: all, none, and _ id_only. Can only be used in a copy set (replSet). By default, members of the secondary replica set load all indexes into memory (related to operations prior to OPLOG). You can modify this behavior so that secondary loads only the _ id index. Specify _ id_ or none to prevent any indexes of mongod from being loaded into memory. Master/Slave Replication: related settings for master-slave replication master: default is false. When set to true, the current instance is configured as the master instance.
Master = true
Slave: defaults to false. When set to true, the current instance is configured as a slave instance.
Slave = true
Source: the default is empty and the format is:. For slave instance replication: specifying this option when setting slave makes the instance source = 127.0.0.1:30001only of the slave replication specified master: the default is empty, and the slave option specifies a database to replicate.
Source = 127.0.0.1VR 30001
Only: the default is empty and is used to specify a database for replication from the option.
# synchronize only abc collections (libraries)
Slavedelay: sets the delay time for synchronizing the master library from the library, which is used for slave settings. The default is 0.
1.slavedelay = 60 # delay 60s to synchronize master data
Autoresync: the default is false, which is used for slave settings. Whether to automatically resynchronize. Set to true, if you are more than 10 seconds behind the master, the slave will be forced to resynchronize automatically. This setting may be problematic if the oplogSize is too small. If the OPLOG size is not large enough to store the difference between master and slave state changes, forced resynchronization is not necessary in this case. Automatic resynchronization never occurs more than once in a minute when the autoresync option is set to false,10.
Autoresync = false
After reading the above, have you mastered how to configure the MongoDB database? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.