Kafka操作命令

启动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

可用主题配置参数

keyvalue描述
cleanup.policycompact只有包含了指定的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.typeCreateTime、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,不彻底的首领选择无效
   
   

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值