快捷导航

云服务器安装mongodb如何清理日志文件

[复制链接]
查看: 702|回复: 0
发表于 2023-6-29 15:45:11 | 显示全部楼层 |阅读模式
mongodb清理日志文件的方法:1、使用mongodb数据库命令“db.runCommand({logRotate:1})”登录到mongod和mongos实例中;2、然后使用“cat /dev/null > [文件名]”系统命令清空日志文件,保留日志即可。具体内容如下:一、日志清理步骤1.使用数据库命令rotate日志,分别登录到mongod和mongos实例上# mongo --host localhost:27xxxMongoDB shell version: 2.6.xconnecting to: localhost:27xxx/testreplicaset003:SECONDARY> dbtestreplicaset003:SECONDARY> use adminswitched to db adminreplicaset003:SECONDARY> db.runCommand({logRotate:1}){ "ok" : 1 }replicaset003:SECONDARY> replicaset001:ARBITER> exitbye# lltotal 22195424-rw-r--r-- 1 mongod mongod 1124 Dec 20 11:04 mongoc.log-rw-r--r-- 1 mongod mongod 33341517 Dec 20 10:59 mongoc.log.2016-12-20T03-01-17-rw-r--r-- 1 mongod mongod 4944 Dec 20 11:07 mongod1.log-rw-r--r-- 1 mongod mongod 680817815 Dec 20 11:03 mongod1.log.2016-12-20T03-04-01-rw-r--r-- 1 mongod mongod 1030 Dec 20 11:07 mongod2.log-rw-r--r-- 1 mongod mongod 1813798574 Dec 20 11:07 mongod2.log.2016-12-20T03-07-43-rw-r--r-- 1 mongod mongod 2413 Dec 20 11:07 mongod.log-rw-r--r-- 1 mongod mongod 1880520643 Dec 20 11:06 mongod.log.2016-12-20T03-06-17-rw-r--r-- 1 mongod mongod 2071 Dec 20 11:05 mongos.log-rw-r--r-- 1 mongod mongod 18319577575 Dec 20 10:52 mongos.log.2016-12-20T02-53-042.使用系统命令清空日志文件,保留日志# cat /dev/null > mongos.log.2016-12-20T02-53-04# cat /dev/null > mongod.log.2016-12-20T03-06-17# cat /dev/null > mongod2.log.2016-12-20T03-07-43# cat /dev/null > mongod1.log.2016-12-20T03-04-01# cat /dev/null > mongoc.log.2016-12-20T03-01-17# [root@dev-mongo-001-242 mongo]# lltotal 28-rw-r--r-- 1 mongod mongod 1338 Dec 20 11:09 mongoc.log-rw-r--r-- 1 mongod mongod 0 Dec 20 11:10 mongoc.log.2016-12-20T03-01-17-rw-r--r-- 1 mongod mongod 7670 Dec 20 11:10 mongod1.log-rw-r--r-- 1 mongod mongod 0 Dec 20 11:10 mongod1.log.2016-12-20T03-04-01-rw-r--r-- 1 mongod mongod 3594 Dec 20 11:10 mongod2.log-rw-r--r-- 1 mongod mongod 0 Dec 20 11:10 mongod2.log.2016-12-20T03-07-43-rw-r--r-- 1 mongod mongod 5247 Dec 20 11:10 mongod.log-rw-r--r-- 1 mongod mongod 0 Dec 20 11:09 mongod.log.2016-12-20T03-06-17-rw-r--r-- 1 mongod mongod 2297 Dec 20 11:10 mongos.log-rw-r--r-- 1 mongod mongod 0 Dec 20 11:09 mongos.log.2016-12-20T02-53-04二、思路1.一般情况下数据库的日志理清都会有两种方式,一种是通过数据库命令,一种是系统命令。2.日志的清理原文件一定要保留,不能使用rm来删除文件,切忌,我们目的是释放空间。3.部分公司要求把日志归档到大数据平台以供分析使用,因此,在清理日志文件的时候需要搞清楚,切勿盲目蛮干。三、官方文档https://docs.mongodb.com/v2.6/tutorial/rotate-log-files/
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

精彩推荐

尚云驿站

  • 投诉建议:350467567@qq.com
  • 软文投稿:350467567@qq.com
  • 友情链接:350467567@qq.com

云服务支持

精彩文章,快速检索

Copyright 尚云驿站  Powered by©  技术支持:飛    ( 闽ICP备2025116718号-15 )