Search code examples
apache-kafkaapache-zookeeperhadoop2filebeat

filebeat to kafka : Failed to connect to broker


Im new in apache environment and currently im trying to send log data from filebeat producer to kafka broker.

environment :

  1. kafka 2.11 (installed via ambari)
  2. filebeat 7.4.2 (windows)

I tried to send logs from filebeat into ambari, I've started kafka servers and created the topic named "test" and it was listed on --list. Im pretty confused about kafka broker's port. In some tutorials i saw they were using 9092 instead 2181. So now ,what port i should use to send logs from filebeat?

here is my filebeat.conf

filebeat.inputs:
    - type: log
      paths:
       - C:/Users/A/Desktop/DATA/mailbox3.csv
output.kafka:
  hosts: ["x.x.x.x:9092"]
  topic: "test"
  partition.round_robin:
    reachable_only: false
  required_acks: 1
  compression: gzip
  max_message_bytes: 1000000

result

2020-06-10T09:00:32.214+0700    INFO    kafka/log.go:53 Failed to connect to broker x.x.x.x:9092: dial tcp x.x.x.x:9092: connectex: No connection could be made because the target machine actively refused it.

2020-06-10T09:00:32.214+0700    INFO    kafka/log.go:53 client/metadata got error from broker -1 while fetching metadata: dial tcp x.x.x.x:9092: connectex: No connection could be made because the target machine actively refused it.

2020-06-10T09:00:32.215+0700    INFO    kafka/log.go:53 kafka message: client/metadata no available broker to send metadata request to
2020-06-10T09:00:32.215+0700    INFO    kafka/log.go:53 client/brokers resurrecting 1 dead seed brokers
2020-06-10T09:00:32.215+0700    INFO    kafka/log.go:53 client/metadata retrying after 250ms... (3 attempts remaining)

2020-06-10T09:00:32.466+0700    INFO    kafka/log.go:53 client/metadata fetching metadata for [test] from broker x.x.x.x:9092

2020-06-10T09:00:34.475+0700    INFO    kafka/log.go:53 Failed to connect to broker x.x.x.x:9092: dial tcp x.x.x.x:9092: connectex: No connection could be made because the target machine actively refused it.

2020-06-10T09:00:34.475+0700    INFO    kafka/log.go:53 client/metadata got error from broker -1 while fetching metadata: dial tcp x.x.x.x:9092: connectex: No connection could be made because the target machine actively refused it.

2020-06-10T09:00:34.477+0700    INFO    kafka/log.go:53 kafka message: client/metadata no available broker to send metadata request to
2020-06-10T09:00:34.477+0700    INFO    kafka/log.go:53 client/brokers resurrecting 1 dead seed brokers
2020-06-10T09:00:34.478+0700    INFO    kafka/log.go:53 client/metadata retrying after 250ms... (2 attempts remaining)

2020-06-10T09:00:34.729+0700    INFO    kafka/log.go:53 client/metadata fetching metadata for [test] from broker x.x.x.x:9092

2020-06-10T09:00:36.737+0700    INFO    kafka/log.go:53 Failed to connect to broker x.x.x.x:9092: dial tcp x.x.x.x:9092: connectex: No connection could be made because the target machine actively refused it.

2020-06-10T09:00:36.737+0700    INFO    kafka/log.go:53 client/metadata got error from broker -1 while fetching metadata: dial tcp x.x.x.x:9092: connectex: No connection could be made because the target machine actively refused it.

2020-06-10T09:00:36.738+0700    INFO    kafka/log.go:53 kafka message: client/metadata no available broker to send metadata request to
2020-06-10T09:00:36.738+0700    INFO    kafka/log.go:53 client/brokers resurrecting 1 dead seed brokers
2020-06-10T09:00:36.738+0700    INFO    kafka/log.go:53 client/metadata retrying after 250ms... (1 attempts remaining)

2020-06-10T09:00:36.989+0700    INFO    kafka/log.go:53 client/metadata fetching metadata for [test] from broker x.x.x.x:9092

2020-06-10T09:00:39.002+0700    INFO    kafka/log.go:53 Failed to connect to broker x.x.x.x:9092: dial tcp x.x.x.x:9092: connectex: No connection could be made because the target machine actively refused it.

2020-06-10T09:00:39.002+0700    INFO    kafka/log.go:53 client/metadata got error from broker -1 while fetching metadata: dial tcp x.x.x.x:9092: connectex: No connection could be made because the target machine actively refused it.

2020-06-10T09:00:39.004+0700    INFO    kafka/log.go:53 kafka message: client/metadata no available broker to send metadata request to
2020-06-10T09:00:39.004+0700    INFO    kafka/log.go:53 client/brokers resurrecting 1 dead seed brokers
2020-06-10T09:00:39.004+0700    INFO    kafka/log.go:53 client/metadata fetching metadata for [test] from broker x.x.x.x:9092

it makes me wonder if i really got 9092 port. So i check out server.properties.Some that i concern the most that:

port=6667
listeners=PLAINTEXT://x.x.x.x:6667

so then i try again to do the filebeat.conf and change port 9092 to 6667 and here is the result

2020-06-10T09:18:01.448+0700    INFO    kafka/log.go:53 client/metadata fetching metadata for [test] from broker x.x.x.x:6667

2020-06-10T09:18:01.450+0700    INFO    kafka/log.go:53 producer/broker/1001 starting up

2020-06-10T09:18:01.451+0700    INFO    kafka/log.go:53 producer/broker/1001 state change to [open] on test/0

2020-06-10T09:18:01.451+0700    INFO    kafka/log.go:53 producer/leader/test/0 selected broker 1001

2020-06-10T09:18:01.451+0700    INFO    kafka/log.go:53 Failed to connect to broker x.x.x.x:6667: dial tcp: lookup x.x.x.x: no such host

2020-06-10T09:18:01.452+0700    INFO    kafka/log.go:53 producer/broker/1001 state change to [closing] because dial tcp: lookup x.x.x.x: no such host

2020-06-10T09:18:01.453+0700    DEBUG   [kafka] kafka/client.go:264     finished kafka batch
2020-06-10T09:18:01.453+0700    DEBUG   [kafka] kafka/client.go:278     Kafka publish failed with: dial tcp: lookup x.x.x.x: no such host
2020-06-10T09:18:01.454+0700    INFO    kafka/log.go:53 producer/leader/test/0 state change to [flushing-3]

2020-06-10T09:18:01.456+0700    INFO    kafka/log.go:53 producer/leader/test/0 state change to [normal]

2020-06-10T09:18:01.456+0700    INFO    kafka/log.go:53 producer/leader/test/0 state change to [retrying-3]

2020-06-10T09:18:01.456+0700    INFO    kafka/log.go:53 producer/leader/test/0 abandoning broker 1001

2020-06-10T09:18:01.456+0700    INFO    kafka/log.go:53 producer/broker/1001 shut down

questions

What happened? Which port should be used? What is the use of each port?

Any respond will be appreciated so much. Thank you

UPDATE

according this source the right source is 6667 since kafka was installed via ambari


Solution

  • There is no restriction on the port that can be used, it only depends on the availability. In the first case, as you said, the broker could have been started on 6667 and hence no process was running on 9092.

    2020-06-10T09:18:01.451+0700 INFO kafka/log.go:53 Failed to connect to broker x.x.x.x:6667: dial tcp: lookup x.x.x.x: no such host

    Next, when you mention advertised.listeners property, you should ensure that the IP you mention in the advertised.listeners is the IP assigned to that machine. You cannot assign 1.1.1.1:9092 (just to mention some example).

    Execute ifconfig (linux), ipconfig (windows) and see the IP of your machine on the network interface that is accessible from your application machine. In linux, it will mostly be eth0

    This IP must be accessible from the machine where you are running your application. So the machine your application is running on should be able to resolve that IP. You may also want to check your network connection between your Kafka broker and the machine you are running your application on.