# 创建新的Topic logstash_test(拥有3个副本)
$ kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic logstash_test
# 查看Topic logstash_test的状态,发现Leader是1(broker.id=1),有三个备份分别是0,1,2
$ kafka-topics.sh --describe --zookeeper localhost:2181 --topic logstash_test
Topic: logstash_test PartitionCount:1 ReplicationFactor:3 Configs:
Topic: logstash_test Partition: 0 Leader: 1 Replicas: 1,0,2 Isr: 1,0,2
# 查看Zookeeper上的Topic
$ zkCli.sh -server localhost:2181
[zk: localhost:2181(CONNECTED) 2] ls /brokers/topics
[logstash_test]
[zk: localhost:2181(CONNECTED) 3] ls /config/topics
[logstash_test, streams-file-input, test1, __consumer_offsets, connect-test, my-replicated-topic, kafka_test, kafka_cluster_topic]
# 查看Kafka的server.properties配置文件中log.dirs=/tmp/kafka-logs的目录
$ ll /tmp/kafka-logs/logstash_test-0
total 37812
drwxrwxr-x 2 yunyu yunyu 4096 Nov 21 22:38 ./
drwxrwxr-x 57 yunyu yunyu 4096 Nov 22 10:58 ../
-rw-rw-r-- 1 yunyu yunyu 10485760 Nov 21 22:41 00000000000000000000.index
-rw-rw-r-- 1 yunyu yunyu 38681667 Nov 21 22:42 00000000000000000000.log
# 删除Topic logstash_test的log文件(这里Kafka集群的所有节点都要删除)
$ rm -rf /tmp/kafka-logs/logstash_test*
# 删除Zookeeper上的Topic
$ zkCli.sh -server localhost:2181
[zk: localhost:2181(CONNECTED) 2] rmr /brokers/topics/logstash_test
[]
[zk: localhost:2181(CONNECTED) 3] rmr /config/topics/logstash_test
# 再次查看Topic logstash_test的状态,已经没有内容输出,说明Topic已经被删除了
$ kafka-topics.sh --describe --zookeeper localhost:2181 --topic logstash_test
# 貌似这种方式也能达到方式一同样的效果,但是偶然发现该方式删除之后创建同名的Topic会有问题
# 再次创建Topic logstash_test
$ kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic logstash_test
# 查看Topic logstash_test的状态,发现Leader是none,isr为空
$ kafka-topics.sh --describe --zookeeper localhost:2181 --topic logstash_test
Topic:logstash_test PartitionCount:1 ReplicationFactor:3 Configs:
Topic: logstash_test Partition: 0 Leader: none Replicas: 1,2,0 Isr: