以下是MongoDB在CentOS上的性能调优技巧:
echo never > /sys/kernel/mm/transparent_hugepage/enabled设置。/etc/mongod.conf中设置storage.wiredTiger.engineConfig.cacheSizeGB为可用内存的50%-80%。net.maxIncomingConnections(如设为5000),启用tcpNoDelay和SO_REUSEADDR。logRotate: reopen),调整journal.commitIntervalMs(如设为100ms)以平衡性能与数据安全。db.collection.createIndex()。explain("executionStats")分析查询计划,确保使用索引。skip()/limit()分页,查询时仅返回必要字段(如{field: 1, _id: 0})。mongostat、mongotop或第三方工具(如Prometheus+Grafana)实时监控性能。mongodump),更新MongoDB至最新版本以获取性能优化。/etc/security/limits.conf中增加mongod的nofiles和nproc限制(如设为100000)。deadline或noop,减少I/O延迟。注意:调优前需备份数据,根据实际负载和硬件环境调整参数,优先通过监控定位瓶颈再针对性优化。