文章目录
命名说明帮助kafka-topics.sh命令帮助说明:kafka-topics.sh --help或者kafka-topics.sh
创建topic以及zk中的变化查看创建topiczk中的变化查看客户端发布者实时生成对应topic的事件(或者称之为消息内容)客户端消费者实时订阅对应topic的事件(或者称之为消息内容)
命名说明帮助
localhost
:kafka_2
.13-2.6.0 gaoxinfu$ pwd
/Users
/gaoxinfu
/using
/kafka_2
.13-2.6.0
localhost
:kafka_2
.13-2.6.0 gaoxinfu$ ls
-la
total
152
drwxr
-xr
-x@
12 gaoxinfu staff
384 10 21 10:05 .
drwxr
-xr
-x@
43 gaoxinfu staff
1376 10 20 18:06 ..
-rw
-r
--r
--@
1 gaoxinfu staff
8196 10 21 09:15 .DS_Store
-rw
-r
--r
--@
1 gaoxinfu staff
29975 7 29 02:16 LICENSE
-rw
-r
--r
--@
1 gaoxinfu staff
337 7 29 02:16 NOTICE
drwxr
-xr
-x@
35 gaoxinfu staff
1120 7 29 02:23 bin
drwxr
-xr
-x@
17 gaoxinfu staff
544 7 29 02:23 config
drwxr
-xr
-x
4 gaoxinfu staff
128 10 21 09:15 data
drwxr
-xr
-x@
104 gaoxinfu staff
3328 7 29 02:23 libs
drwxr
-xr
-x
19 gaoxinfu staff
608 10 21 11:16 logs
-rw
------- 1 gaoxinfu staff
27172 10 21 10:08 nohup
.out
drwxr
-xr
-x@
3 gaoxinfu staff
96 7 29 02:23 site
-docs
localhost
:kafka_2
.13-2.6.0 gaoxinfu$ ls
-la
./bin
/
total
272
drwxr
-xr
-x@
35 gaoxinfu staff
1120 7 29 02:23 .
drwxr
-xr
-x@
12 gaoxinfu staff
384 10 21 10:05 ..
-rwxr
-xr
-x@
1 gaoxinfu staff
1423 7 29 02:16 connect
-distributed
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
1396 7 29 02:16 connect
-mirror
-maker
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
1420 7 29 02:16 connect
-standalone
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
861 7 29 02:16 kafka
-acls
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
873 7 29 02:16 kafka
-broker
-api
-versions
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
864 7 29 02:16 kafka
-configs
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
945 7 29 02:16 kafka
-console
-consumer
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
944 7 29 02:16 kafka
-console
-producer
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
871 7 29 02:16 kafka
-consumer
-groups
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
948 7 29 02:16 kafka
-consumer
-perf
-test
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
871 7 29 02:16 kafka
-delegation
-tokens
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
869 7 29 02:16 kafka
-delete
-records
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
866 7 29 02:16 kafka
-dump
-log
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
870 7 29 02:16 kafka
-leader
-election
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
863 7 29 02:16 kafka
-log
-dirs
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
862 7 29 02:16 kafka
-mirror
-maker
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
886 7 29 02:16 kafka
-preferred
-replica
-election
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
959 7 29 02:16 kafka
-producer
-perf
-test
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
874 7 29 02:16 kafka
-reassign
-partitions
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
874 7 29 02:16 kafka
-replica
-verification
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
10074 7 29 02:16 kafka
-run
-class.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
1376 7 29 02:16 kafka
-server
-start
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
1217 7 29 02:16 kafka
-server
-stop
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
945 7 29 02:16 kafka
-streams
-application
-reset
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
863 7 29 02:16 kafka
-topics
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
958 7 29 02:16 kafka
-verifiable
-consumer
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
958 7 29 02:16 kafka
-verifiable
-producer
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
1714 7 29 02:16 trogdor
.sh
drwxr
-xr
-x@
29 gaoxinfu staff
928 7 29 02:16 windows
-rwxr
-xr
-x@
1 gaoxinfu staff
867 7 29 02:16 zookeeper
-security
-migration
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
1393 7 29 02:16 zookeeper
-server
-start
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
1221 7 29 02:16 zookeeper
-server
-stop
.sh
-rwxr
-xr
-x@
1 gaoxinfu staff
1019 7 29 02:16 zookeeper
-shell
.sh
localhost
:kafka_2
.13-2.6.0 gaoxinfu$
因为上面的命令比较多,如果想要查看某个命令的具体参数,可以直接输入指定命令回车或者加上–help,如下
kafka-topics.sh命令帮助说明:kafka-topics.sh --help或者kafka-topics.sh
localhost
:kafka_2
.13-2.6.0 gaoxinfu$ pwd
/Users
/gaoxinfu
/using
/kafka_2
.13-2.6.0
localhost
:kafka_2
.13-2.6.0 gaoxinfu$ bin
/kafka
-topics
.sh
--help
This tool helps to create
, delete
, describe
, or change a topic
.
Option Description
------ -----------
--alter Alter the number of partitions
,
replica assignment
, and
/or
configuration
for the topic
.
--at
-min
-isr
-partitions
if set when describing topics
, only
show partitions whose isr count is
equal to the configured minimum
. Not
supported with the
--zookeeper
option
.
--bootstrap
-server
<String
: server to REQUIRED
: The Kafka server to connect
connect to
> to
. In
case of providing
this, a
direct Zookeeper connection won't be
required
.
--command
-config
<String
: command Property file containing configs to be
config property file
> passed to Admin Client
. This is used
only with
--bootstrap
-server option
for describing and altering broker
configs
.
--config
<String
: name
=value
> A topic configuration override
for the
topic being created or altered
.The
following is a list of valid
configurations
:
cleanup
.policy
compression
.type
delete
.retention
.ms
file
.delete
.delay
.ms
flush
.messages
flush
.ms
follower
.replication
.throttled
.
replicas
index
.interval
.bytes
leader
.replication
.throttled
.replicas
max
.compaction
.lag
.ms
max
.message
.bytes
message
.downconversion
.enable
message
.format
.version
message
.timestamp
.difference
.max
.ms
message
.timestamp
.type
min
.cleanable
.dirty
.ratio
min
.compaction
.lag
.ms
min
.insync
.replicas
preallocate
retention
.bytes
retention
.ms
segment
.bytes
segment
.index
.bytes
segment
.jitter
.ms
segment
.ms
unclean
.leader
.election
.enable
See the Kafka documentation
for full
details on the topic configs
.It is
supported only in combination with
--
create
if --bootstrap
-server option
is used
.
--create Create a
new topic.
--delete Delete a topic
--delete
-config
<String
: name
> A topic configuration override to be
removed
for an existing topic
(see
the list of configurations under the
--config option
). Not supported with
the
--bootstrap
-server option
.
--describe List details
for the given topics
.
--disable
-rack
-aware Disable rack aware replica assignment
--exclude
-internal exclude internal topics when running
list or describe command
. The
internal topics will be listed by
default
--force Suppress console prompts
--help Print usage information
.
--if-exists
if set when altering or deleting or
describing topics
, the action will
only execute
if the topic exists
.
--if-not
-exists
if set when creating topics
, the
action will only execute
if the
topic does not already exist
.
--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
). If not supplied
for create
, defaults to the cluster
default.
--replica
-assignment
<String
: 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
. If not supplied
, defaults
to the cluster
default.
--topic
<String
: topic
> The topic to create
, alter
, describe
or delete
. It also accepts a regular
expression
, except
for --create
option
. Put topic name in
double
quotes and use the '\' prefix to
escape regular expression symbols
; e
.
g
. "test\.topic".
--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
-min
-isr
-partitions
if set when describing topics
, only
show partitions whose isr count is
less than the configured minimum
.
Not supported with the
--zookeeper
option
.
--under
-replicated
-partitions
if set when describing topics
, only
show under replicated partitions
--version Display Kafka version
.
--zookeeper
<String
: hosts
> DEPRECATED
, The connection string
for
the zookeeper connection in the form
host
:port
. Multiple hosts can be
given to allow fail
-over
.
localhost
:kafka_2
.13-2.6.0 gaoxinfu$
创建topic以及zk中的变化查看
创建topic
命令
bin
/kafka
-topics
.sh
--create
--topic quickstart
-events
--bootstrap
-server localhost
:9092
命令解析
--create: 指定创建topic动作
--topic:指定新建topic的名称
--bootstrap
-server
:服务地址和端口
新开一个客户端
localhost
:kafka_2
.13-2.6.0 gaoxinfu$ pwd
/Users
/gaoxinfu
/using
/kafka_2
.13-2.6.0
localhost
:kafka_2
.13-2.6.0 gaoxinfu$ bin
/kafka
-topics
.sh
--create
--topic quickstart
-events
--bootstrap
-server localhost
:9092
Created topic quickstart
-events
.
localhost
:kafka_2
.13-2.6.0 gaoxinfu$
zk中的变化查看
客户端发布者实时生成对应topic的事件(或者称之为消息内容)
localhost
:kafka_2
.13-2.6.0 gaoxinfu$ bin
/kafka
-console
-producer
.sh
--topic quickstart
-events
--bootstrap
-server localhost
:9092
>这是我第一个事件
>这是我第二个事件
>
输入上面的命令,回车之后,会需要我们输入对应的消息内容 这里注意下,为了实时能够看到,订阅上面topic消费者可以实时接收到消息内容,我们在进行发布者生成消息之前,建议先打开消费者客户端
客户端消费者实时订阅对应topic的事件(或者称之为消息内容)
localhost
:kafka_2
.13-2.6.0 gaoxinfu$ bin
/kafka
-console
-consumer
.sh
--topic quickstart
-events
--from
-beginning
--bootstrap
-server localhost
:9092
这是我第一个事件
这是我第二个事件