Skip to content

Instantly share code, notes, and snippets.

@piatra
Last active May 24, 2024 17:04
Show Gist options
  • Save piatra/0d6f7ad1435fa7aa790a to your computer and use it in GitHub Desktop.
Save piatra/0d6f7ad1435fa7aa790a to your computer and use it in GitHub Desktop.
start zookeeper and kafka in the background and create a topic
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Please supply topic name"
exit 1
fi
nohup bin/zookeeper-server-start.sh -daemon config/zookeeper.properties > /dev/null 2>&1 &
sleep 2
nohup bin/kafka-server-start.sh -daemon config/server.properties > /dev/null 2>&1 &
sleep 2
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic $1
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic parsed
@khanhafizurrahman32
Copy link

Hi, while I tried your script I got the following error:
WARN Session 0x0 for server null, unexpected error, closing socket connection and attempting to reconnect (org.apache.zookeeper.ClientCnxn)
java.net.ConnectException: Connection refused

any help on this, please?

@zenglian
Copy link

Use "-daemon" instead

#!/bin/bash
$KAFKA_HOME/bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
$KAFKA_HOME/bin/kafka-server-start.sh -daemon config/server.properties

@piatra
Copy link
Author

piatra commented Jul 9, 2019

Thanks, updated.

@douglasawh
Copy link

@khanhafizurrahman32 I know this is over two years later, but for anyone else with the issue...firewall could be blocking it

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