Kafka Single Node
| Server IP | Host Role |
|---|---|
| 192.168.10.7 | Kafka Server |
Kafka Server
-
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 package download link. Download and upload to the deployment server.https://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 package download link. Download and upload to the deployment server.https://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/ -
Modify Zookeeper configuration file
cat > /usr/local/kafka/config/zookeeper.properties <<EOFadmin.enableServer=falsedataDir=/data/kafka/zookeeper/clientPort=2181maxClientCnxns=0EOF -
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=1transaction.state.log.replication.factor=1transaction.state.log.min.isr=1log.retention.hours=168log.segment.bytes=1073741824log.retention.check.interval.ms=300000zookeeper.connect=127.0.0.1:2181zookeeper.connection.timeout.ms=6000group.initial.rebalance.delay.ms=0message.max.bytes=10485760replica.fetch.max.bytes=10485760EOF- Modify the value of
listenersto the actual local IP during deployment.
- Modify the value of
-
Create Kafka user
useradd -M -s /sbin/nologin kafka -
Grant permissions to 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 startup on boot
systemctl start zookeepersystemctl enable zookeepersystemctl start kafkasystemctl enable kafka -
Check service status
systemctl status zookeepersystemctl status kafka