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

猜你喜欢

转载自blog.csdn.net/weixin_44784018/article/details/109488122