kafka+flume使用

一、安装使用kafka
1、下载kafka安装包
选择二进制下载
二进制包
2、解压

tar -zxvf kafka_2.13-2.6.0.tgz -C ./

解压之后进入kafka目录kafka目录结构
3、修改配置文件(config目录下)

vim server.properties

要求全集群唯一

broker.id=0

允许外部连接

listeners=PLAINTEXT://0.0.0.0:9092
advertised.listeners=PLAINTEXT://192.168.xx.xx:9092

zookeeper节点地址,用逗号分隔“,”

zookeeper.connect=localhost:2181

4、启动zookeeper(在kafka目录下),后台运行

bin/zookeeper-server-start.sh -daemon config/zookeeper.properties

启动之后能看到进程QuorumPeerMain

jps
5074 Jps
5032 QuorumPeerMain

5、启动kafka

bin/kafka-server-start.sh -daemon config/server.properties

启动之后能看到进程Kafka

jps
5446 Kafka
5510 Jps
5032 QuorumPeerMain

----停止kafka进程

bin/kafka-server-stop.sh

----启动消费者

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092  --topic 主题名 --from-beginning

----启动生产者

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic 主题名

二、flume安装和使用
1、下载安装包
选择二进制下载
下载flume安装包
2、解压

tar -xvf apache-flume-1.9.0-bin.tar

解压之后进入flume目录
flume目录
3、修改配置文件(config目录下)

cp flume-conf.properties.template flume-conf.properties
vim flume-conf.properties
a1.sources = s1
a1.channels = c1
a1.sinks = k1

a1.sources.s1.type = syslogudp
a1.sources.s1.bind = 0.0.0.0
a1.sources.s1.port = 44444

a1.channels.c1.type = memory

a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.kafka.topic = DjangoLog(主题名称)
a1.sinks.k1.kafka.bootstrap.servers = 192.168.xx.xx:9092

a1.sources.s1.channels = c1
a1.sinks.k1.channel = c1

4、启动flume

bin/flume-ng agent --conf conf/ --conf-file conf/flume-conf.properties --name a1 &

5、测试flume能否收到消息

telnet 192.168.xx.xxx 44444
telnet 192.168.xx.xxx 44444
Trying 192.168.xx.xxx...
Connected to 192.168.xx.xxx.
Escape character is '^]'.
123
OK

6、使用 kafka消费者查看

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092  --topic DjangoLog --from-beginning
123
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值