1. Logstash 架构
Logstash 管道三阶段:
Input → Filter → Output
2. stdin 输入
bin/logstash -e 'input{stdin{}}output{stdout{codec=>rubydebug}}'
3. file 输入
3.1 基本配置
input {
file {
path => "/var/log/nginx/access.log"
type => "nginx"
start_position => "end"
}
}
output {
stdout { codec => rubydebug }
}
3.2 关键参数
4. sincedb 机制
- 记录每个文件的读取偏移量
- 断点续传,防止重复采集
- 文件路径 + inode 关联
4.1 start_position 生效条件
- 仅对首次看到的文件生效
- 如果 sincedb 已有记录,start_position 被忽略
5. 错误速查表
6. 总结
- Logstash 管道:Input → Filter → Output
- sincedb 实现断点续传
- start_position 只对新文件生效