[Logstash] 如何找到并清空logstash-input-file插件的文件监控记录(sincedb)?

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/winx_coder/article/details/53419818

Logstash版本

2.4.1

问题

在Logstash中,已经通过logstash-input-file插件导入了一些本地日志文件。现在需要重新导入这些日志文件,但是logstash-input-file插件会自动忽略之前已经读取的文件。要想重新导入之前的文件,只能清空文件监控记录。

那么,文件监控记录到底在哪里?

 

官方插件说明文档中,关于文件监控记录(sincedb)的说明:

 The plugin keeps track of the current position in each file byrecording it in a separate file named sincedb. Thismakes it possible to stop and restart Logstash and have it pick up where itleft off without missing the lines that were added to the file while Logstashwas stopped

......

By default, the sincedb file is placed in the home directory of the user running Logstash with a filename basedon the filename patterns being watched.

可见,sincedb默认保存在当前用户的Home目录下。 但是,在当前用户的Home目录下执行ls命令,没有找到所谓的sincedb文件?

解决

1.sincedb文件是隐藏文件,需要在Home目录下执行显示所有文件的命令,才能显示出来:

sudo ls –a

文件名形如:.sincedb_647fd4a05bc6792451e1013e54ce1bac

2.用rm命令删除这些.sincedb_开头的文件即可。

rm .sincedb_647fd4a05bc6792451e1013e54ce1bac

注意:

在执行删除操作之前,需要先关闭Logstash,否则Logstash会报错。


3.重新启动Logstash之前,要记得删除已经导入Elasticsearch的文档。否则,当Logstash再次导入文档后,ES中会出现重复的文档。

参考资料:http://www.wklken.me/posts/2015/04/26/elk-for-nginx-log.html


警告:被删除的数据难以恢复,谨慎操作。

猜你喜欢

转载自blog.csdn.net/winx_coder/article/details/53419818
今日推荐