mongodb profile details, memory limitations, user validation yaml format

Keywords: Operation & Maintenance MongoDB network Docker

17:18:30 May 27, 2019 Siemens Phoenix 275 more readings

Category Column: MongoDB

Copyright Statement: This is an original blogger article that follows  CC 4.0 BY-SA  Copyright Agreement, reproduced with a link to the original source and this statement.

Links to this article: https://blog.csdn.net/weixin_43886133/article/details/90607193

 

mongodb Single Node Profile Details


Mongodb version 3.0 and above are basically configuration files in yaml syntax format. Starting a mongo instance will start with default parameters if it is not a specified configuration file or parameter command.

 

Common basic profile parameters

storage:
  # The mongod process stores the data directory, and this configuration is valid only for mongod processes
  dbPath: /data/mongodb/db
  //Whether or not to turn on journal log persistent storage, which is used for data recovery, is the most basic feature of mongod and is often used for failure recovery.64-bit system defaults to true and 32-bit defaults to false, which is recommended to be turned on and only valid for mongod processes.
  journal:
    enabled: true
 # Storage Engine Type, after mongodb 3.0, supports both "mmapv1" and "wiredTiger" engines, with default value of "mmapv1"; officially, the wiredTiger engine is better.
  engine: mmapv1

systemLog:
  # Log output destination, which can be specified as "file" or "syslog", means output to a log file or, if not specified, to standard output
  destination: file
  # If true, the log will continue to be added at the end of the existing log when mongod/mongos restarts.Otherwise, the current log file will be backed up and a new one will be created; the default is false.
  logAppend: true
  # Log Path
  path: /var/log/mongodb/mongod.log

net:
 # Specify Port
  port: 27017
  # Bind Outer Network op multiple separated by commas
  bindIp: 0.0.0.0
  maxIncomingConnections: 10000
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

Configuration related to memory optimization

MongoDB will become more and more memory intensive, even in dangerous situations, and will remain at its highest level.
There is relevant content on the official website: https://docs.mongodb.com/v3.4/core/wiredtiger/index.html
Following is a profile boot for mongo by adding a memory-limited configuration based on the official network

storage:
  dbPath: /data/mongodb/db
  journal:
    enabled: true
  engine: wiredTiger
    # The following configuration is only valid for the wiredTiger engine (version 3.0 and above)  
  	wiredTiger:
  	  # Memory size of wiredTiger cached working set data in GB
      # This value determines that wiredTiger has a different memory model from mmapv1, which limits mongod's memory usage, whereas mmapv1 cannot (depending on system-level mmap).By default, the value of cacheSizeGB assumes that the current node deploys only one mongod instance, which is half the size of physical memory; if the current node deploys multiple mongod processes, this value needs to be configured appropriately.If mongod is deployed in a virtual container (for example, lxc, cgroups, Docker), it will not be able to use the physical memory of the entire system, and this value needs to be adjusted appropriately.The default value is half of physical memory.
      engineConfig:
      	cacheSizeGB: 5

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
  
net:
  port: 27017
  bindIp: 0.0.0.0
  maxIncomingConnections: 10000
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

Add User Authentication

Before turning on user authentication, you need to create a root user such as:

use admin
db.createUser({
user:"root",
pwd:"root123",
roles:[
{
role:"userAdminAnyDatabase",
db:"admin"
}
]
})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

Then add the following configuration information to the configuration file

security:
  authorization: enabled
  • 1
  • 2

Then restart mongo, otherwise user authentication will not take effect and you can create other normal users after restarting

Posted by jolly on Tue, 17 Sep 2019 19:52:58 -0700