Reputation: 2068
I set on a ubuntu node of a cluster a kafka 0.11.0.0 instance. Until some weeks ago everything worked fine, today I'm trying to starting it and I obtain this error after the boot:
[2017-09-11 16:21:13,894] INFO [Kafka Server 0], started (kafka.server.KafkaServer)
[2017-09-11 16:21:18,998] WARN Connection to node 0 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2017-09-11 16:21:21,991] WARN Connection to node 0 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
... and so on...
My server.properties:
############################# Server Basics #############################
# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0
# Switch to enable topic deletion or not, default value is false
delete.topic.enable=true
############################# Socket Server Settings ##########################$
# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
#listeners=PLAINTEXT://9092
# Hostname and port the broker will advertise to producers and consumers. If no$
# it uses the value for "listeners" if configured. Otherwise, it will use the $
# returned from java.net.InetAddress.getCanonicalHostName().
advertised.listeners=PLAINTEXT://hidden_ip:55091
I edited advertised.listeners because there is a proxy to redirect requests to the broker. Anyway until some weeks ago everything worked fine...
My step to start kafka:
1- service zookeeper start
2- ./kafka_2.11-0.11.0.0/bin/kafka-server-start.sh ~/kafka_2.11-0.11.0.0/config/server.properties
Any advises? Thank you
Upvotes: 47
Views: 209934
Reputation: 1
If you are working on Windows and have used WSL/WSL2(Ubuntu/Linux) to deploy kafka server then try to disable ipv6
#I had to disable WSL2 ipv6 for kafka and other services running and being accesible to my local spring project
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
Upvotes: 0
Reputation: 1007
I got it working by setting the listeners property in Kafka in WSL2 to the IPv6 loopback address:
In kafka_2.13-3.5.1/config/kraft/server.properties
for KRaft-mode, or kafka_2.13-3.5.1/config/server.properties
for Zookeeper-mode, change:
listeners=PLAINTEXT://:9092,CONTROLLER://:9093
to
listeners=PLAINTEXT://[::1]:9092,CONTROLLER://:9093
and to advertise the same address to the consumers:
advertised.listeners=PLAINTEXT://localhost:9092
to
advertised.listeners=PLAINTEXT://[::1]:9092
The property default values are slightly different in the two property files. Just adapt the IP part.
I posted the KRaft server.properties
to highlight that the CONTROLLER:
-part should stay untouched.
And for the Java application, the property respectively:
kafka.bootstrap.servers=[::1]:9092
Credits to https://docs.conduktor.io/desktop/kafka-cluster-connection/setting-up-a-connection-to-kafka/connecting-to-kafka-running-on-windows-wsl-2/#two-ways-to-fix-this where I found the basics for the IPv6 solution, just had to extend it a bit for the KRaft-mode.
Upvotes: 4
Reputation: 325
I faced the same issue When I was learning kafka. In my case found that I didn't started the zookeeper and kafka server. Due to that broker may not be available error was showing. So After starting both zookeeper and kafka server the problem was resolved.
start zookeeper:
zookeeper-server-start.sh ~/kafka_2.13-3.1.0/config/zookeeper.properties
start Kafka:
kafka-server-start.sh ~/kafka_2.13-3.1.0/config/server.properties
Upvotes: 0
Reputation: 953
uncomment this line
#listeners=PLAINTEXT://:9092
changed this to
listeners=PLAINTEXT://127.0.0.1:9092
Upvotes: 59
Reputation: 1
If you are using Spring Boot, please see if the below property is set in application.properties
file, assuming a producer application only:
spring.kafka.producer.bootstrap-servers=localhost:9092
Otherwise, the following should work in general:
kafka.bootstrap.servers=localhost:9092
I didn’t have to change listeners
in the server.properties
file, as others have proposed.
Upvotes: 0
Reputation: 495
I was having same issue where everything was working fine and just stopped working one day. I backtracked my changes surrounding the Kafka initial set up and figured out below are steps that needs to be taken to fix this
Make sure that your JDK is installed correctly. I exactly had the issue because the JDK path/JAVA_HOME path I was pointing to was incorrect due to which even when the broker started it was not detected by the Client.
If then also nothing works out, then go for
#listeners=PLAINTEXT://:9092 changed this to
listeners=PLAINTEXT://127.0.0.1:9092
or
listeners=PLAINTEXT://localhost:9092
Upvotes: 1
Reputation: 800
I'm sure this is solved by now but I was getting this on a Kafka client running on an AWS ECS task trying to connect to a Kafka cluster running on EC2 instances and the problem was the security groups. Adding the CIDRS of all ECS task's allowed subnets (ECS -> cluster -> task -> details -> allowed subents) in the list of inbound rules for the cluster (ec2 -> instances -> security -> (select your security group) -> edit inbound rules -> (custom TCP/9092/CIDR) -> Add Rule) solved the issue.
Upvotes: 0
Reputation: 1
With spring-boot, kafka (image: spotify/kafka) and docker-compose combination, you might need to set below property in project:
broker-addresses: <hostname>:9092
Also, the services in docker-compose need to have environment property configured as below,
KAFKA_BOOTSTRAP_SERVERS: <hostname>:9092
Hope this might helps someone.
Upvotes: 0
Reputation: 2644
error message: "Connection to node -1 could not be established. Broker may not be available"
Solution:
I was getting this error because I was having a different version of kafka running on cluster vs local. Make sure the version is the same. I was specifying the version in pom.xml
under properties
tag
Upvotes: 0
Reputation: 469
I was also facing the same problem on WINDOWS 10 and went through all the answers in this post. What caused this problem for me and how I solved is this, On my fresh windows machine, I did a jre (jre-8u221) installation and then followed the steps mentioned in Apache Kafka documentation to start zookeeper, kafka server, send messages through producer etc. But I was getting errors related to broker not available. I then downloaded jdk (jdk-8u221 from Oracle) and installed it. Set the JAVA_HOME and Path variables and restarted the machine. Everything after worked in one go.
Upvotes: 2
Reputation: 5279
I also had the same issue...
So I start by asking Zookeeper some data
echo dump | nc localhost 2181
I get back something like this
SessionTracker dump:
Session Sets (3):
0 expire at Sun Dec 03 18:15:48 GST 2017:
0 expire at Sun Dec 03 18:15:51 GST 2017:
1 expire at Sun Dec 03 18:15:54 GST 2017:
0x1601c9a25190000
ephemeral nodes dump:
Sessions with Ephemerals (1):
0x1601c9a25190000:
/controller
/brokers/ids/0
I read this to mean that I have 1 Broker available - and it is has an id of 0.
So, lets find about that broker.
bin/zookeeper-shell.sh localhost:2181 <<< "get /brokers/ids/0"
And I see
{"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT"},"endpoints":["PLAINTEXT://192.168.1.220:9092"],"jmx_port":-1,"host":"192.168.1.220","timestamp":"1512308520781","port":9092,"version":4}
cZxid = 0x69
ctime = Sun Dec 03 17:42:00 GST 2017
mZxid = 0x69
mtime = Sun Dec 03 17:42:00 GST 2017
pZxid = 0x69
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x1601c9a25190000
dataLength = 196
numChildren = 0
This rather startled me ... PLAINTEXT://192.168.1.220:9092, so when I changed my connect string to read
bin/kafka-console-producer.sh --broker-list PLAINTEXT://192.168.1.220:9092 --topic test
It all now worked.
Good luck !!
Upvotes: 31
Reputation: 850
We faced the same situation, when we started to search the logs for the actual cause of the error.
When we were starting the Kafka cluster, it was using by default
listeners=PLAINTEXT://:9092
to connect and was not able to find the host.
We changed the line to
listeners=PLAINTEXT://<our ip address> :9092,
then
listeners=PLAINTEXT://<our ip address> :9093,
in our server-1.properties ( another broker id file ) and the same we replicated in other server.properties file and restarted our cluster.
Upvotes: 13
Reputation: 1085
i configed the kafka server.properties's listener as listeners=PLAINTEXT://**10.127.96.151**:9092
but i request the consumer as ./kafka-console-consumer.sh --bootstrap-server **localhost**:9092 --topic topic1 --from-beginning
, then it bursts the WARNs.
when i fix the consumer bootstrap-server as 10.127.96.151:9092, it runs all well with no more WARNs
Upvotes: 4
Reputation: 87
I server.propertes:
listeners=PLAINTEXT://hidden_ip:9092
when I run:bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic lt1
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic lt1
I get same error just like you get.and I try run :
bin/kafka-console-producer.sh --broker-list hidden_ip:9092 --topic lt1
it work,I get no error.
So i think you should check what's port kafka server used.This error when port is not esestablished or you connect wrong ip.
PS:I run this on same machine.
Upvotes: 1