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

Viewed 6679

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.

6 Answers

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.

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

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

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

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

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.

Related