- 安装:
tar -zxvf kafka_2.11-0.10.0.1.tgz |
zookeeper.connect=192.168.56.101:2181,192.168.126.102:2181,192.168.126.103:2181 |
broker.id=1 log.dirs=/app/kafka_2.11-0.10.0.1/logs zookeeper.connect=192.168.56.101:2181,192.168.56.102:2181,192.168.56.103:2181 delete.topic.enable=true listeners=PLAINTEXT://192.168.56.101:9092 advertised.listeners=PLAINTEXT://192.168.56.101:9092 |
|
- 配置环境变量
(1)vi /etc/profile #set kafka environment export KAFKA_HOME=/app/kafka_2.11-0.10.0.1 export PATH=$PATH:$KAFKA_HOME/bin (2)生效环境变量 source /etc/profile |
- 主要命令脚本
启动(需先启动zk): kafka-server-start.sh /app/kafka_2.11-0.10.0.1/config/server.properties 后台方式启动: kafka-server-start.sh -daemon /app/kafka_2.11-0.10.0.1/config/server.properties 停止命令: kafka-server-stop.sh --创建topic kafka-topics.sh --zookeeper 192.168.56.101:2181 --create --topic testTopic --partitions 4 --replication-factor 2 注: partitions指定topic分区数,replication-factor指定topic每个分区的副本数 --查看所有topic列表 kafka-topics.sh --zookeeper 192.168.56.101:2181 --list --查看指定topic信息 kafka-topics.sh --zookeeper 192.168.56.101:2181 --describe --topic testTopic --生产数据 kafka-console-producer.sh --broker-list 192.168.56.101:9092 --topic testTopic --消费数据 --老版本 kafka-console-consumer.sh --zookeeper 192.168.56.101:2181 --topic testTopic --from-beginning (不加from-beginning为从最新消息开始消费) --新版本 kafka-console-consumer.sh --bootstrap-server 192.168.56.101:9092 --topic testTopic --from-beginning --删除topic主题或log begin (通过调整清理策略删除数据) 需有这两个配置 # 启用删除主题 delete.topic.enable=true # 检查日志段文件的间隔时间,以确定是否文件属性是否到达删除要求。 log.retention.check.interval.ms=10000 --查看topic策略 kafka-configs.sh --zookeeper 192.168.56.101:2181 --describe --entity-type topics --entity-name testTopic --如果想保留主题,只删除主题现有数据(log)。可以通过修改数据保留时间实现 kafka-configs.sh --zookeeper 192.168.56.101:2181 --entity-type topics --entity-name testTopic --alter --add-config retention.ms=10000 --删除config策略 kafka-configs.sh --zookeeper 192.168.56.101:2181 --entity-type topics --entity-name testTopic --alter --delete-config retention.ms #慎用 #kafka-topics.sh --delete --zookeeper 192.168.56.101:2181 --topic testTopic --删除topic主题或log end --从文件导入topic,使用connector connect-standalone.sh config/connect-standalone.properties config/connect-file-source.properties config/connect-file-sink.properties 查看topic某分区偏移量最大(小)值 kafka-run-class.sh kafka.tools.GetOffsetShell --topic testTopic --time -1 --broker-list 192.168.56.101:9092 --partitions 0 |
- 问题
- sparkStreaming 连接报错:org.apache.spark.SparkException: Couldn't find leader offsets for Set([testTopic2,0], [testTopic2,1], [testTopic2,2], [testTopic2,3])
listeners=PLAINTEXT://192.168.56.101:9092 advertised.listeners=PLAINTEXT://192.168.56.101:9092 这两个配置项没有配置,导致外部无法通过正确的地址连接kafka,配置后重启kafka解决 |