Kafka单机集群安装
下载地址
https://kafka.apache.org/downloads
解压到指定目录
tar -zxf /mnt/d/software/kafka_2.12-3.9.0.tgz -C /mnt/d/apps
mv /mnt/d/apps/kafka_2.12-3.9.0 /mnt/d/apps/kafka
自动添加相关配置信息及启动脚本
假定当前机器的IP地址:172.29.2.194
KAFKA_HOME=/mnt/d/apps/kafka
for i in {1..3}; do
mkdir -p $KAFKA_HOME/server$i/logs
mkdir -p $KAFKA_HOME/server$i/conf
touch $KAFKA_HOME/server$i/conf/server.properties
cat > $KAFKA_HOME/server$i/conf/server.properties <<EOF
broker.id=$i
delete.topic.enable=true
auto.create.topics.enable=false
unclean.leader.election.enable=false
listeners=PLAINTEXT://:909$i
advertised.listeners=PLAINTEXT://172.29.2.194:909$i
log.dirs=$KAFKA_HOME/server$i/logs
zookeeper.connect=localhost:218$i,localhost:218$i,localhost:218$i/kafka
replica.fetch.max.bytes=20971520
offsets.retention.minutes=10080
EOF
done
cat > /mnt/d/apps/kafka/start.sh <<EOF
/mnt/d/apps/kafka/bin/kafka-server-start.sh -daemon /mnt/d/apps/kafka/server1/conf/server.properties
/mnt/d/apps/kafka/bin/kafka-server-start.sh -daemon /mnt/d/apps/kafka/server2/conf/server.properties
/mnt/d/apps/kafka/bin/kafka-server-start.sh -daemon /mnt/d/apps/kafka/server3/conf/server.properties
EOF
cat > /mnt/d/apps/kafka/stop.sh <<EOF
/mnt/d/apps/kafka/bin/kafka-server-stop.sh /mnt/d/apps/kafka/server1/conf/server.properties
/mnt/d/apps/kafka/bin/kafka-server-stop.sh /mnt/d/apps/kafka/server2/conf/server.properties
/mnt/d/apps/kafka/bin/kafka-server-stop.sh /mnt/d/apps/kafka/server3/conf/server.properties
EOF
测试验证
# 创建主题
/mnt/d/apps/kafka/bin/kafka-topics.sh --create --topic hello-bsmn --bootstrap-server localhost:9091 --partitions 1 --replication-factor 1
# 列出主题
/mnt/d/apps/kafka/bin/kafka-topics.sh --list --bootstrap-server localhost:9091
# 生产者发送消息
/mnt/d/apps/kafka/bin/kafka-console-producer.sh --topic hello-bsmn --bootstrap-server localhost:9091
# 消息者消费消息
/mnt/d/apps/kafka/bin/kafka-console-consumer.sh --topic hello-bsmn --bootstrap-server localhost:9091 --from-beginning
本文来自博客园,作者:白首码农,转载请注明原文链接:https://www.cnblogs.com/bsmn/p/18581990