1,在官网下载filebeat 官网下载地址: https://www.elastic.co/cn/downloads

2,下载kafka 下载地址: http://archive.apache.org/dist/kafka/

3,下载完kafka之后,直接解压即可 wget -c http://archive.apache.org/dist/kafka/2.1.1/kafka_2.11-2.1.1.tgz tar -xf kafka-2.1.1-src.tg

4,kafka常用命令介绍 进入kafka目录 cd kafka_2.11-2.1.1

启动zookeeper ./bin/zookeeper-server-start.sh ./config/zookeeper.properties &

启动kafka ./bin/kafka-server-start.sh ./config/server.properties &

创建topic ./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test 列出topic ./bin/kafka-topics.sh --list --zookeeper localhost:2181

启动生产者并发送消息 ./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

开启另外一个终端,启动消费者接受消息 ./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

效果图如下: 生产者: 消费者:

5,测试成功,现在我们配置filebeat的配置文件 filebeat.inputs:

  • type: log enabled: true paths: #- /var/log/*.log
    • /var/log/messages #监听的日志文件 filebeat.config.modules: path: ${path.config}/modules.d/*.yml reload.enabled: false setup.template.settings: index.number_of_shards: 3 output.kafka: enabled: true hosts: ["10.10.100.215:9092","10.10.100.216:9092","10.10.100.217:9092"] # kafka集群配置 topic: "caolihua01" #kafka 订阅的主题

6,启动filebeat并查看控制台输出

7,查看kafka是否接受到filebeat收集到的日志信息 ./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning