在CentOS上調整MongoDB的內存使用,可以通過修改MongoDB的配置文件來實現。以下是具體步驟:
MongoDB的配置文件通常位于 /etc/mongod.conf
。
sudo nano /etc/mongod.conf
在配置文件中找到 storage
部分,可以看到 wiredTiger
相關的設置。你需要調整 engineConfig.cacheSizeGB
參數來控制MongoDB使用的最大內存量。
例如,如果你想讓MongoDB使用最多4GB的內存,可以這樣設置:
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 4
按 Ctrl + X
,然后按 Y
確認保存,最后按 Enter
退出。
修改配置文件后,需要重啟MongoDB服務以使更改生效。
sudo systemctl restart mongod
你可以使用以下命令來驗證MongoDB的內存使用情況:
db.serverStatus().mem
或者使用 top
或 htop
命令查看MongoDB進程的內存使用情況。
top -p $(pgrep mongod)
通過以上步驟,你應該能夠在CentOS上成功調整MongoDB的內存使用。