logstash从kafka读json格式日志输入es

老大让研究ELK,经过几天的摸索,终于把流程跑通了。
版本:
kafka 0.10.2.0
logstash 5.3.0
elasticsearch 5.3.0
修改logstash中配置文件
vi logstash.conf

input {
    kafka{
        bootstrap_servers => ["10.10.10.10:9092"]
        group_id => "es"
        topics => ["myTest"]
        codec => json {
                 charset => "UTF-8"
        }
    }
}

output {
        # 处理后的日志落到本地文件
        file {
                path => "/data/logstash/test.log"
                flush_interval => 0
       }
       # 处理后的日志入es
       elasticsearch {
        hosts => ["10.10.10.20:9200"]
        index => "test"
        id => "my_plugin_id"
        document_id => "%{userid}"
        document_type => "mytype"
       }
}

其中在input 中指定codec => json就可以解析kafka中json字符串
output中index 指定索引,document_type指定类型,document_id指定主键
如果有重复的主键会自动被覆盖!

发布了118 篇原创文章 · 获赞 25 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/lhxsir/article/details/95991529