Skip to content

Instantly share code, notes, and snippets.

@nashmaniac
Created October 24, 2019 11:46
Show Gist options
  • Save nashmaniac/fb440a5384c8ee6adfc64aebfdf75eeb to your computer and use it in GitHub Desktop.
Save nashmaniac/fb440a5384c8ee6adfc64aebfdf75eeb to your computer and use it in GitHub Desktop.
Update Kafka config in google deployment
#!/bin/bash
#
# Script to update Kafka configuration information
# Must be run using sudo as the Kafka config file is owned by root
#
# Use colors for notification purposes
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m'
# Location of the Kafka configuration file
CONFIG_FILE="/opt/kafka/config/server.properties"
# Obtain the Public IP of this Google instance
echo -e -n "${GREEN}Obtaining the Public IP address of this instance ... ${NC}"
MYIP=`curl -s -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip`
echo -e " ${CYAN}${MYIP}${NC}"
echo ""
echo -e "${GREEN}Updating the Kafka configuration ...${NC}"
echo " Enabling PLAINTEXT listeners"
echo -e " Updating PLAINTEXT advertised.listeners to use public IP ${CYAN}${MYIP}${NC}"
# Update the config file
sed -i.o -e "s/^#listeners=PLAINTEXT:.*$/listeners=PLAINTEXT:\/\/:9092/" \
-e "s/^#advertised.listeners=PLAINTEXT:.*$/advertised.listeners=PLAINTEXT:\/\/${MYIP}:9092/" $CONFIG_FILE
# Restart Kafka with the new configuration
echo ""
echo -e "${GREEN}Restarting the Kafka service ...${NC}"
systemctl restart kafka
sleep 5
systemctl status kafka
echo ""
echo -e "${GREEN}Done${NC}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment