logstash
第一步
vi config/logstash.conf
input { kafka { bootstrap_servers => "127.0.0.1:9092" # 从kafka 中读取匹配到的topic topics => ["host-message","host-secure"] # kafka收集到的文件格式是json,因此这里选择json解析 codec => "json" } } output { stdout { codec => rubydebug } }
检查语法:logstash -f 配置文件 -t
启动服务:logstash -f 配置文件
第二步
input { kafka { bootstrap_servers => "127.0.0.1:9092" topics => ["host-message","host-secure"] # kafka收集到的文件格式是json,因此这里选择json解析 codec => "json" } } output { elasticsearch { # 把 topics => ["host-message","host-secure"] 传递给 elasticseach 中"host-message-%{+YYYY.MM.dd}"这个index。这样的情况下host-message和 host-secre都会混在一起不方便查看 index => "host-message-%{+YYYY.MM.dd}" hosts => ["172.16.100.6:9200"] } }
检查语法:logstash -f 配置文件 -t
启动服务:logstash -f 配置文件
第三步
input { kafka { bootstrap_servers => "127.0.0.1:9092" topics => ["host-message","host-secure"] # kafka收集到的文件格式是json,因此这里选择json解析 codec => "json" } } output { if [fields][type] == "host-message" { elasticsearch { index => "host-message-%{+YYYY.MM.dd}" hosts => ["172.16.100.6:9200"] } } if [fields][type] == "host-secure" { elasticsearch { index => "host-secure-%{+YYYY.MM.dd}" hosts => ["172.16.100.6:9200"] } } }
检查语法:logstash -f 配置文件 -t
启动服务:logstash -f 配置文件
logstash 也可以通过命令行传递配置文件 **输出到标准输出**
/opt/logstash/bin/logstash -e ' input { stdin { } } output { stdout { codec =>rubydebug } }'
输出到文件
/opt/logstash/bin/logstash -e ' input { stdin { } } output { file { path => "/tmp/test-%{+YYYY.MM.dd}.log" gzip => true } }'
输出到elasticsearch
/opt/logstash/bin/logstash -e ' input{ stdin{ } } output{ elasticsearch{ hosts => ["10.4.7.12:9200"] index => "logstash-test-%{+YYY.MM.dd}" } }'
/opt/logstash/bin/logstash -e ' input{ stdin{ } } output{ redis{ host => ["10.4.7.21:6379"] data_type => "list" key => "test" } }'
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏