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 配置文件
标签:配置文件,json,kafka,host,message,logstash 来源: https://www.cnblogs.com/wangend/p/16365009.html