Skip to content

Instantly share code, notes, and snippets.

Last active July 2, 2022 10:44
  • Star 30 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Create Kafka Multi Node, Multi Broker Cluster

How to create a MultiNode - MultiBroker Cluster for Kafka on AWS

PreRequisites :

  1. Kafka Binary files :

  2. Atleast 2 AWS machines : AWS EMR or EC2 will be preferable

  3. A Kafka Manager Utility to watch up the Cluster :


  1. Now first download the kafka Tarball or binaries on your AWS instances and extract them

    tar -xzvf kafka_2.10- mv kafka_2.10- kafka

  2. On Both the Instances, you only need two properties to be changed i.e. &

a) Going with the first one edit "" on both the instances to

vi ~/kafka/config/
clientPort=2080 #Changing the Port from default "2181" to "2080"
#add here more servers if you want

b) Now edit both instances "" and update the following this

vi ~/kafka/config/ 
port=9092<IP1> #for 2nd EC2 instance it'll be "ec2-<IP2>"
zookeeper.connect=ec2-<IP1>,ec2-<IP2> #Add all the Instances here for each Instance
  1. After this go to the /tmp of every instance and create following things :

    cd /tmp/ mkdir zookeeper #Zookeeper temp dir cd zookeeper touch myid #Zookeeper temp file echo '1' >> myid #Add Server ID for Respective Instances i.e. "server.1 and server.2 etc"

  2. Now all is done, Need to start zookeeper and kafka-server on both instances

    ##Start on both Instances

    ~/kafka/bin/ ~/kafka/config/

    ~/kafka/bin/ ~/kafka/config/

  3. Now go to KafkaTool and add both of your AWS instances, You'll see multi brokers with multple partitions in it.

Post your questions here for more help

Copy link

t6nand commented Dec 4, 2015

How to test for multiple instances of zookeeper with kafka on same machine?

Copy link

Do both instances have zookeeper and Kafka? Or does one instance of Kafka and one zookeeper. I'm trying to do one on each. How would I configure server.1 and server.2 even if zookeeper is only in one instance?

Copy link

ciasom commented Oct 3, 2016

Hi, how can you run 2 zookeepers? I got an warning when I started it: You need at least 3 servers.

Copy link

kjarrad commented Oct 4, 2016

The 'E' in EC2 is 'elastic'.
That is, AWS can add/remove nodes to the cluster to achieve horizontal scalability.
Can this Gist be expanded to include this?

Note: I'm only asking about configuration of the cluster. Until that is achieved there is no need to consider issues such as re-sharding or reassigning partition leaders.

Copy link

I have 2 different servers, I want to fetch logs in a kafka topic from 1st server and load these logs on to elastic which is running on 2nd server. ELK and kafka is running on 2nd server. what configurations are required for it ?

Copy link

Ritesh-Sharma commented Mar 22, 2017

Hi @mkanchwala , can you tell me what are these port range

what is running on these ports ?

Copy link

I am getting this error:

[2017-03-22 11:32:25,038] INFO Notification time out: 1600 (org.apache.zookeeper.server.quorum.FastLeaderElection)
[2017-03-22 11:32:31,644] WARN Cannot open channel to 2 at election address /<IP>:3888 (org.apache.zookeeper.server.quorum.QuorumCnxManager) connect timed out
	at Method)
	at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(
	at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(
	at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(

Any Idea how to fix it?

Copy link

amitk-abk commented May 9, 2017

Thanks for this write up! Its definitely helpful.
Just wanted to know if zookeeper cluster that is set up already is to be used, is there any need to alter
I think just editing with that already present zookeeper set up should be sufficient.
Hope this is the case.

Copy link

thank you for this very good post. I have couple of questions here.

  1. I installed kafka with 3 brokers by ambari.
  2. I have few and files on these 3 servers.
  3. I guess is should be --> /usr/hdp/ --> please confirm it.

For the server.propertied, I have these files on these 3 broker machines
4. /etc/kafka/conf.backup/
5. I guess is should be --> /usr/hdp/ -- please confirm it
6. finally, what is the relationship between these zookeepers on broker server and zookeeper on the maters servers? kafka zookeeper seemed have its won dormitory, these zookeeper still work with other zookeepers in the cluster?

your post is very detailed, learned so much from it.
thank you for your help.

Copy link

I have figured out the file I need to modify, however, when I start, I got an error:
Invalid config, exiting abnormally (org.apache.zookeeper.server.quorum.QuorumPeerMain)
any ideas? please help.

Copy link

hi, at your step #5, you said "Now go to KafkaTool and add both of your AWS instances, You'll see multi brokers with multple partitions in it."
I had a different approach, I have installed kafka with 3 brokers on which zookeepers already installed, then I came back to following your steps to configure, you think this would make difference? this would cause my errors I have here? Invalid config, exiting abnormally (org.apache.zookeeper.server.quorum.QuorumPeerMain)

please respond.
thank you so much for your help.

Copy link

please discard all my questions, I fixed it.

Copy link

Trying to configure multinode instance using the steps mentioned however i am getting below error :
"Invalid config, exiting abnormally"

ubuntu@kafka2:~/kafka/kafka_2.11-1.0.0$ bin/ config/
[2018-01-04 11:50:07,623] INFO Reading configuration from: config/ (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
[2018-01-04 11:50:07,647] INFO Resolved hostname: x.x.x.189 to address: /x.x.x.189 (org.apache.zookeeper.server.quorum.QuorumPeer)
[2018-01-04 11:50:07,647] INFO Resolved hostname: x.x.x.231 to address: /x.x.x.231 (org.apache.zookeeper.server.quorum.QuorumPeer)
[2018-01-04 11:50:07,647] WARN No server failure will be tolerated. You need at least 3 servers. (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
[2018-01-04 11:50:07,648] ERROR Invalid config, exiting abnormally (org.apache.zookeeper.server.quorum.QuorumPeerMain)
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing config/
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(
Caused by: java.lang.IllegalArgumentException: initLimit is not set
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(
... 2 more
Invalid config, exiting abnormally

Here is my file:
i also created myid file inside the datadir and gave the server id (231 and 189 respectively in both the servers)

Copy link

@Tiyadong How did you fix it? i am getting the exact same error.

Copy link

sdarwin commented Apr 4, 2018

Notice the message: "You need at least 3 servers." An odd number of zookeeper servers is recommended.

Copy link

DivsDibs commented May 4, 2018

@avinash-mishra I fixed it with having correct Inbound rule specified in Security Group attached to the EC2, while accessing internally and not over internet.

Copy link

Why do you need to specify '2888:3888' in for server.1 and server.2 ?

Copy link

sarat532 commented Jul 2, 2022

Hi @avinash-mishra I'm also getting the same error.

[2022-07-02 10:27:51,573] WARN Cannot open channel to 2 at election address ip-172-31-39-106.ap-south-1.compute.internal/ (org.apache.zookeeper.server.quorum.QuorumCnxManager) Connection refused (Connection refused) at java.base/ Method) at java.base/ at java.base/ at java.base/ at java.base/ at java.base/ at org.apache.zookeeper.server.quorum.QuorumCnxManager.initiateConnection( at org.apache.zookeeper.server.quorum.QuorumCnxManager$ at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker( at java.base/java.util.concurrent.ThreadPoolExecutor$ at java.base/
Please let me know how you resolved this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment