1、准备java环境
[root@T-DMP02-10 kafka_2.13-2.4.0]# java -version java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
2、部署zookeeper,参考
3、准备安装包kafka_2.13-2.4.0.tgz,解压
[root@T-DMP02-10 data]# tar zxf kafka_2.13-2.4.0.tgz [root@T-DMP02-10 data]# cd kafka_2.13-2.4.0/config [root@T-DMP02-10 config]# vim server.properties [root@T-DMP02-10 config]# grep '^[a-z]' server.properties broker.id=0 listeners=PLAINTEXT://172.19.70.37:9092 num.network.threads=3 num.io.threads=8 socket.send.buffer.bytes=102400 socket.receive.buffer.bytes=102400 socket.request.max.bytes=104857600 log.dirs=/data/kafka_2.13-2.4.0/kafka-logs num.partitions=1 num.recovery.threads.per.data.dir=1 offsets.topic.replication.factor=1 transaction.state.log.replication.factor=1 transaction.state.log.min.isr=1 log.retention.hours=168 log.segment.bytes=1073741824 log.retention.check.interval.ms=300000 zookeeper.connect=172.19.70.37:2181 zookeeper.connection.timeout.ms=6000 group.initial.rebalance.delay.ms=0 [root@T-DMP02-10 kafka_2.13-2.4.0]# mkdir kafka-logs
3、启动kafka
[root@T-DMP02-10 kafka_2.13-2.4.0]# ./bin/kafka-server-start.sh -daemon ./config/server.properties # -daemon,后台启动
4、kafka基础操作
1)创建topic
[root@T-DMP02-10 kafka_2.13-2.4.0]# bin/kafka-topics.sh --create --zookeeper 172.19.70.37:2181 --replication-factor 1 --partitions 1 --topic test Created topic test.
2)查看已创建的topic列表
[root@T-DMP02-10 kafka_2.13-2.4.0]# bin/kafka-topics.sh --list --zookeeper 172.19.70.37:2181 test
3)模拟生产者生产数据
[root@T-DMP02-10 kafka_2.13-2.4.0]# bin/kafka-console-producer.sh --broker-list 172.19.70.37:9092 --topic test
4)模拟消费者消费数据
[root@T-DMP02-10 kafka_2.13-2.4.0]# bin/kafka-console-consumer.sh --bootstrap-server 172.19.70.37:9092 --from-beginning --topic test