Kafka 相关命令(windows版)

启动服务器

> bin\windows\kafka-server-start.bat config\server.properties

创建一个topic

> bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

查看topic

> bin\windows\kafka-topics.bat --list --zookeeper localhost:2181

启动一个生产者

> bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test
# 然后在控制台输入需要发送的消息

启动一个消费者

> bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning

设置多代理集群

> copy config/server.properties config/server-1.properties
> copy config/server.properties config/server-2.properties
# 创建后在config文件夹中修改  server-1.properties 和 server-2.properties 的配置
# broker.id属性是集群中每个节点的名称,这一名称是唯一且永久的。为了避免所有的代理尝试在同一个端口注册,或者覆盖彼此的数据,需要重写端口和日志目录,因为我是在同一台机器上运行的
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,分区为1的新topic

> bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic

查看代理状态

> bin\windows\kafka-topics.bat --describe --zookeeper localhost:2181 --topic my-replicated-topic
# 以下是控制台输出的信息
> Topic:my-replicated-topic   PartitionCount:1    ReplicationFactor:3 Configs:
> Topic: my-replicated-topic  Partition: 0    Leader: 1   Replicas: 1,2,0    Isr: 1,2,0
# leader:是负责给定分区所有读写操作的节点。每个节点都是随机选择的部分分区的领导者
# replicas:是复制分区日志的节点列表,不管这些节点是leader还是follower
# isr:是一组同步的副本,是replicas列表的子集

获取节点processid,杀死对应进程

> wmic process where "caption = 'java.exe' and commandline like '%server-1.properties%'" get processid
# 以下是控制台输出信息
> ProcessId
> 6016
# 杀死pid为6016的进程
> taskkill /pid 6016 /f
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值