1. log Rotate command
> use admin
> db.adminCommand({logRotate : 1})
2. logRotate - kill (mongodb 3.0 부터 가능)
# kill -SIGUSR1 ${pidof mongod}
- 2번째 방법의 경우 mongod.conf 의 logAppend, logRatate 정보에 따라 달라진다.
systemLog:
destination: file
logAppend: true
logRotate: rename
path: /data/logs/mongodb.log
systemLog.logAppend
Type: boolean
Default: False
When true, mongos or mongod appends new entries to the end of the existing log file when the mongos or mongod instance restarts. Without this option, mongod will back up the existing log and create a new file.
systemLog.logRotate
Type: string
Default: rename
New in version 3.0.0.
The behavior for the logRotate command. Specify either rename or reopen:
- rename renames the log file.
- reopen closes and reopens the log file following the typical Linux/Unix log rotate behavior. Use reopen when using the Linux/Unix logrotate utility to avoid log loss.
If you specify reopen, you must also set systemLog.logAppend to true.
명령어 cronjob으로 등록
# pgrep -f mongod | xargs kill -SIGUSR1 $1
결과 (일자별로 새로운 파일 생성)
mongodb.log
mongodb.log.2019-06-02T-05-25-13
mongodb.log.2019-06-03T-05-25-13
참조 문서 :
https://docs.mongodb.com/manual/reference/configuration-options/#systemLog.syslogFacility
https://www.percona.com/blog/2018/09/27/automating-mongodb-log-rotation/
'Database > MongoDB' 카테고리의 다른 글
systemctl로 mongodb 서비스모드로 시작하기 (0) | 2019.06.11 |
---|---|
MongoDB 영속성 (Persistence) (0) | 2019.06.06 |
MongoDB Max connection 변경 (with Ansible) (0) | 2019.05.31 |