原创 2016-06-07 14:55:53 0236php
MongoDB 日志切换(Rotate Log Files)实战 1. 在mongo shell下,执行logRotate命令: useadmindb.runCommand({logRotate:1}) 须要在mongos,mongod,config server运行。 该方式的变种: a) 在unix shell下运行: mongolocalhost/admin–eval“dbo.runCommahtml
MongoDB 日志切换(Rotate Log Files)实战python
1. 在mongo shell下,执行logRotate命令: mongodb
1shell 2工具 |
|
须要在mongos,mongod,config server运行。spa
该方式的变种:unix
a) 在unix shell下运行:
1 |
|
b) Bash脚本:
1 2 3 4 5 6 7 8 9 |
|
c) 将以下脚本保存到logRotate.js文件:
1 |
|
建立脚本logRotate.sh:
1 2 3 4 5 |
|
d) logRotate.sh //写到计划任务crontab便可(须要expect软件包)
1 2 3 4 5 6 7 |
|
2. 使用SIGUSR1信号:
1 2 |
|
该方法的变种:
a) 用python写的定时脚本,天天产生一个新的log,超过7天的log自行删除。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
在root下crontab –e编辑定时任务
1 |
|
3. 日志管理工具logrotate
自动化的最好方式是使用logrotate,其中copytruncate参数能更好工做。
拷贝如下代码到/etc/logrotate.d/mongodb文件中,确保脚本中的路径和文件名正确。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
4. Mongodb bug mongodb稳定性差强人意。在切换过程当中也会致使mongodb进程终止。 具体内容能够查看下mongodb bug系统:SERVER-473九、SERVER-3339。