nataliya
nataliya

Reputation: 111

Problem with kafka - Failed with result 'exit-code', status=1/FAILURE

I tried to install apache-kafka several times but I always had this problem. I'm using ubuntu on my virtual machine. When I'm trying to activate kafka service using sudo systemctl start kafka and then controlling if it's working at first, the output is "active (running)", but if I double-check it and the output is "failed (Result: exit-code) ". And I tried sudo systemctl enable kafka but it didn't work.

This is the output:

● kafka.service

 Loaded: loaded (/etc/systemd/system/kafka.service; enabled; vendor preset: enabled)
 Active: failed (Result: exit-code) since Wed 2021-05-26 05:40:22 PDT; 3s ago
 Process: 8098 ExecStart=/bin/sh -c /home/kafka/kafka/bin/kafka-server-start.sh /home/kafka/kafka/co>
 Main PID: 8098 (code=exited, status=1/FAILURE)

 May 26 05:40:19 ubuntu systemd[1]: Started kafka.service.
 May 26 05:40:22 ubuntu systemd[1]: kafka.service: Main process exited, code=exited, status=1/FAILURE
 May 26 05:40:22 ubuntu systemd[1]: kafka.service: Failed with result 'exit-code'. 

You can see the full output attached

enter image description here

I also tried journalctl -xe and it recommended using ./gradlew jar -PscalaVersion=2.13.5, and I download it, at first it seemed to work, but the following day I had the same problem ( kafka.service: Failed with result 'exit-code'.). And if I tried journalctl -xe I had an output that you can see attached.

enter image description here

With zookeeper I had no problem, it's always active.

Thank you in advance.

Upvotes: 11

Views: 26554

Answers (9)

Chandan Rajput
Chandan Rajput

Reputation: 441

The issue is with cluster id, if you open the server log of Kafka which is mostly located at /home/kafka/logs/server.log You will find some below kind of logs

ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
kafka.common.InconsistentClusterIdException: The Cluster ID XXXXXXXXXXXXXXXX doesn't match stored clusterId Some(XXXXXXXXXXXXXXXX) in meta.properties. The broker is trying to join the wrong cluster. Configured zookeeper. connect may be wrong.
        at kafka.server.KafkaServer.startup(KafkaServer.scala:218)
        at kafka.Kafka$.main(Kafka.scala:109)
        at kafka.Kafka.main(Kafka.scala)

So what you need to do is just delete that meta.properties from the log directory (this log directory will be as per your Kafka server.properties configuration) Then just restaet zookerpper and kafka. That's it, It will work.

Upvotes: 0

Jamil Noyda
Jamil Noyda

Reputation: 3639

In my case, I was using a Source Download which I was : kafka-3.3.1-src.tgz

use binary version Scala 2.13 - kafka_2.13-3.3.1.tgz

You can download it from https://kafka.apache.org/downloads

Upvotes: 0

Alexey Khachatryan
Alexey Khachatryan

Reputation: 187

All you need to do is to build kafka project before running it:

./gradlew jar -PscalaVersion=2.13.6

Note that you need to have Java installed.

Upvotes: 1

igaraev
igaraev

Reputation: 99

I installed kafka on a test server and got the same error. I looked in Htop to see what is loading the CPU. Stopped unnecessary processes

servise stop "SERVICENAME".

I launched kafka again and everything worked.

Upvotes: 0

Manikanta Komuravelli
Manikanta Komuravelli

Reputation: 894

In my case Kafka didn't start in the first place, I reassigned a different logs folder to server.properties files and provided necessary rights to the folder, and restarted both the zookeeper and Kafka services, and then they seem to work.

Upvotes: 0

Hello Xin Chao
Hello Xin Chao

Reputation: 1

For me, I found out that the system actually has 2 folder kafka so when the service started, it said "exit-code" -> My solution for my problem is delete 1 folder and keep folder /home/kafka

Upvotes: 0

emir
emir

Reputation: 1406

I had the same issue by following the tutorial from well known site. I fixed the problem by doing all from the scratch this way.

sudo apt update
sudo apt install default-jdk

I downloaded latest BINARY release from here https://kafka.apache.org/downloads. I used https://dlcdn.apache.org/kafka/3.0.0/kafka_2.13-3.0.0.tgz

sudo wget https://dlcdn.apache.org/kafka/3.0.0/kafka_2.13-3.0.0.tgz

Unpack and move

tar xzf kafka_2.13-3.0.0.tgz
mv kafka_2.13-3.0.0 /usr/local/kafka

edit zookeeper unit file

sudo vi /etc/systemd/system/zookeeper.service

add this content

[Unit]
Description=Apache Zookeeper server
Documentation=http://zookeeper.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties
ExecStop=/usr/local/kafka/bin/zookeeper-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target

Edit Kafka systemd unit file

sudo vi /etc/systemd/system/kafka.service

and add the content below. Note: You must change JAVA_HOME=path to your path

[Unit]
Description=Apache Kafka Server
Documentation=http://kafka.apache.org/documentation.html
Requires=zookeeper.service

[Service]
Type=simple
Environment="JAVA_HOME=REPLACE-THIS-WITH-YOUR-PATH"
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh

[Install]
WantedBy=multi-user.target

Reload the systemd daemon to apply new changes.

sudo systemctl daemon-reload

Start zookeeper and kafka

sudo systemctl start zookeeper
sudo systemctl start kafka

check kafka status now, it should be running

sudo systemctl status kafka

Upvotes: 4

Kartik_Bhatnagar
Kartik_Bhatnagar

Reputation: 230

Open the file meta.properties.

In my case, it was located at the path /home/kafka/logs/meta.properties

Just comment the the cluster.id with a #

Restart zookeeper and kafka.

Upvotes: 20

OneCricketeer
OneCricketeer

Reputation: 191681

tried to install apache-kafka several times

Kafka doesn't come with Systemd scripts. Follow the official Apache Kafka website to see how you start it without systemctl

If you want to install on Ubuntu, Confluent Community edition allows you to do apt-get install to get both Kafka and Zookeeper


Your error shows an InconsistentClusterIdException, which means you need to wipe the data directories for Zookeeper and Kafka so that the broker will start in a fresh state

Upvotes: 0

Related Questions