Bidirectional backwards compatibility was introduced in 2017 – which means my experience where you needed to upgrade the broker first and then the clients is no longer true. Rejoice!
Sandbox Setup
Two CentOS docker containers were provisioned as follows:
docker run -dit --name=kafka1 -p 9092:9092 centos:latest docker run -dit --name=kafka2 -p 9093:9092 -p9000:9000 centos:latest
# Shell into each container and do the following:
sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-* sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
# Get Ips and hosts into /etc/hosts
172.17.0.2 40c2222cfea0
172.17.0.3 2923addbcb6d
# Update installed packages & install required tools
dnf update yum install -y passwd vim net-tools wget git unzip
# Add a kafka user, make a kafka folder, and give the kafka user ownership of the kafka folder
useradd kafka passwd kafka usermod -aG wheel kafka mkdir /kafka chown kafka:kafka /kafka
# Install Kafka
su – kafka cd /kafka wget https://archive.apache.org/dist/kafka/2.5.0/kafka_2.12-2.5.0.tgz tar vxzf kafka_2.12-2.5.0.tgz rm kafka_2.12-2.5.0.tgz ln -s /kafka/kafka_2.12-2.5.0 /kafka/kafka
# Configure zookeeper
vi /kafka/kafka/config/zookeeper.properties dataDir=/kafka/zookeeperdata server.1=172.17.0.2:2888:3888
# Start Zookeeper on the first server
screen -S zookeeper /kafka/kafka/bin/zookeeper-server-start.sh /kafka/kafka/config/zookeeper.properties
# Configure the cluster
vi /kafka/kafka/config/server.properties broker.id=1 # unique number per cluster node listeners=PLAINTEXT://:9092 zookeeper.connect=172.17.0.2:2181
# Start Kafka
screen -S kafka /kafka/kafka/bin/kafka-server-start.sh /kafka/kafka/config/server.properties
# Edit producer.properties on a server
vi /kafka/kafka/config/producer.properties bootstrap.servers=172.17.0.2:9092,172.17.0.3:9092
# Create test topic
/kafka/kafka/bin/kafka-topics.sh --create --zookeeper 172.17.0.2:2181 --replication-factor 2 --partitions 1 --topic ljrTest
# Post messages to the topic
/kafka/kafka/bin/kafka-console-producer.sh --broker-list 172.17.0.2:9092 --producer.config /kafka/kafka/config/producer.properties --topic ljrTest
# Retrieve messages from topic
/kafka/kafka/bin/kafka-console-consumer.sh --bootstrap-server 172.17.0.2:9092 --topic ljrTest --from-beginning /kafka/kafka/bin/kafka-console-consumer.sh --bootstrap-server 172.17.0.3:9092 --topic ljrTest --from-beginning
Voila, a functional Kafka sandbox cluster.
Now we’ll install the cluster manager
cd /kafka git clone --depth 1 --branch 3.0.0.6 https://github.com/yahoo/CMAK.git cd CMAK vi conf/application.conf cmak.zkhosts="40c2222cfea0:2181" # CMAK requires java > 1.8 … so getting 11 set up cd /usr/lib/jvm wget https://cdn.azul.com/zulu/bin/zulu11.58.23-ca-jdk11.0.16.1-linux_x64.zip unzip zulu11.58.23-ca-jdk11.0.16.1-linux_x64.zip mv zulu11.58.23-ca-jdk11.0.16.1-linux_x64 zulu-11 PATH=/usr/lib/jvm/zulu-11/bin:$PATH ./sbt -java-home /usr/lib/jvm/zulu-11 clean dist cp /kafka/CMAK/target/universal/cmak-3.0.0.6.zip /kafka cd /kafka unzip cmak-3.0.0.6.zip cd cmak-3.0.0.6 screen -S CMAK bin/cmak -java-home /usr/lib/jvm/zulu-11 -Dconfig.file=/kafka/cmak-3.0.0.6/conf/application.conf -Dhttp.port=9000
Access it at http://cmak_host:9000
Sandbox Upgrade Process
# Back up the Kafka installation (excluding log files)
tar cvfzp /kafka/kafka-2.5.0.tar.gz --exclude logs /kafka/ws_npm_kafka/kafka_2.12-2.5.0
# Get newest Kafka version installed
# From another host where you can download the file, transfer it to the kafka server
scp kafka_2.12-3.2.3.tgz list@kafka1:/tmp/
# Back on the Kafka server — copy the tgz file into the Kafka directory
mv /tmp/kafka_2.12-3.2.3.tgz /kafka/kafka
# Verify Kafka data is stored outside of the install directory:
[kafka@40c2222cfea0 config]$ grep log.dir server.properties log.dirs=/tmp/kafka-logs
# Verify zookeeper data is stored outside of the install directory:
[kafka@40c2222cfea0 config]$ grep dataDir zookeeper.properties dataDir=/kafka/zookeeperdata
# Get the new version of Kafka – start with the zookeeper(s) then do the other nodes
cd /kafka wget https://downloads.apache.org/kafka/3.2.3/kafka_2.12-3.2.3.tgz tar vxfz /kafka/kafka_2.12-3.2.3.tgz
# Copy config from old iteration to new
cp /kafka/kafka_2.12-2.5.0/config/* /kafka/kafka_2.12-3.2.3/config/
# Edit server.properties and add a configuration line to force the inter-broker protocol version to the currently running Kafka version
# This ensures your cluster is using the “old” version to communicate and you can, if needed, revert to the previous version
vi /kafka/kafka/config/server.properties inter.broker.protocol.version=2.5.0
# Restart each Kafka server – waiting until it has come online before restarting the next one – with the new binaries
# Stop kafka
systemctl stop kafka
# Move symlink to new folder
unlink /kafka/kafka ln -s /kafka/kafka_2.12-3.2.3 /kafka/kafka
# start kafka
systemctl start kafka
# Or, to watch it run,
/kafka/kafka/bin/kafka-server-start.sh /kafka/kafka/config/server.properties
# Finally, ensure you’ve still got ‘stuff’
/kafka/kafka/bin/kafka-console-consumer.sh --bootstrap-server 172.17.0.3:9092 --topic ljrTest --from-beginning
# And verify the version has updated
[kafka@40c2222cfea0 bin]$ ./kafka-topics.sh --version 3.2.3 (Commit:50029d3ed8ba576f)
# Until this point, we can just roll back to the old folder & revert to the previous version of Kafka … that’s out backout plan.
# Once everything has been confirmed to be working, bump the inter-broker protocol version to the new version & restart Kafka
vi /kafka/kafka/config/server.properties inter.broker.protocol.version=3.2