1. 停止kafka集群

root@bluejay-PC:/# /usr/local/kafka/kafka01/bin/kafka-server-stop.sh
root@bluejay-PC:/# /usr/local/kafka/kafka02/bin/kafka-server-stop.sh
root@bluejay-PC:/# /usr/local/kafka/kafka03/bin/kafka-server-stop.sh

2. 删除kafka集群中每个服务的logs

root@bluejay-PC:/usr/local/kafka/kafka01/logs# rm -rf *
root@bluejay-PC:/usr/local/kafka/kafka02/logs# rm -rf *
root@bluejay-PC:/usr/local/kafka/kafka03/logs# rm -rf *

3.停止zookeeper集群的每个服务

root@bluejay-PC:/# /usr/local/zookeeper/zookeeper01/bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper01/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
root@bluejay-PC:/# /usr/local/zookeeper/zookeeper02/bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper02/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
root@bluejay-PC:/# /usr/local/zookeeper/zookeeper03/bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper03/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
root@bluejay-PC:/#

4. 删除zookeeper中的data 中除myid的所有内容,和dataLog中所有内容

root@bluejay-PC:/# cd /usr/local/zookeeper/zookeeper01/data
root@bluejay-PC:/usr/local/zookeeper/zookeeper01/data# ls
myid  version-2
root@bluejay-PC:/usr/local/zookeeper/zookeeper01/data# rm -rf version-2/

root@bluejay-PC:/usr/local/zookeeper/zookeeper01/data#
root@bluejay-PC:/usr/local/zookeeper/zookeeper01/data# ls
myid
root@bluejay-PC:/usr/local/zookeeper/zookeeper01/data# cd /usr/local/zookeeper/zookeeper02/data
root@bluejay-PC:/usr/local/zookeeper/zookeeper02/data# rm -rf version-2/
root@bluejay-PC:/usr/local/zookeeper/zookeeper02/data# ls
myid
root@bluejay-PC:/usr/local/zookeeper/zookeeper02/data# cd /usr/local/zookeeper/zookeeper03/data
root@bluejay-PC:/usr/local/zookeeper/zookeeper03/data# rm -rf version-2/
root@bluejay-PC:/usr/local/zookeeper/zookeeper03/data# ls
myid
root@bluejay-PC:/usr/local/zookeeper/zookeeper03/data#

5. 重启zookeeper集群
 

root@bluejay-PC:/# /usr/local/zookeeper/zookeeper01/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper01/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
root@bluejay-PC:/# /usr/local/zookeeper/zookeeper02/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper02/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
root@bluejay-PC:/# /usr/local/zookeeper/zookeeper03/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper03/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

6.  重新配置每个kafka的配置文件

将log.dirs 配置到data目录

log.dirs=/usr/local/kafka/kafka03/data

7. 创建topic后查看 kafka 中的logs 和 data目录

/usr/local/kafka/kafka03/bin/kafka-topics.sh  --create --zookeeper 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183  --replication-factor 1  --partitions 1 --topic first
root@bluejay-PC:/usr/local/kafka/kafka03/logs# ls -l
总用量 164
-rw-r--r-- 1 root staff   307 4月   4 15:05 controller.log
-rw-r--r-- 1 root staff     0 4月   4 15:05 kafka-authorizer.log
-rw-r--r-- 1 root staff     0 4月   4 15:05 kafka-request.log
-rw-r--r-- 1 root staff  9955 4月   4 15:05 kafkaServer-gc.log.0.current
-rw-r--r-- 1 root staff 67722 4月   4 15:07 kafkaServer.out
-rw-r--r-- 1 root staff   172 4月   4 15:05 log-cleaner.log
-rw-r--r-- 1 root staff 67722 4月   4 15:07 server.log
-rw-r--r-- 1 root staff  5675 4月   4 15:07 state-change.log
root@bluejay-PC:/usr/local/kafka/kafka03/logs# ls -l ../data
总用量 88
-rw-r--r-- 1 root staff    0 4月   4 15:05 cleaner-offset-checkpoint
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-0
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-12
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-15
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-18
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-21
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-24
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-27
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-3
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-30
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-33
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-36
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-39
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-42
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-45
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-48
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-6
drwxr-sr-x 2 root staff 4096 4月   4 15:07 __consumer_offsets-9
drwxr-sr-x 2 root staff 4096 4月   4 15:07 first-0
-rw-r--r-- 1 root staff    4 4月   4 15:09 log-start-offset-checkpoint
-rw-r--r-- 1 root staff   88 4月   4 15:05 meta.properties
04-16 03:30