描述主題的配置
bin/kafka-configs.sh --zookeeper localhost:2181 --describe --entity-type topics --entity-name test_topic
設(shè)置保留時(shí)間
# Deprecated way
bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic test_topic --config retention.ms=1000
# Modern way
bin/kafka-configs.sh --zookeeper localhost:2181 --alter --entity-ty
在使用kafka默認(rèn)安裝的zookeeper啟動(dòng)是的命令是
/opt/kafka/bin/zookeeper-server-start.sh /opt/kafka/config/zookeeper.properties
使用我們自己安裝的zookeeper啟動(dòng)命令是:
./zkServer.sh start
啟動(dòng)kafka
/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
創(chuàng)建主題:
/opt/kafka/bin/kafka-topic.sh --create --zookeeper localhost:2181 --replication-factor 1? --partitions 1 --topic 1707d
查看主題:
/opt/kafka/bin/kafka-topics.sh --list 1707d --zookeeper localhost:2181
服務(wù)器端:
/opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic 1707d
客戶端的命令:
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic 1707d (--from-beginning)
從第一行可以看到這個(gè)命令可以修改 topic, client, user 或 broker 的配置栖博。
如果要設(shè)置 topic,就需要設(shè)置 entity-type 為topics榕订,輸入如下命令:
> bin/kafka-configs.sh --entity-type topics
Command must include exactly one action: --describe, --alter
命令提示需要指定一個(gè)操作(不只是上面提示的兩個(gè)操作)冈止,增加--describe試試:
> bin/kafka-configs.sh --entity-type topics --describe
[root@localhost kafka_2.11-0.10.2.1]# bin/kafka-configs.sh --entity-type topics --describe
Missing required argument "[zookeeper]"
繼續(xù)增加 --zookeeper:
> bin/kafka-configs.sh --entity-type topics --describe --zookeeper localhost:2181
Configs for topic '__consumer_offsets' are segment.bytes=104857600,cleanup.policy=compact,compression.type=producer
由于沒有指定主題名锯茄,這里顯示了__consumer_offsets的信息细卧。下面指定一個(gè)topic試試鹃彻。
> bin/kafka-configs.sh --entity-type topics --describe --zookeeper localhost:2181 --entity-name test
Configs for topic 'test' are
此時(shí)顯示了test主題的信息技肩,這里是空。
因?yàn)镵afka完善的命令提示,可以很輕松的通過提示信息來進(jìn)行下一步操作虚婿,運(yùn)用熟練后旋奢,基本上很快就能實(shí)現(xiàn)自己想要的命令。
pe topics --entity-name test_topic --add-config retention.ms=1000
如果您需要?jiǎng)h除主題中的所有消息然痊,則可以利用保留時(shí)間至朗。首先將保留時(shí)間設(shè)置為非常低(1000 ms),等待幾秒鐘剧浸,然后將保留時(shí)間恢復(fù)為上一個(gè)值锹引。
注意:默認(rèn)保留時(shí)間為24小時(shí)(86400000毫秒)。
刪除主題
bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic test_topic
注意:需要在Broker的配置文件server.properties中配置 delete.topic.enable=true 才能刪除主題唆香。
主題信息
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test_topic
添加分區(qū)
bin/kafka-topics.sh --alter --zookeeper localhost:2181 --topic test_topic --partitions 3
創(chuàng)建主題
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic test_topic
列出主題
bin/kafka-topics.sh --list --zookeeper localhost:2181
關(guān)于集群方面嫌变,我總結(jié)的幾個(gè)點(diǎn)就在于,不管是我們開啟的那個(gè)服務(wù)躬它,數(shù)據(jù)都是可以聯(lián)想的腾啥,yes,完畢