MongoDB 日志配置与管理
一 基础配置
systemLog:
destination: file # 输出到文件;也可设为 stdout 或 syslog
path: /var/log/mongodb/mongod.log
logAppend: true # 追加而非覆盖
verbosity: 1 # 全局日志详细度,0-5,越高越详细
quiet: false
修改后使用服务管理工具使配置生效,例如:sudo systemctl restart mongod。以上为常见且通用的基础配置项与生效方式。二 日志轮转
/var/log/mongodb/mongod.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 644 mongodb mongodb
sharedscripts
postrotate
if pgrep mongod >/dev/null; then
systemctl kill --signal=SIGUSR1 mongod 2>/dev/null || \
/bin/kill -SIGUSR1 $(cat /var/run/mongodb/mongod.pid 2>/dev/null) >/dev/null 2>&1
fi
endscript
}
三 日志级别与动态调优
四 审计日志与注意事项
五 易混淆概念 存储引擎 Journal 与 服务器日志