Kafka Windows下启动命令

kafka 参数 zookeeper 和 bootstrap-server 的区别

  • zookeeper:旧版 kafka 参数
  • bootstrap-server:新版 kafka 参数

原因:Kafka开发团队重写了ZooKeeper的Quorum控制器代码并嵌入到Kafka中。所以从v2.8版本开始,Kafka不再依赖ZooKeeper

实例

# 旧版(< v2.2)
kafka-topics.sh --zookeeper localhost1:2181,localhost2:2181,localhost3:2181 --create --topic ..
​
# 新版(>= v2.2)
kafka-topics.sh --bootstrap-server localhost1:9092 --create --topic ..

其中,2181是ZooKeeper的监听端口,9092是Kafka的监听端口。

旧版用--zookeeper参数,主机名(或IP)和端口用ZooKeeper的,也就是server.properties文件中zookeeper.connect属性的配置值

新旧用--bootstrap-server参数,主机名(或IP)和端口用某个节点的即可,即主机名(或主机IP):9092。

windows启用 kafka 命令

# 1.启动zookeeper,kafka高版本已经集成 zookeeper
bin\windows\zookeeper-server-start.bat config\zookeeper.properties
​
# 2.启动kafka服务器
bin\windows\kafka-server-start.bat config\server.properties
​
# 3.创建topic
bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic singleTopic
​
# 4.查看topics
bin\windows\kafka-topics.bat --bootstrap-server localhost:9092 --list
​
# 5.查看topic 详细信息
bin\windows\kafka-topics.bat --bootstrap-server localhost:9092 --describe --topic singleTopic
​
# 6.删除topic
>bin\windows\kafka-topics.bat --delete --bootstrap-server localhost:9092 --topic singleTopic
​
# 7.关闭 kafka 服务器
bin\windows\kafka-server-stop.bat

集群配置

> copy config/server.properties config/server-1.properties
> copy config/server.properties config/server-2.properties

现在编辑这些新文件并设置如下属性:

config/server-1.properties:
    broker.id=1
    listeners=PLAINTEXT://:9093
    log.dir=/tmp/kafka-logs-1
 
config/server-2.properties:
    broker.id=2
    listeners=PLAINTEXT://:9094
    log.dir=/tmp/kafka-logs-2
> bin\windows\kafka-server-start.bat config\server-1.properties 
​
>bin\windows\kafka-server-start.bat config\server-2.properties
​
# 创建一个副本为3的新topic
# 注意,副本数不能大于主机数,但是可以有多个分区
>bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 3 --partitions 1 --topic replicationTopic
​
# 查看 topic 详情
bin\windows\kafka-topics.bat --bootstrap-server localhost:9092 --describe --topic replicationTopic
​
# console result:
Topic: replicationTopic TopicId: _HHXXeS0Smmyl2MihBZxtw PartitionCount: 1       ReplicationFactor: 3    Configs: segment.bytes=1073741824
        Topic: replicationTopic Partition: 0    Leader: 0       Replicas: 0,1,2 Isr: 0,1,2

创建生产者和消费者

# 创建生产者
bin\windows\kafka-console-producer.bat --bootstrap-server localhost:9092 --topic singleTopic
​
# 创建消费者
bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic singleTopic --from-beginning

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值