启动zookeeper服务:
bin\windows\zookeeper-server-start.bat config\zookeeper.properties
启动kfaka服务:
bin\windows\kafka-server-start.bat config\server.properties
停止kafka
bin\windows\kafka-server-stop.bat
停止zookeeper
bin\windows\zookeeper-server-stop.bat
创建topic:
bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic testDemo
修改topic分区(分区数只能增加不能减少)
bin\windows\kafka-topics.bat --zookeeper localhost:2181 --alter --topic HelloWorld --partitions 2
描述topic(分区数量,主题覆盖的配置,每个分区副本清单)
bin\windows\kafka-topics.bat --describe --zookeeper localhost:2181 --topic my-replicated-topic
删除主题
bin\windows\kafka-topics.bat --zookeeper localhost:2181 --delete --topic HelloWorld
列出集群里所有topic:
bin\windows\kafka-topics.bat --list --zookeeper localhost:2181
启动produce:
kafka-console-producer.bat --broker-list localhost:9092 --topic testDemo
启动consumer:
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic testDemo --from-beginning
覆盖主题默认参数
命令格式:
bin\windows\kafka-configs.bat -zookeeper localhost:2181 -entity-type topics -entity-name testDemo2 -alter -add-config log.retention.hours=120
可用主题配置参数
key | value | 描述 |
cleanup.policy | compact | 只有包含了指定的key的消息会被保留下来(压缩日志),其他的被丢掉 |
compression.type | “gzip”、“snappy”、“lz4” | broker将消息批次写入磁盘时所使用的压缩类型。 |
delete.retention.ms | 整数(毫秒数) | 被标识为待删除的数据能保留多久,以ms为单位,该参数只对压缩日志类型的主题有效 |
file.delete.delay.ms | 整数(毫秒数) | 从磁盘上删除日志片段和索引之前可以等待多长时间,以ms为单位 |
flush.messages | 整数 | 需要收到多少消息,才能将他们刷新到磁盘 |
flush.ms | 整数(毫秒数) | 将消息刷新到磁盘之前可以等待多长时间 |
index.interval.bytes | 日志片段的两个索引之间能够容纳的消息字节数 | |
max.message.bytes | 最大消息字节数 | |
message.format.version | broker将消息写入磁盘时所用的消息格式,必须是有效的API版本,例如“0.10.0” | |
message.timestamp.difference.max.ms | 消息自带的时间戳和broker收到消息时时间戳之间最大差值,ms单位 | |
message.timestamp.type | CreateTime、LogAppendTime | 将消息写磁盘时采用哪种时间戳,目前支持两种格式,CreateTime客户端指定时间戳,LogAppendTime消息被写入分区时间戳。 |
min.cleanable.dirty.ratio | 可用分区的最少同步副本 | |
preallocate | 如果被设置为true,需要为新的日志片段预分配空间 | |
retention.bytes | 主题能够保留的消息量,以字节为单位 | |
retention.ms | 主题能够保留消息多长时间,ms单位 | |
segment.bytes | 日志片段的消息字节数 | |
segment.index.bytes | 单个日志片段的最大索引字节数 | |
segment.jitter.bytes | 滚动日志片段时,在segment.ms基础上增加随机毫秒数 | |
unclean.leader.election.enable | 如果被设置为true,不彻底的首领选择无效 | |