Kafka Cluster
| Server IP | Host Role |
|---|---|
| 192.168.10.7 | Kafka Node01 |
| 192.168.10.8 | Kafka Node02 |
| 192.168.10.9 | Kafka Node03 |
Kafka Node01
-
Download JDK installation package
- Server with Internet Access
- Server without Internet Access
wget https://pdpublic.mingdao.com/private-deployment/offline/common/OpenJDK21U-jdk_x64_linux_hotspot_21.0.8_9.tar.gz# JDK installation package download link, upload to the deployment server after downloadinghttps://pdpublic.mingdao.com/private-deployment/offline/common/OpenJDK21U-jdk_x64_linux_hotspot_21.0.8_9.tar.gz -
Extract the JDK to the installation directory
tar -zxvf OpenJDK21U-jdk_x64_linux_hotspot_21.0.8_9.tar.gzmv jdk-21.0.8+9 /usr/local/openjdk-21 -
Configure Java symbolic link
ln -s /usr/local/openjdk-21/bin/java /bin/java -
Download Kafka installation package
- Server with Internet Access
- Server without Internet Access
wget https://pdpublic.mingdao.com/private-deployment/offline/common/kafka_2.13-3.9.1.tgz# Kafka installation package download link, upload to the deployment server after downloadinghttps://pdpublic.mingdao.com/private-deployment/offline/common/kafka_2.13-3.9.1.tgz -
Extract Kafka to the installation directory
tar -zxvf kafka_2.13-3.9.1.tgz -C /usr/localmv /usr/local/kafka_2.13-3.9.1/ /usr/local/kafka/ -
Create data directories
mkdir -p /data/kafka/zookeeper/ /data/kafka/kafka-logs/ -
Add Zookeeper myid
echo 1 > /data/kafka/zookeeper/myid- Note: Each node has a different myid
-
Modify Zookeeper configuration file
cat > /usr/local/kafka/config/zookeeper.properties <<EOFadmin.enableServer=falsedataDir=/data/kafka/zookeeper/clientPort=2181maxClientCnxns=0initLimit=10syncLimit=5server.1=192.168.10.7:2888:3888server.2=192.168.10.8:2888:3888server.3=192.168.10.9:2888:3888EOF- server.1 corresponds to the server with myid content of 1
- server.2 corresponds to the server with myid content of 2
- server.3 corresponds to the server with myid content of 3
-
Modify Kafka memory limit to 4g
sed -i ':a;N;$!ba;s/Xm[xs]1G/Xmx4G/1' /usr/local/kafka/bin/kafka-server-start.shsed -i ':a;N;$!ba;s/Xm[xs]1G/Xms4G/1' /usr/local/kafka/bin/kafka-server-start.sh -
Modify Kafka configuration file
cat > /usr/local/kafka/config/server.properties <<'EOF'broker.id=0listeners=PLAINTEXT://0.0.0.0:9092advertised.listeners=PLAINTEXT://192.168.10.7:9092num.network.threads=3num.io.threads=8socket.send.buffer.bytes=102400socket.receive.buffer.bytes=102400socket.request.max.bytes=104857600log.dirs=/data/kafka/kafka-logs/num.partitions=10num.recovery.threads.per.data.dir=1offsets.topic.replication.factor=3transaction.state.log.replication.factor=3transaction.state.log.min.isr=2log.retention.hours=168log.segment.bytes=1073741824log.retention.check.interval.ms=300000zookeeper.connect=192.168.10.7:2181,192.168.10.8:2181,192.168.10.9:2181zookeeper.connection.timeout.ms=6000group.initial.rebalance.delay.ms=0default.replication.factor=3acks=allmin.insync.replicas=2message.max.bytes=10485760replica.fetch.max.bytes=10485760EOF- Note: broker.id value is different for each node
- Modify the listeners value to the actual local IP during deployment
- Modify the zookeeper.connect value to the actual IPs of the three Zookeeper nodes during deployment
-
Create Kafka user
useradd -M -s /sbin/nologin kafka -
Set permissions for Kafka related directories
chown -R kafka:kafka /usr/local/kafka /data/kafka -
Configure systemd to manage Zookeeper
cat > /etc/systemd/system/zookeeper.service <<'EOF'[Unit]Description=Zookeeper[Service]User=kafkaGroup=kafkaLimitNOFILE=102400LimitNPROC=102400ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.propertiesExecStop=/usr/bin/kill $MAINPIDRestart=on-failure[Install]WantedBy=multi-user.targetEOF -
Configure systemd to manage Kafka
cat > /etc/systemd/system/kafka.service <<'EOF'[Unit]Description=KafkaAfter=zookeeper.serviceRequires=zookeeper.service[Service]User=kafkaGroup=kafkaLimitNOFILE=102400LimitNPROC=102400ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.propertiesExecStop=/usr/bin/kill $MAINPIDRestart=on-failure[Install]WantedBy=multi-user.targetEOF -
Start Zookeeper and Kafka and enable autostart on boot
systemctl start zookeepersystemctl enable zookeepersystemctl start kafkasystemctl enable kafka -
Check service status
systemctl status zookeepersystemctl status kafka
Kafka Node02
-
Download JDK installation package
- Server with Internet Access
- Server without Internet Access
wget https://pdpublic.mingdao.com/private-deployment/offline/common/OpenJDK21U-jdk_x64_linux_hotspot_21.0.8_9.tar.gz# JDK installation package download link, upload to the deployment server after downloadinghttps://pdpublic.mingdao.com/private-deployment/offline/common/OpenJDK21U-jdk_x64_linux_hotspot_21.0.8_9.tar.gz -
Extract the JDK to the installation directory
tar -zxvf OpenJDK21U-jdk_x64_linux_hotspot_21.0.8_9.tar.gzmv jdk-21.0.8+9 /usr/local/openjdk-21 -
Configure Java symbolic link
ln -s /usr/local/openjdk-21/bin/java /bin/java -
Download Kafka installation package
- Server with Internet Access
- Server without Internet Access
wget https://pdpublic.mingdao.com/private-deployment/offline/common/kafka_2.13-3.9.1.tgz# Kafka installation package download link, upload to the deployment server after downloadinghttps://pdpublic.mingdao.com/private-deployment/offline/common/kafka_2.13-3.9.1.tgz -
Extract Kafka to the installation directory
tar -zxvf kafka_2.13-3.9.1.tgz -C /usr/localmv /usr/local/kafka_2.13-3.9.1/ /usr/local/kafka/ -
Create data directories
mkdir -p /data/kafka/zookeeper/ /data/kafka/kafka-logs/ -
Add Zookeeper myid
echo 2 > /data/kafka/zookeeper/myid- Note: Each node has a different myid
-
Modify Zookeeper configuration file
cat > /usr/local/kafka/config/zookeeper.properties <<EOFadmin.enableServer=falsedataDir=/data/kafka/zookeeper/clientPort=2181maxClientCnxns=0initLimit=10syncLimit=5server.1=192.168.10.7:2888:3888server.2=192.168.10.8:2888:3888server.3=192.168.10.9:2888:3888EOF- server.1 corresponds to the server with myid content of 1
- server.2 corresponds to the server with myid content of 2
- server.3 corresponds to the server with myid content of 3
-
Modify Kafka memory limit to 4g
sed -i ':a;N;$!ba;s/Xm[xs]1G/Xmx4G/1' /usr/local/kafka/bin/kafka-server-start.shsed -i ':a;N;$!ba;s/Xm[xs]1G/Xms4G/1' /usr/local/kafka/bin/kafka-server-start.sh -
Modify Kafka configuration file
cat > /usr/local/kafka/config/server.properties <<'EOF'broker.id=1listeners=PLAINTEXT://0.0.0.0:9092advertised.listeners=PLAINTEXT://192.168.10.8:9092num.network.threads=3num.io.threads=8socket.send.buffer.bytes=102400socket.receive.buffer.bytes=102400socket.request.max.bytes=104857600log.dirs=/data/kafka/kafka-logs/num.partitions=10num.recovery.threads.per.data.dir=1offsets.topic.replication.factor=3transaction.state.log.replication.factor=3transaction.state.log.min.isr=2log.retention.hours=168log.segment.bytes=1073741824log.retention.check.interval.ms=300000zookeeper.connect=192.168.10.7:2181,192.168.10.8:2181,192.168.10.9:2181zookeeper.connection.timeout.ms=6000group.initial.rebalance.delay.ms=0default.replication.factor=3acks=allmin.insync.replicas=2message.max.bytes=10485760replica.fetch.max.bytes=10485760EOF- Note: broker.id value is different for each node
- Modify the listeners value to the actual local IP during deployment
- Modify the zookeeper.connect value to the actual IPs of the three Zookeeper nodes during deployment
-
Create Kafka user
useradd -M -s /sbin/nologin kafka -
Set permissions for Kafka related directories
chown -R kafka:kafka /usr/local/kafka /data/kafka -
Configure systemd to manage Zookeeper
cat > /etc/systemd/system/zookeeper.service <<'EOF'[Unit]Description=Zookeeper[Service]User=kafkaGroup=kafkaLimitNOFILE=102400LimitNPROC=102400ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.propertiesExecStop=/usr/bin/kill $MAINPIDRestart=on-failure[Install]WantedBy=multi-user.targetEOF -
Configure systemd to manage Kafka
cat > /etc/systemd/system/kafka.service <<'EOF'[Unit]Description=KafkaAfter=zookeeper.serviceRequires=zookeeper.service[Service]User=kafkaGroup=kafkaLimitNOFILE=102400LimitNPROC=102400ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.propertiesExecStop=/usr/bin/kill $MAINPIDRestart=on-failure[Install]WantedBy=multi-user.targetEOF -
Start Zookeeper and Kafka and enable autostart on boot
systemctl start zookeepersystemctl enable zookeepersystemctl start kafkasystemctl enable kafka -
Check service status
systemctl status zookeepersystemctl status kafka
Kafka Node03
-
Download JDK installation package
- Server with Internet Access
- Server without Internet Access
wget https://pdpublic.mingdao.com/private-deployment/offline/common/OpenJDK21U-jdk_x64_linux_hotspot_21.0.8_9.tar.gz# JDK installation package download link, upload to the deployment server after downloadinghttps://pdpublic.mingdao.com/private-deployment/offline/common/OpenJDK21U-jdk_x64_linux_hotspot_21.0.8_9.tar.gz -
Extract the JDK to the installation directory
tar -zxvf OpenJDK21U-jdk_x64_linux_hotspot_21.0.8_9.tar.gzmv jdk-21.0.8+9 /usr/local/openjdk-21 -
Configure Java symbolic link
ln -s /usr/local/openjdk-21/bin/java /bin/java -
Download Kafka installation package
- Server with Internet Access
- Server without Internet Access
wget https://pdpublic.mingdao.com/private-deployment/offline/common/kafka_2.13-3.9.1.tgz# Kafka installation package download link, upload to the deployment server after downloadinghttps://pdpublic.mingdao.com/private-deployment/offline/common/kafka_2.13-3.9.1.tgz -
Extract Kafka to the installation directory
tar -zxvf kafka_2.13-3.9.1.tgz -C /usr/localmv /usr/local/kafka_2.13-3.9.1/ /usr/local/kafka/ -
Create data directories
mkdir -p /data/kafka/zookeeper/ /data/kafka/kafka-logs/ -
Add Zookeeper myid
echo 3 > /data/kafka/zookeeper/myid- Note: Each node has a different myid
-
Modify Zookeeper configuration file
cat > /usr/local/kafka/config/zookeeper.properties <<EOFadmin.enableServer=falsedataDir=/data/kafka/zookeeper/clientPort=2181maxClientCnxns=0initLimit=10syncLimit=5server.1=192.168.10.7:2888:3888server.2=192.168.10.8:2888:3888server.3=192.168.10.9:2888:3888EOF- server.1 corresponds to the server with myid content of 1
- server.2 corresponds to the server with myid content of 2
- server.3 corresponds to the server with myid content of 3
-
Modify Kafka memory limit to 4g
sed -i ':a;N;$!ba;s/Xm[xs]1G/Xmx4G/1' /usr/local/kafka/bin/kafka-server-start.shsed -i ':a;N;$!ba;s/Xm[xs]1G/Xms4G/1' /usr/local/kafka/bin/kafka-server-start.sh -
Modify Kafka configuration file
cat > /usr/local/kafka/config/server.properties <<'EOF'broker.id=2listeners=PLAINTEXT://0.0.0.0:9092advertised.listeners=PLAINTEXT://192.168.10.9:9092num.network.threads=3num.io.threads=8socket.send.buffer.bytes=102400socket.receive.buffer.bytes=102400socket.request.max.bytes=104857600log.dirs=/data/kafka/kafka-logs/num.partitions=10num.recovery.threads.per.data.dir=1offsets.topic.replication.factor=3transaction.state.log.replication.factor=3transaction.state.log.min.isr=2log.retention.hours=168log.segment.bytes=1073741824log.retention.check.interval.ms=300000zookeeper.connect=192.168.10.7:2181,192.168.10.8:2181,192.168.10.9:2181zookeeper.connection.timeout.ms=6000group.initial.rebalance.delay.ms=0default.replication.factor=3acks=allmin.insync.replicas=2message.max.bytes=10485760replica.fetch.max.bytes=10485760EOF- Note: broker.id value is different for each node
- Modify the listeners value to the actual local IP during deployment
- Modify the zookeeper.connect value to the actual IPs of the three Zookeeper nodes during deployment
-
Create Kafka user
useradd -M -s /sbin/nologin kafka -
Set permissions for Kafka related directories
chown -R kafka:kafka /usr/local/kafka /data/kafka -
Configure systemd to manage Zookeeper
cat > /etc/systemd/system/zookeeper.service <<'EOF'[Unit]Description=Zookeeper[Service]User=kafkaGroup=kafkaLimitNOFILE=102400LimitNPROC=102400ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.propertiesExecStop=/usr/bin/kill $MAINPIDRestart=on-failure[Install]WantedBy=multi-user.targetEOF -
Configure systemd to manage Kafka
cat > /etc/systemd/system/kafka.service <<'EOF'[Unit]Description=KafkaAfter=zookeeper.serviceRequires=zookeeper.service[Service]User=kafkaGroup=kafkaLimitNOFILE=102400LimitNPROC=102400ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.propertiesExecStop=/usr/bin/kill $MAINPIDRestart=on-failure[Install]WantedBy=multi-user.targetEOF -
Start Zookeeper and Kafka and enable autostart on boot
systemctl start zookeepersystemctl enable zookeepersystemctl start kafkasystemctl enable kafka -
Check service status
systemctl status zookeepersystemctl status kafka
Kafka Cluster Verification
-
Start producer on Kafka Node01
/usr/local/kafka/bin/kafka-console-producer.sh --bootstrap-server 127.0.0.1:9092 --topic test01- After starting, enter message content randomly in the terminal
-
Check messages on Kafka Node02/3
/usr/local/kafka/bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --from-beginning --topic test01/usr/local/kafka/bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --from-beginning --topic test01- If the output includes message content from the producer, everything is functioning correctly.