先创建一个topic：

```bash
./bin/kafka-topics.sh --create --topic demo --zookeeper localhost:2181 --partitions 2 --replication-factor 1
```

查看topic:

```bash
./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic demo
Topic:demo      PartitionCount:2        ReplicationFactor:1     Configs:
Topic: demo     Partition: 0    Leader: 0       Replicas: 0     Isr: 0
Topic: demo     Partition: 1    Leader: 0       Replicas: 0     Isr: 0
```

修改topic：

能增加分区，但不能减少分区，如：

```bash
 ./bin/kafka-topics.sh --alter --zookeeper localhost:2181 --topic demo --partitions 5
WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected
Adding partitions succeeded!

./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic demo
Topic:demo      PartitionCount:5        ReplicationFactor:1     Configs:
Topic: demo     Partition: 0    Leader: 0       Replicas: 0     Isr: 0
Topic: demo     Partition: 1    Leader: 0       Replicas: 0     Isr: 0
Topic: demo     Partition: 2    Leader: 0       Replicas: 0     Isr: 0
Topic: demo     Partition: 3    Leader: 0       Replicas: 0     Isr: 0
Topic: demo     Partition: 4    Leader: 0       Replicas: 0     Isr: 0
```



删除topic:

```bash
kafka-topics --delete --zookeeper server1:2181,server2:2181 --topic demo
```

流程图：

![image-20190419130656949](http://limbo.oss-cn-beijing.aliyuncs.com/2019-04-19-050657.png)

