kafka 的topic 创建和删除试验

zookeeper和kafka 的安装,参考:

http://www.cnblogs.com/caoguo/p/5958608.html

参考上述URL后,在个人的伪分布式环境下,安装了kafka

确认 zookeeper 为运行状态:

$ service zookeeper-server status
zookeeper-server is running

启动kafka:
[training@localhost ~]$ /etc/init.d/kafka start
Starting Kafka:/sbin/runuser: cannot set groups: Operation not permitted
done.

创建topic:
# ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test333
Created topic "test333".

确认topic:
[root@localhost bin]# ./kafka-topics.sh --list --zookeeper localhost:2181
test333

删除topic:
# ./kafka-topics.sh --delete --zookeeper localhost:2181 --topic test333
Topic test333 is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.

再度确认topic:
# ./kafka-topics.sh --list --zookeeper localhost:2181
test333 - marked for deletion

由于kafka 的配置文件中,没有设置 delete.topic.enable =true。
此topic 标记为 "marked for deletion"。

设置 delete.topic.enable =true后,仍然没有得到删除。

进行永久删除:

执行 rmr /brokers/topics/test333:

# zookeeper-client
Connecting to localhost:2181
2017-10-15 17:40:54,251 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.5-cdh5.7.0--1, built on 03/23/2016 18:30 GMT
2017-10-15 17:40:54,311 [myid:] - INFO [main:Environment@100] - Client environment:host.name=localhost
2017-10-15 17:40:54,312 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_60
2017-10-15 17:40:54,359 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2017-10-15 17:40:54,360 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/java/jdk1.8.0_60/jre
2017-10-15 17:40:54,360 [myid:] - INFO [main:Environment@100] - Client 
environment:java.class.path=/usr/lib/zookeeper/bin/../build/classes:/usr/lib/zookeeper/bin/../build/lib/*.jar:/usr/lib/zookeeper/bin/../lib/slf4j-log4j12.jar:/usr/lib/zookeeper/bin/../lib/slf4j-log4j12-1.7.5.jar:/usr/lib/zookeeper/bin/../lib/slf4j-api-1.7.5.jar:/usr/lib/zookeeper/bin/../lib/netty-3.2.2.Final.jar:/usr/lib/zookeeper/bin/../lib/log4j-1.2.16.jar:/usr/lib/zookeeper/bin/../lib/jline-2.11.jar:/usr/lib/zookeeper/bin/../zookeeper-3.4.5-cdh5.7.0.jar:/usr/lib/zookeeper/bin/../src/java/lib/*.jar:/etc/zookeeper/conf::/etc/zookeeper/conf:/usr/lib/zookeeper/zookeeper.jar:/usr/lib/zookeeper/zookeeper-3.4.5-cdh5.7.0.jar:/usr/lib/zookeeper/lib/slf4j-log4j12.jar:/usr/lib/zookeeper/lib/log4j-1.2.16.jar:/usr/lib/zookeeper/lib/slf4j-log4j12-1.7.5.jar:/usr/lib/zookeeper/lib/slf4j-api-1.7.5.jar:/usr/lib/zookeeper/lib/jline-2.11.jar:/usr/lib/zookeeper/lib/netty-3.2.2.Final.jar
2017-10-15 17:40:54,365 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2017-10-15 17:40:54,365 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2017-10-15 17:40:54,373 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2017-10-15 17:40:54,374 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2017-10-15 17:40:54,374 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2017-10-15 17:40:54,376 [myid:] - INFO [main:Environment@100] - Client environment:os.version=2.6.32-504.30.3.el6.x86_64
2017-10-15 17:40:54,376 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root
2017-10-15 17:40:54,394 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root
2017-10-15 17:40:54,395 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/usr/local/kafka_2.11-0.10.0.1/bin
2017-10-15 17:40:54,431 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@1a86f2f1
Welcome to ZooKeeper!
2017-10-15 17:40:54,709 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@975] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2017-10-15 17:40:55,962 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@852] - Socket connection established, initiating session, client: /127.0.0.1:54572, server: localhost/127.0.0.1:2181
2017-10-15 17:40:56,140 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x15f1e700b330016, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] ls /admin/delete_topics
[test333]
[zk: localhost:2181(CONNECTED) 1] ls /brokers/topics

[zk: localhost:2181(CONNECTED) 3] rmr /brokers/topics/test333
[zk: localhost:2181(CONNECTED) 4] 
[zk: localhost:2181(CONNECTED) 4] ls /brokers/topics
[]
[zk: localhost:2181(CONNECTED) 5] quit
Quitting...
2017-10-15 17:56:07,144 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@512] - EventThread shut down
2017-10-15 17:56:07,146 [myid:] - INFO [main:ZooKeeper@684] - Session: 0x15f1e700b330016 closed
#