[root@iZ2zed126f44v90yv59ht3Z rabbitmq]# cat /usr/local/mongodb/mongodb.conf
port = 27017
dbpath = /usr/local/mongodb/data
logpath = /usr/local/mongodb/logs/mongodb.log
fork = true
logappend = true
auth = true
rest = true
maxConns = 20000
directoryperdb=true
wiredTigerCacheSizeGB = 10
-
2018-08-16 15:48:00
转载于:https://www.cnblogs.com/gaoyuechen/p/9487745.html
更多相关内容 -
MongoDB内存配置 --wiredTigerCacheSizeGB
2021-03-03 17:31:32解决方案是使用 --wiredTigerCacheSizeGB设置内存大小, --------------------- 作者:Sumtoo 来源:CSDN 原文:https://blog.csdn.net/LuyaoYing001/article/details/75576820 版权声明:本文为博主原创文章,转载...用top命令查看系统占用内存的情况 top -p $(pidof mongod),发现mongod占用了8G内存的35.6%。在服务器上运行两个mongod进程,很容易导致mongod异常退出。
一度以为是C++程序发生内存泄漏导致了系统异常崩溃,现在可以肯定是由mongod配置的内存占用太高导致的。
(也可以通过命令 free -m 查看系统的内存使用情况,但是要注意可用内存是free+buffers+cached)
内存不足引发bulk_write_exception。
关于mongod如何管理内存,度娘有如下一段话:
目前,MongoDB使用的是内存映射存储引擎,它会把磁盘IO操作转换成内存操作,如果是读操作,内存中的数据起到缓存的作用,如果是写操作,内存还可以把随机的写操作转换成顺序的写操作,总之可以大幅度提升性能。MongoDB并不干涉内存管理工作,而是把这些工作留给操作系统的虚拟缓存管理器去处理,这样的好处是简化了MongoDB的工作,但坏处是你没有方法很方便的控制MongoDB占多大内存,事实上MongoDB会占用所有能用的内存,所以最好不要把别的服务和MongoDB放一起。
MongoDB Manual上说:
MongoDB keeps most recently used data in RAM. If you have created indexes for your queries and your working data set fits in RAM, MongoDB serves all queries from memory.
简而言之,就是mongod把这事交给操作系统了,缺了就跟OS要内存,多了也不还,爱咋咋地。
如果需要强行收回内存也不是没有办法:
重启mongod,或者调用 db.runCommand({closeAllDatabases:1})来清除内存
使用Linux命令清除缓存中的数据:echo 3 > /proc/sys/vm/drop_caches
在应用运行过程中重启mongod,是比较ugly的做法,可以尝试使用第二种方法。
还有没有更好的方法控制mongodb占用的内存大小呢?
查看mongod -h发现mongod提供了额外的可选参数来控制WiredTiger存储引擎所占用的cache size。需要注意的是,cache size设置较低,同时mongodb复杂查询很频繁的话,会有延迟发生。
cacheSizeGB 指的就是Cache size,包括数据和索引。Mongod本身使用内存如连接池堆栈以及sorting buffer等都是额外的,不会被统计到这个数字里面。如果索引在内存,查询冷数据取决于你的IO能力。如果IO latency很低,系统也没有是高负载,那响应时间应该是毫秒级的区别。但是如果查询很频繁,又涉及到很多范围、批量查询,IOPS又跟不上,那就有可能到几百几千毫秒都有可能。
Starting in 3.4, the WiredTiger internal cache, by default, will use the larger of either:
50% of RAM minus 1 GB, or
256 MB.
从官方文档可以得知,一个mongod实例几乎要占用服务器上一般的内存,也就是说,如果在同一台服务器上同时开始两个或以上mongod实例,那么很大可能会发生内存不足而异常退出。这就是导致bulk_write_exception问题的原因。
解决方案是使用 --wiredTigerCacheSizeGB设置内存大小,
---------------------
作者:Sumtoo
来源:CSDN
原文:https://blog.csdn.net/LuyaoYing001/article/details/75576820
版权声明:本文为博主原创文章,转载请附上博文链接!
-
mongodb 3.2配置内存缓存大小为MB/MongoDB 3.x内存限制配wiredTigerCacheSizeGB
2021-02-02 19:59:56mongodb 3.2配置内存缓存大小为MB/MongoDB 3.x内存限制配置 mongodb占用内存非常高,这是因为官方为了提升存储的效率,设计...- -wiredTigerCacheSizeGB number New in version 3.0. Defines the maximum size of the imongodb 3.2配置内存缓存大小为MB/MongoDB 3.x内存限制配置
mongodb占用内存非常高,这是因为官方为了提升存储的效率,设计就这么设计的。
但是大部分的个人开发者所购买的服务器内存并没有那么大,所以,我们需要配置下MongoDB的内存缓存大小,不然mongodb会占用非常多。
WiredTiger Options
- -wiredTigerCacheSizeGB number
New in version 3.0.Defines the maximum size of the internal cache that WiredTiger will use for all data.
With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache.
Changed in version 3.2: Starting in MongoDB 3.2, the WiredTiger internal cache, by default, will use the larger of either:
- 60% of RAM minus 1 GB, or
- 1 GB.
mongodb会尽可能的把所有的数据都缓存,以便提高效率。
以mongodb 3.2为例,WiredTiger内部缓存,默认会用掉
- 60% * 内存 - 1GB
- 1GB
当你的内存大于1GB,mongodb会用掉 内存的60% - 1GB 的内存作为缓存;
当你的内存小于1GB,mongodb会直接用掉1GB。
另外,MongoDB 3.4与3.2也是有区别的
MongoDB 3.4该配置项为:
参考官方demo
https://docs.mongodb.com/v3.4/reference/configuration-options/#storage-optionsstorage.wiredTiger.engineConfig.cacheSizeGB
Type: float
The maximum size of the internal cache that WiredTiger will use for all data.
Changed in version 3.4: Values can range from 256MB to 10TB and can be a float. In addition, the default value has also changed.
Starting in 3.4, the WiredTiger internal cache, by default, will use the larger of either:
- 50% of RAM minus 1 GB, or
- 256 MB.
参考配置:
https://jira.mongodb.org/browse/SERVER-22274下面是修改后的配置:/etc/mongod.conf
Where and how to store data.
storage: dbPath: /var/lib/mongo #dbPath: /mongodata journal: enabled: true # engine: mmapv1: smallFiles: true wiredTiger: engineConfig: configString : cache_size=512M
在docker-compose.yml中配置
可参考
-
限制mongodb内存的使用
2021-01-07 12:58:56默认情况下,mongodb占用的内存大小为: Starting in 3.4, the WiredTiger internal cache, by default, will use the larger of either: 50% of RAM minus 1 GB, or 256 MB. 即 (总内存 × 50% - 1GB) 和 (256... -
使用Docker部署MongoDB Cluster
2018-04-19 18:44:13wiredTigerCacheSizeGB 5 volumes: - / data /configsrv_db:/ data /configdb ports: - "27018:27017" restart: always container_name: configsrv ulimits: nofile: soft: 300000 hard: ...使用Docker部署MongoDB Cluster
环境准备
- 四台服务器,分别命名为ServerA、ServerB、ServerC、ServerD
- 2 Shard(1 Primary 1 Secondary 1 Arbiter) Nodes
- 3 Config Nodes
- 4 Router Nodes
Docker镜像
docker-compose.yml
ServerA配置文件
version: '2' services: configsrv: image: mongo command: mongod --keyFile /data/configdb/mongodb-keyfile --oplogSize 1024 --replSet configrs --port 27017 --configsvr --wiredTigerCacheSizeGB 5 volumes: - /data/configsrv_db:/data/configdb ports: - "27018:27017" restart: always container_name: configsrv ulimits: nofile: soft: 300000 hard: 300000 rs1_node: image: mongo command: mongod --keyFile /data/db/mongodb-keyfile --oplogSize 10240 --replSet rs1 --directoryperdb --port 27017 --shardsvr volumes: - /data/rs1_node_db:/data/db ports: - "27019:27017" restart: always container_name: rs1_node ulimits: nofile: soft: 300000 hard: 300000 router: image: mongo command: mongos --keyFile /data/db/mongodb-keyfile --configdb configrs/ServerA:27018,ServerB:27018,ServerC:27018 ports: - "27017:27017" volumes: - /data/router_db:/data/db restart: always container_name: router ulimits: nofile: soft: 300000 hard: 300000
ServerB配置文件
version: '2' services: configsrv: image: mongo command: mongod --keyFile /data/configdb/mongodb-keyfile --oplogSize 1024 --replSet configrs --port 27017 --configsvr --wiredTigerCacheSizeGB 5 volumes: - /data/configsrv_db:/data/configdb ports: - "27018:27017" restart: always container_name: configsrv ulimits: nofile: soft: 300000 hard: 300000 rs1_node: image: mongo command: mongod --keyFile /data/db/mongodb-keyfile --oplogSize 10240 --replSet rs1 --directoryperdb --port 27017 --shardsvr volumes: - /data/rs1_node_db:/data/db ports: - "27019:27017" restart: always container_name: rs1_node ulimits: nofile: soft: 300000 hard: 300000 rs2_arbiter: image: mongo command: mongod --keyFile /data/db/mongodb-keyfile --oplogSize 1024 --replSet rs2 --directoryperdb --port 27017 --shardsvr --wiredTigerCacheSizeGB 1 --nojournal --smallfiles volumes: - /data/rs2_arbiter_db:/data/db ports: - "27020:27017" restart: always container_name: rs2_arbiter ulimits: nofile: soft: 300000 hard: 300000 router: image: mongo command: mongos --keyFile /data/db/mongodb-keyfile --configdb configrs/ServerA:27018,ServerB:27018,ServerC:27018 ports: - "27017:27017" volumes: - /data/router_db:/data/db restart: always container_name: router ulimits: nofile: soft: 300000 hard: 300000
ServerC配置文件
version: '2' services: configsrv: image: mongo command: mongod --keyFile /data/configdb/mongodb-keyfile --oplogSize 1024 --replSet configrs --port 27017 --configsvr --wiredTigerCacheSizeGB 5 volumes: - /data/configsrv_db:/data/configdb ports: - "27018:27017" restart: always container_name: configsrv ulimits: nofile: soft: 300000 hard: 300000 rs2_node: image: mongo command: mongod --keyFile /data/db/mongodb-keyfile --oplogSize 10240 --replSet rs2 --directoryperdb --port 27017 --shardsvr volumes: - /data/rs2_node_db:/data/db ports: - "27019:27017" restart: always container_name: rs2_node ulimits: nofile: soft: 300000 hard: 300000 rs1_arbiter: image: mongo command: mongod --keyFile /data/db/mongodb-keyfile --oplogSize 1024 --replSet rs1 --directoryperdb --port 27017 --shardsvr --wiredTigerCacheSizeGB 1 --nojournal --smallfiles volumes: - /data/rs1_arbiter_db:/data/db ports: - "27020:27017" restart: always container_name: rs1_arbiter ulimits: nofile: soft: 300000 hard: 300000 router: image: mongo command: mongos --keyFile /data/db/mongodb-keyfile --configdb configrs/ServerA:27018,ServerB:27018,ServerC:27018 ports: - "27017:27017" volumes: - /data/router_db:/data/db restart: always container_name: router ulimits: nofile: soft: 300000 hard: 300000
ServerD配置文件
version: '2' services: rs2_node: image: mongo command: mongod --keyFile /data/db/mongodb-keyfile --oplogSize 10240 --replSet rs2 --directoryperdb --port 27017 --shardsvr volumes: - /data/rs2_node_db:/data/db ports: - "27019:27017" restart: always container_name: rs2_node ulimits: nofile: soft: 300000 hard: 300000 router: image: mongo command: mongos --keyFile /data/db/mongodb-keyfile --configdb configrs/ServerA:27018,ServerB:27018,ServerC:27018 ports: - "27017:27017" volumes: - /data/router_db:/data/db restart: always container_name: router ulimits: nofile: soft: 300000 hard: 300000
启动前准备工作
- 创建mongodb-keyfile文件
openssl rand -base64 741 > mongodb-keyfile chmod 600 mongodb-keyfile
- 创建宿主机的volume文件夹
初始化Config节点
重要:在初始化启动前需要去掉
docker-compose.yml
配置文件中的--keyFile
参数启动节点
在ServerA、ServerB和ServerC三台服务器上运行命令:
docker-compose up -d configsrv初始化
利用mongo连接到ServerA节点,输入以下命令创建管理用户:
use admin db.createUser({user: "mongoUserAdmin", pwd: "123456", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] }) db.createUser({user: "mongoRootAdmin", pwd: "123456", roles: [ { role: "root", db: "admin" } ] })
初始化ReplicaSet信息
rs.initiate( { _id: "configrs", configsvr: true, members: [ { _id : 0, host : "ServerA:27018" }, { _id : 1, host : "ServerB:27018" }, { _id : 2, host : "ServerC:27018" } ] } )
初始化Shard1节点
重要:在初始化启动前需要去掉
docker-compose.yml
配置文件中的--keyFile
参数启动节点
在ServerA和ServerB两台服务器上运行命令:
docker-compose up -d rs1_node
在ServerC服务器上运行命令:
docker-compose up -d rs1_arbiter
初始化
利用mongo连接到ServerA节点,创建管理用户
use admin db.createUser({user: "mongoUserAdmin", pwd: "123456", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] }) db.createUser({user: "mongoRootAdmin", pwd: "123456", roles: [ { role: "root", db: "admin" } ] })
初始化ReplicaSet信息
rs.initiate( { _id : "rs1", members: [ { _id : 0, host : "ServerA:27019" }, { _id : 1, host : "ServerB:27019" } ] } )
增加Arbiter节点
rs.addArb("ServerC:27020")
查看rs状态:
rs.status()
初始化Shard2节点
与Shard1节点雷同,只需要修改对应的服务器IP
重启Config和Shard节点
取消
--keyFile
参数的注释,删掉上述创建的所有container利用
docker-compose
再次启动上面所有节点启动Router节点
使用命令
docker-compose up -d router
在四台服务器上启动路由节点配置Cluster
增加Shard节点
使用mongo连接到任意一台服务器的router节点,然后执行以下命令将Shard节点加入到当前Cluster中
use admin db.auth("<username>","<password>") sh.addShard("rs1/ServerA:27019") sh.addShard("rs2/ServerD:27019")
启动Sharding
在对collection进行sharding之前一定要先对数据库启动sharding
sh.enableSharding("<database>") sh.shardCollection( "<database>.<collection>", { _id : "hashed" } )
参考资料
-
MongoDB 4.2 限制内存
2021-05-12 03:52:16先说结论本文适配 MongoDB 4.2.1不能通过 MongoDB 的配置文件严格限制 MongoDB 占用的内存将 storage.wiredTiger.engineConfig.cacheSizeGB 配置为期望占用最大内存的 60% 左右即可查看 MongoDB 内存使用情况mem>... -
mongodb 修改cache-size 大小
2021-08-04 14:23:03{ "setParameter": 1, "wiredTigerEngineRuntimeConfig": "cache_size=20G"}) 配置参数修改 启动的时候添加 参数 --wiredTigerCacheSizeGB=10 kubedb 修改 apiVersion: v1 kind: ConfigMap metadata: name: mongodb-... -
docker-compose安装mongodb说明
2022-01-05 10:58:371.1. 配置docker-compose.yml mongod.conf内容如下,一般只需要修改wiredTiger.engineConfig.cacheSizeGB,具体大小请查考官方文档 # mongod.conf # for documentation of all options, see: ... -
docker-compose增加鉴权
2021-04-08 11:42:27rw - /etc/localtime:/etc/localtime environment: - MONGO_INITDB_ROOT_USERNAME=root - MONGO_INITDB_ROOT_PASSWORD=123456 command: –wiredTigerCacheSizeGB 1.5 –auth deploy: resources: limits: cpus: $... -
mongodb 6、mongodb内存使用优化
2019-01-28 22:15:37一个是file system cache,wiredTigerCacheSizeGB参数设置的应该是 internal cache. 通过上面2.3中的cacheSizeGB只能限制内部缓存,而不能限制文件系统使用的缓存,mongodb 会使用剩余所有其他的文件系统缓存,所以... -
记录MongoDB占用内存太大
2020-07-08 17:49:17原因: MongoDB为了优化本身的读写效率,将内存当作缓存,所以读写的...maxConns=10000 #连接数 解释: --wiredTigerCacheSizeGB 8 限制缓存使用内存大小为8GB,这样MongoDB使用的内存就是(8GB-1GB)* 50%,也就是3.5g -
MongoDB WiredTiger 内存使用情况和限制
2021-02-19 15:21:19MongoDB WiredTiger 内存使用情况和限制 Mongo学习笔记-...内存限制配置 在对应的配置文件中加入:wiredTigerCacheSizeGB = 10 参考文档:https://docs.mongodb.com/v3.0/reference/configuration-options/index.html -
关于mongodb3.4的内存困惑
2018-03-03 02:00:29疑问2:我设置了启动参数wiredTigerCacheSizeGB=100,但是现在使用内存超过了100G,看官网文档上说,mongodb有两部分内存,一个是WiredTiger internal cache,一个是file system cache,wiredTigerCacheSizeGB参数... -
linux下安装启动mongodb,并设置内存
2020-03-19 11:27:03-wiredTigerCacheSizeGB 2 解释: 我这边路径和参考文章作者的路径不一样,大家要确认好自己的路径 需要配置mongodb.conf(参考https://www.cnblogs.com/tjp40922/p/11870321.html) –wiredTigerCacheSizeGB 2 限制... -
mongodb占用内存太大解决办法
2021-01-26 23:34:46在使用MongoDB的时候遇到了一个内存占用的问题,爬虫爬过来的图片在库中存的是网络地址,要写一个脚本对图片进行分批.../usr/bin/mongod --config /etc/mongod.conf --fork --wiredTigerCacheSizeGB 8 关键在于 --wi.. -
mongodb性能优化
2021-01-27 08:57:54一、数据库设计优化:范式化与反范式化1、完全分离(范式化){"_id" : ObjectId("5124b5d86041c7dca81917"),"title" : "如何使用MongoDB","author" : [ObjectId("144b5d83041c7dca84416"),ObjectId("144b5d83041c7dca... -
MongoDB内存占用过高问题解决方案
2020-05-09 15:28:07或者参考docker hub中简介使用wiredTigerCacheSizeGB参数启动: docker run --name some-mongo -d mongo --wiredTigerCacheSizeGB 1.5 1.2 运行中的容器可使用 docker update -m 1g name 来更新容器使用内存... -
mongodb各种配置
2020-06-02 08:29:09基本 配置文件 cat > /mongodb/conf/mongo.conf <<EOF systemLog: destination: file path: "/mongodb/log/mongodb.log" logAppend: true storage: journal: enabled: true ... por -
MongoDB 异常宕机与参数cacheSizeGB
2019-09-16 18:25:17近期,处理一MongoDB异常宕机故障,与MongoDB引擎参数cacheSizeGB相关,该参数用来限制MongoDB的wiredTiger引擎使用内存的量。下边是故障处理过程,供以后问题处理参考。 业务方反馈:MongoDB在2019.9.16 9:16:... -
MongoDB从入门到优化
2019-05-14 17:06:14--wiredTigerCacheSizeGB 。 两个参数。 三、mongodb 配置参数 Mongodb 建议使用 YAML 格式的配置文件,也支持 ini 格式的配置文件。 ini 配置文件参数解析 bind_ip = 0.0.0.0 #绑定的 ip,如果是 0.0.0.0 ... -
Mongodb的安装和配置
2020-07-07 15:18:11Mongodb是一种开源的文档型数据库,是专为可扩展性,高性能和高可用性而设计的数据库,是非关系型数据库中功能最丰富,最像关系型数据库的,它支持的数据结构非常松散,是类似 json的bjson 格式,因此可以存储比较... -
windows下修改mongodb 内存占用方法
2019-01-08 11:01:26在 mongo.conf 文件中添加 wiredTigerCacheSizeGB=4 (4表示4个GB) -
『MongoDB』MongoDB高可用部署架构——分片集群篇(Sharding)
2022-03-17 07:22:36-port 27010 --fork --shardsvr --wiredTigerCacheSizeGB 1 3.4 初始化第一个分片复制集 mongo --host member1.example.com:27010 rs.initiate({ _id: "shard1", "members": [ { "_id": 0, "host": ... -
内存限制
2020-12-24 09:15:19或者参考docker hub中简介使用wiredTigerCacheSizeGB参数启动: docker run --name some-mongo -d mongo --wiredTigerCacheSizeGB 1.5 1.2 运行中的容器可使用 docker update -m 1g name 来更新容器使用内存... -
mongo相关
2017-11-23 21:55:001、启动mongo服务:mongod --port 8051 --dbpath E:\GameDB\DB --wiredTigerCacheSizeGB 5(端口,数据路径、内存上限控制,单位为G) 2、简单的mongo定时完全备份批处理 1 @rem 备份mongo数据库批处理 2 @...