以下是优化Ubuntu上MongoDB配置的关键措施:
/etc/mongod.conf中设置storage.wiredTiger.engineConfig.cacheSizeGB(建议50%-75%物理内存)。storage.wiredTiger.collectionConfig.blockCompressor: snappy(减少磁盘占用)。net.maxIncomingConnections和net.maxOutgoingConnections适应高并发。storage.journal.enabled: true,并合理设置commitIntervalMs。sh.enableSharding)水平扩展。rs.initiate)提高可用性和读取性能。explain()方法优化慢查询。mongostat、mongotop或第三方工具(如Prometheus+Grafana)监控性能。mongodump/mongorestore)、重建索引、清理无用数据。vm.swappiness、ulimit等参数以适配数据库负载。注意:修改配置前需在测试环境验证,优先通过mongod.conf文件修改,避免直接命令行参数覆盖。
参考来源: