kafka 和 Logstash的使用

1. 前提

已有logstash
已有filebeat
已有kafka
查询当前kafka中topics
./kafka-topics.sh --zookeeper 192.168.220.123:2181 --list

__consumer_offsets
test
test1
testbylixr

ELK的配置,请参考:http://www.jianshu.com/p/460a307adebb

2. Filebeat 配置

- input_type: log
  document_type: login
  paths:
     - /data/ncyd/logs/epg/login.log
     - /data/ncyd/epg2logs/epg/login.log
output.elasticsearch:
  hosts: ["ip:9200"]

3. Logstash 配置

input {     
  beats {
    port => "5044"
   }
}
output {
        if [type] == "login" {
            kafka {
                topic_id => "login"
                bootstrap_servers => "ip:9092"
             }
        }
        if [type] == "tomcataccess" {
             elasticsearch {
                hosts => ["ip:9200"]
                index => "logstash-tomcat-accesslog-%{+YYYY.MM.dd}"
                #codec => "json"
           }
        }   
}

4. 访问应用产生login日志

5. 查看kafka中是否有相应topic和数据

  1. 查看topic
bash-4.3# ./kafka-topics.sh  --zookeeper 192.168.220.123:2181 --list
__consumer_offsets
login
test
test1
testbylixr
  1. 查看topic中数据
./kafka-console-consumer.sh --zookeeper 192.168.220.123:2181 --from-beginning --topic login
2017-01-18 13:41:00 {"apkPlatform":"ZTE","apkVersionCode":"60","apkVersionName":"2.0.0","ipAddr":"ip","macAddr":"ABCDEFG","softwareVersion":"1.1.1","stbId":"stbidForTest","stbType":"OTTForTest","userId":"jl016"}

6. 其他

  1. 在这个过程中遇到一个很奇怪的错误
    java.io.IOException: Unreasonable length = 1701969920
    不清楚报错原因,重启了kafka和zookeeper之后 就变正常啦。

  2. 写数据
    bin/kafka-console-producer.sh --broker-list 192.168.220.123:9092 --topic login

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 本人陆陆续续接触了ELK的1.4,2.0,2.4,5.0,5.2版本,可以说前面使用当中一直没有太多感触,最近使用...
    三杯水Plus阅读 4,279评论 0 12
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,773评论 19 139
  • 一、入门1、简介Kafka is a distributed,partitioned,replicated com...
    HxLiang阅读 3,701评论 0 9
  • 本文转载自http://dataunion.org/?p=9307 背景介绍Kafka简介Kafka是一种分布式的...
    Bottle丶Fish阅读 5,592评论 0 34
  • 我失眠了? 是的,你失眠了。 可你不是凌晨三点悠然绽放的海棠花,手机屏幕悠悠的白光,投射在你憔悴的脸上。 黑夜笼罩...
    方厘几粒阅读 287评论 0 0

友情链接更多精彩内容