kafka 常用命令
Kafka
解压,进入kafka目录下的bin目录
启动zk
nohup ./zookeeper-server-start.sh ../config/zookeeper.properties &
nohup ./bin/zookeeper-server-start.sh ./config/zookeeper.properties &
启动kafka
nohup ./kafka-server-start.sh ../config/server.properties &
nohup ./bin/kafka-server-start.sh ./config/server.properties &
创建topic
./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
或
./kafka-topics.sh --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test2 --create
列出topic
./kafka-topics.sh --list --zookeeper localhost:2181
或
./kafka-topic --zookeeper localhost:2181 --list
启动生产者并发送消息
./kafka-console-producer.sh --broker-list localhost:9092 --topic zyl
输入消息
nihao
china
另外开个终端,启动消费者接受消息
./kafka-console-consumer.sh --zookeeper localhost:2181 --topic zyl --from-beginning
可以接受到
nihao
china
另外开个终端,可以看到有4个进程(分别为zk、kafka、控制台消费者、控制台生产者)
[root@aa bin]# jps | grep -v Jps
9802 QuorumPeerMain
10392 Kafka
10956 ConsoleConsumer
10887 ConsoleProducer
使用集群3个节点(多个节点也同理,加上之前的,我一共弄了4个节点)
拷贝并修改配置文件
cp server.properties server1.properties
cp server.properties server2.properties
cp server.properties server3.properties
nohup ./kafka-server-start.sh ../config/server1.properties &
nohup ./kafka-server-start.sh ../config/server2.properties &
nohup ./kafka-server-start.sh ../config/server3.properties &
[root@aa bin]# ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic(注意,指定的是3)
Created topic "my-replicated-topic".
[root@aa bin]# ./kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic
Topic:my-replicated-topic PartitionCount:1 ReplicationFactor:3 Configs:
Topic: my-replicated-topic Partition: 0 Leader: 2 Replicas: 2,3,0 Isr: 2,3,0
[root@aa bin]# ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 4 --partitions 1 --topic my-replicated-topic
Error while executing topic command Topic "my-replicated-topic" already exists.
kafka.common.TopicExistsException: Topic "my-replicated-topic" already exists.
at kafka.admin.AdminUtils$.createOrUpdateTopicPartitionAssignmentPathInZK(AdminUtils.scala:171)
at kafka.admin.AdminUtils$.createTopic(AdminUtils.scala:156)
at kafka.admin.TopicCommand$.createTopic(TopicCommand.scala:86)
at kafka.admin.TopicCommand$.main(TopicCommand.scala:50)
at kafka.admin.TopicCommand.main(TopicCommand.scala)
[root@aa bin]# ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 4 --partitions 1 --topic my-replicated-topic2
Created topic "my-replicated-topic2".
[root@aa bin]# ./kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic2
Topic:my-replicated-topic2 PartitionCount:1 ReplicationFactor:4 Configs:
Topic: my-replicated-topic2 Partition: 0 Leader: 1 Replicas: 1,2,3,0 Isr: 1,2,3,0
[root@aa bin]# ./kafka-topics.sh --describe --zookeeper localhost:2181 --topic zyl
Topic:zyl PartitionCount:1 ReplicationFactor:1 Configs:
Topic: zyl Partition: 0 Leader: 0 Replicas: 0 Isr: 0
启动生产者并发送消息
./kafka-console-producer.sh --broker-list localhost:9092 --topic my-replicated-topic
另外开个终端,启动消费者接受消息
./kafka-console-consumer.sh --zookeeper localhost:2181 --from-beginning --topic my-replicated-topic
另外开个终端,可以看到有9个进程(分别为1个zk、4个kafka、2个控制台消费者、2个控制台生产者)
[root@aa ~]# jps | grep -v Jps
9802 QuorumPeerMain
10392 Kafka
11547 Kafka
12007 ConsoleProducer
10956 ConsoleConsumer
10887 ConsoleProducer
11469 Kafka
12054 ConsoleConsumer
11710 Kafka
查看单独的进程:
ps -ef | grep server.properties | grep -v grep
ps -ef | grep "server1.properties" | grep -v grep
测试leader
杀掉进程,然后--describe查看
[root@aaa bin]# ./kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic
Topic:my-replicated-topic PartitionCount:1 ReplicationFactor:3 Configs:
Topic: my-replicated-topic Partition: 0 Leader: 2 Replicas: 2,3,0 Isr: 2,3,0
可以看到leader是2.
[root@aa bin]# ./kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic2
Topic:my-replicated-topic2 PartitionCount:1 ReplicationFactor:4 Configs:
Topic: my-replicated-topic2 Partition: 0 Leader: 1 Replicas: 1,2,3,0 Isr: 1,2,3,0
可以看到leader是2.
[root@aa bin]# ps -ef | grep server1.properties | grep -v grep
杀掉某个kafka进程
kill -9 11469
./kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic2
Topic:my-replicated-topic2 PartitionCount:1 ReplicationFactor:4 Configs:
Topic: my-replicated-topic2 Partition: 0 Leader: 2 Replicas: 1,2,3,0 Isr: 2,3,0
[root@aa bin]# ./kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic
Topic:my-replicated-topic PartitionCount:1 ReplicationFactor:3 Configs:
Topic: my-replicated-topic Partition: 0 Leader: 2 Replicas: 2,3,0 Isr: 2,3,0
可以看到my-replicated-topic2的leader变成了2。
问题:
1.zookeeper-shell.sh如何使用
2.能不能通过kafka-server-stop.sh停止某个kafka呢
Command must include exactly one action: --list, --describe, --create or --alter
Option Description
------ -----------
--alter Alter the configuration for the topic.
--config <name=value> A topic configuration override for the
topic being created or altered.
--create Create a new topic.
--deleteConfig <name> A topic configuration override to be
removed for an existing topic
--describe List details for the given topics.
--help Print usage information.
--list List all available topics.
--partitions <Integer: # of partitions> The number of partitions for the topic
being created or altered (WARNING:
If partitions are increased for a
topic that has a key, the partition
logic or ordering of the messages
will be affected
--replica-assignment A list of manual partition-to-broker
<broker_id_for_part1_replica1 : assignments for the topic being
broker_id_for_part1_replica2 , created or altered.
broker_id_for_part2_replica1 :
broker_id_for_part2_replica2 , ...>
--replication-factor <Integer: The replication factor for each
replication factor> partition in the topic being created.
--topic <topic> The topic to be create, alter or
describe. Can also accept a regular
expression except for --create option
--topics-with-overrides if set when describing topics, only
show topics that have overridden
configs
--unavailable-partitions if set when describing topics, only
show partitions whose leader is not
available
--under-replicated-partitions if set when describing topics, only
show under replicated partitions
--zookeeper <urls> REQUIRED: The connection string for
the zookeeper connection in the form
host:port. Multiple URLS can be
given to allow fail-over.
kafka 常用命令的更多相关文章
- kafka常用命令
以下是kafka常用命令行总结: 0.查看有哪些主题: ./kafka-topics.sh --list --zookeeper 192.168.0.201:12181 1.查看topic的详细信息 ...
- Kafka学习之四 Kafka常用命令
Kafka常用命令 以下是kafka常用命令行总结: 1.查看topic的详细信息 ./kafka-topics.sh -zookeeper 127.0.0.1:2181 -describe -top ...
- Kafka常用命令收录
目录 目录 1 1. 前言 2 2. Broker默认端口号 2 3. 安装Kafka 2 4. 启动Kafka 2 5. 创建Topic 2 6. 列出所有Topic 3 7. 删除Topic 3 ...
- Hadoop生态圈-Kafka常用命令总结
Hadoop生态圈-Kafka常用命令总结 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.管理Kafka服务的命令 1>.开启kafka服务 [yinzhengjie@s ...
- Kafka常用命令合集
在上一篇文章<Linux安装Kafka>中,已经介绍了如何在Linux安装Kafka,以及Kafka的启动/关闭和创建发话题并产生消息和消费消息.这篇文章就介绍介绍Kafka的那些常用的命 ...
- kafka常用命令笔记
0.查看有哪些主题: ./kafka-topics.sh --list --zookeeper 192.168.0.201:12181 1.查看topic的详细信息 ./kafka-topics.sh ...
- Kafka常用命令及配置文件
创建topic,指定备份分区数 bin/kafka-topics.sh --create --zookeeper zk:2181 --replication-factor 2 --partitions ...
- Kafka常用命令及详细介绍
目录 常用操作 Sentry kafka 清理 Kafka 术语 Kafka 主题剖析 Kafka 生产者 kafka 消费者和消费组 一致性和可用性 写入处理 失败处理 Kafka 客户端一致性 文 ...
- kafka常用命令(cdh5.10.0+kafka)
参考资料:http://kafka.apache.org/quickstart 进入kafka安装目录(CDH安装路径为:/opt/cloudera/parcels/KAFKA):进入bin目录: c ...
随机推荐
- springcloud- FeginClient 调用统一拦截添加请求头 RequestInterceptor ,被调用服务获取请求头
使用场景: 在springcloud中通过Fegin调用远端RestApi的时候,经常需要传递一些参数信息到被调用服务中去,比如从A服务调用B服务的时候, 需要将当前用户信息传递到B调用的服务中去,我 ...
- CSS3 文本超出后显示省略号...
纯用CSS实现,主要采用代码 overflow:hidden; text-overflow:ellipsis;//这是让文本溢出后,显示成省略号. white-space:nowrap;//禁止自动换 ...
- CUDA概述
基本概念和定义 CUDA实际上是一种多平台计算系统,最基本的配置是一台CPU主机和一块显卡,两者都能进行计算.其中CPU主机称为host, GPU称为device,CUDA的API程序的命名和参数命名 ...
- cookie注入原理及注入检测
通常我们的开发人员在开发过程中会特别注意到防止恶意用户进行恶意的注入操作,因此会对传入的参数进行适当的过滤,但是很多时候,由于个人对安全技术了解的不同,有些开发人员只会对get,post这种方式提交的 ...
- flowable DmnEngine和DmnEngineConfiguration
一.DmnEngineConfiguration创建实例 DmnEngineConfiguration 提供了7个公共的静态方法,用于创建自身实例. 其中5个是使用spring的机制加载配置文件. 另 ...
- GPU编程自学2 —— CUDA环境配置
深度学习的兴起,使得多线程以及GPU编程逐渐成为算法工程师无法规避的问题.这里主要记录自己的GPU自学历程. 目录 <GPU编程自学1 -- 引言> <GPU编程自学2 -- CUD ...
- KL散度(Kullback-Leibler_divergence)
KL散度(Kullback-Leibler_divergence) 一. 概念 KL-divergence,俗称KL距离,常用来衡量两个概率分布的距离. 根据shannon的信息论,给定一个字符集的概 ...
- SQL基础五(作业代码)
create database stuinfo create table student ( mid ) not null primary key, mname ) not null ) create ...
- Jmeter用表格查看结果
Sample#:编号类似id Start Time:开始时间 Thread Name:线程名称 Label:请求名称 Sample Time:取样时间ms Status:状态 Bytes:接受字节数 ...
- LOJ2425 NOIP2015 运输计划 【二分+LCA+树上差分】*
LOJ2425 NOIP2015 运输计划 LINK 题意:给你一颗树,可以将任意一条边的权值变成0,然后求m条路径的长度的最小值 思路: 先二分最后的距离ans,然后我们把路程大于ans的所有路径拿 ...