26

According to official kafka documentation after command bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic server throw error "Failed to acquire lock on file .lock in tmp/kafka-logs". How to fix it?

Dima Dorogonov
  • 2,297
  • 1
  • 20
  • 23

5 Answers5

38

just delete directory /tmp/kafka-logs and try again

Fisher
  • 645
  • 6
  • 12
  • And to avoid next error do I need to change listeners (like listeners=PLAINTEXT://:9093) in config/server-1.properties ? – Dima Dorogonov May 18 '16 at 09:48
  • 1
    1. Will there be any data loss if I delete the logs directory? 2. What is the root cause of this problem? – Lana Nova Aug 08 '18 at 18:27
  • 1
    @LanaNova please refer [this](https://stackoverflow.com/questions/45599625/kafka-unable-to-start-kafka-process-can-not-access-file-00000000000000000000/53653488#comment98345918_53653488) – nambastha Apr 25 '19 at 07:36
  • Thanks, @nishantambastha. We use one zookeeper for multiple kafkas, so this solution won't work for us. – Lana Nova Apr 27 '19 at 18:35
  • I suggest a better way without delete the files: 1. netstat -anp|grep -w :9092 2. kill -9 – LIU YUE May 09 '19 at 03:02
  • I removed /tmp/kafka-logs directory. Now, it is giving an error Leader_not_available. – Krishna Kumar Singh Mar 08 '21 at 12:08
15

Remove the file .lock in /tmp/kafka-logs:

rm /tmp/kafka-logs/.lock.

That way you can keep any pre-existing logs.

7

Had the same problem. Removed the kafka log files and worked for me.

sudo rm -rf /tmp/kafka-logs
mahfuz195
  • 116
  • 1
  • 4
3

Had the same problem. First, I removed the .lock file

#rm /tmp/kafka-logs/.lock # 

and still I got below error

ERROR There was an error in one of the threads during logs loading: java.io.FileNotFoundException: /tmp/kafka-logs/__consumer_offsets-5/00000000000000000000.log (Permission denied) (kafka.log.LogManager) [2018-04-17 13:35:09,088] FATAL [Kafka Server 0], Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer) java.io.FileNotFoundException: /tmp/kafka-logs/__consumer_offsets-5/00000000000000000000.log (Permission denied) at java.io.RandomAccessFile.open0(Native Method)

so, I had to remove the folder

# rm /tmp/kafka-logs #

and it worked fine.

ata
  • 3,398
  • 5
  • 20
  • 31
HD298
  • 151
  • 2
  • 6
1

Remove kafka-logs folder

Use

cd /tmp 
rm -r kafka-logs
CodingBee
  • 1,011
  • 11
  • 8