默認情況下纹因,mongodb占用的內(nèi)存大小為:
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.
即 (總內(nèi)存 × 50% - 1GB) 和 (256MB) 兩者中的較大值肖卧。
由于mongodb會占用較大內(nèi)存涌庭,所以生產(chǎn)環(huán)境一般會將mongodb單獨托管嚼隘。
特殊情況下保屯,比如調(diào)試開發(fā)環(huán)境秉版,或只有一臺服務(wù)器贤重,則可以限制mongodb的內(nèi)存。
新增配置文件 /etc/mongod.conf
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
mmapv1:
smallFiles: true
wiredTiger:
engineConfig:
configString : cache_size=160M
然后以配置文件的方式啟動
mongod -f /etc/mongod.conf --fork --logpath=/etc/mongodb.log
啟動后用top命令檢查內(nèi)存使用情況清焕。
其他方式:
https://www.techpaste.com/2016/04/limit-mongodb-memory-usage/
停止mongod
killall mongod
檢查進程
ps -ef|grep mongod | grep -v grep