Kafka学习4_Kafka创建、查看和删除Topic

进行Kafka相关操作和测试,创建的Topic越来越多,影响到了后续工作的正常进行,所以对已经创建的Topic进行管理


创建Topic

[hadoop@Slave1 bin]$ cd
[hadoop@Slave1 ~]$ cd /usr/local/kafka/bin
[hadoop@Slave1 bin]$ sh kafka-topics.sh --create --topic kafkatopic5 --replication-factor 1 --partitions 1 --zookeeper Slave1:2181
Created topic "kafkatopic5".
[hadoop@Slave1 bin]$ 

查看已经创建的Topic

[hadoop@Slave1 bin]$ ./kafka-topics.sh --list --zookeeper localhost:2181
flume1
flume2
flume3
flume4
flume5
flume6
flume7
kafkaTopic
kafkatopic
kafkatopic2
kafkatopic3
kafkatopic4
kafkatopic5
logStash
logStash1
logStash2
logStash3
logStash4
logStash5
logStash6
logStash7
[hadoop@Slave1 bin]$ 

删除Topic

[hadoop@Slave1 kafka]$ cd bin
[hadoop@Slave1 bin]$ ls
kafka-console-consumer.sh            kafka-run-class.sh
kafka-console-producer.sh            kafka-server-start.sh
kafka-consumer-offset-checker.sh     kafka-server-stop.sh
kafka-consumer-perf-test.sh          kafka-simple-consumer-shell.sh
kafka-mirror-maker.sh                kafka-topics.sh
kafka-preferred-replica-election.sh  windows
kafka-producer-perf-test.sh          zookeeper-server-start.sh
kafka-reassign-partitions.sh         zookeeper-server-stop.sh
kafka-replay-log-producer.sh         zookeeper-shell.sh
kafka-replica-verification.sh
[hadoop@Slave1 bin]$ ./kafka-topics.sh --delete --zookeeper Slave1:2181 --topic kafkatopic5
Topic kafkatopic5 is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.
[hadoop@Slave1 bin]$ 

用上面这种方法删除主题后,有一个提示信息,如下所示

Topic kafkatopic5 is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.
 
  

要删除的kafkatopic5被标记为删除,如果delete.topic.enble没有被标记为true,它将不会产生影响。


需要配置delete.topic.enble

[hadoop@Slave1 bin]$ cd ..
[hadoop@Slave1 kafka]$ ls
bin  config  libs  LICENSE  logs  NOTICE
[hadoop@Slave1 kafka]$ cd config/
[hadoop@Slave1 config]$ ls
consumer.properties  server.properties       zookeeper.properties
log4j.properties     test-log4j.properties
producer.properties  tools-log4j.properties
[hadoop@Slave1 config]$ vim server.properties 
[hadoop@Slave1 config]$ 
对config目录下的server.properties进行修改,在最末行加上:delete.topic.enble=true


在Slave2和Slave3上做同样修改

[hadoop@Slave1 config]$ ssh Slave2
Last login: Wed Nov 11 17:41:53 2015 from master
[hadoop@Slave2 ~]$ cd /usr/local/kafka/config/
[hadoop@Slave2 config]$ vim server.properties 
[hadoop@Slave2 config]$ exit
logout
Connection to Slave2 closed.
[hadoop@Slave1 config]$ ssh Slave3
Last login: Wed Nov 11 17:42:32 2015 from master
[hadoop@Slave3 ~]$ cd /usr/local/kafka/config/
[hadoop@Slave3 config]$ vim server.properties 
[hadoop@Slave3 config]$ exit
logout
Connection to Slave3 closed.
[hadoop@Slave1 config]$ 

进行删除,删除过后,还剩下下面两个topic

[hadoop@Slave1 bin]$ ./kafka-topics.sh --list --zookeeper localhost:2181flume1
kafkaTopic
[hadoop@Slave1 bin]$ 

查看消息文件是否删除

[hadoop@Slave1 bin]$ cd /tmp/kafka-logs/
[hadoop@Slave1 kafka-logs]$ ls
flume1-0      recovery-point-offset-checkpoint
kafkaTopic-0  replication-offset-checkpoint
[hadoop@Slave1 kafka-logs]$ 
只剩下两个剩下的主题对应的topic


查看Slave2和Slave3上的相关信息

[hadoop@Slave1 kafka-logs]$ ssh Slave2
Last login: Wed Nov 11 22:06:28 2015 from slave1
[hadoop@Slave2 ~]$ cd /tmp/kafka-logs/
[hadoop@Slave2 kafka-logs]$ ls
recovery-point-offset-checkpoint  replication-offset-checkpoint
[hadoop@Slave2 kafka-logs]$ exit
logout
Connection to Slave2 closed.
[hadoop@Slave1 kafka-logs]$ ssh Slave3
Last login: Wed Nov 11 22:07:35 2015 from slave1
[hadoop@Slave3 ~]$ cd /tmp/kafka-logs/
[hadoop@Slave3 kafka-logs]$ ls
recovery-point-offset-checkpoint  replication-offset-checkpoint
[hadoop@Slave3 kafka-logs]$ cd /usr/local/kafka/bin/
[hadoop@Slave3 bin]$ ./kafka-topics.sh --list --zookeeper localhost:2181
flume1
kafkaTopic
[hadoop@Slave3 bin]$ 


你可能感兴趣的:(Kafka,原创)