16

I'm trying out Kafka (0.8.2.1) in a VM, but am having trouble with it: though everything is fine while the machine remains on (even if I restart ZK/Kafka), if I reboot the machine (after gracefully shutting down ZK/Kafka) it seems all Kafka topics go lost.

I'm probably missing something basic here, since this is probably not supposed to happen. What might it be?

cd /vagrant/kafka_2.11-0.8.2.1
bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 10 --topic foo
bin/kafka-topics.sh --list --zookeeper localhost:2181
# foo
# ^C then resume ZooKeeper, Kafka, or both
bin/kafka-topics.sh --list --zookeeper localhost:2181
# foo
# ^C both, reboot machine, boot ZK/Kafka again
bin/kafka-topics.sh --list --zookeeper localhost:2181
# no topics
4
  • 1
    Where are the logs being stored? Make sure they're not in a tmp directory that could get wiped on restart. Commented Sep 7, 2015 at 11:24
  • 2
    And the ZK data dir must be checked too. The kafka-topics.sh --list command lists only zookeeper datas. I would check also the vagrant provisionning config : dir get cleared, files copy... Commented Sep 7, 2015 at 12:21
  • @ChrisGerken: Thanks, the log dir was still set to a default /tmp/kafka-logs/, so it would appear this is probably it. Changing the log directory is actually yielding me fatal errors on broker start though, so let me try and fix that to confirm moving the log directory allows it to persist through restarts... Commented Sep 7, 2015 at 12:34
  • Turns out the default /tmp/kafka-logs log dir does get cleared on boot in Ubuntu/Debian, fix in that link. If you could add your comment as an answer here I'll accept it. Commented Sep 7, 2015 at 13:18

3 Answers 3

26

Looks like the default location for logs is in the /tmp directory which gets wiped on reboot. Change that location in the config to a more permanent location.

3
  • Can you point out where to change the config for kafka and zookeeper logs directory? Commented Dec 18, 2018 at 12:20
  • @JackDaniels See the Kafka Config Doc for info on the log.dir and log.dirs properties Commented Dec 19, 2018 at 7:38
  • 2
    It is also better to change the dataDir property in zookeeper.properties file to a permanent path, so you don't get the exception kafka.common.InconsistentClusterIdException when you start your kafka server after rebooting your operating system.
    – VFX
    Commented May 26, 2022 at 13:36
7

This happens because the tmp folder get cleared out on reboot.

To fix this issue, do the following.

Go to you kafka installation directory and search for the file server.properties. You should see a section as below

A comma separated list of directories under which to store log files
log.dirs=/tmp/kafka-logs

Change the logs.dir to something more local or a custom dir like this. log.dirs=/Users/xxx/yyy/software/confluent-5.3.1/mydata

Reboot your kafka cluster for the changes to take effect. Reboot your system and you will see the Topics are still present.

5

Go to kafka installation folder > config> server.properties

search for log.dirs in that file, change path from /tmp/logs to local directory. Restart kafka server and you will see topics created will be saved in that local folder we have changed in config file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.