kafka 安装需要先安装java、zookeeper,此处默认已具备。
浏览器直接访问下载:
https://dlcdn.apache.org/kafka/
或者直接命令下载
wget https://dlcdn.apache.org/kafka/3.6.0/kafka_2.12-3.6.0.tgz
# 解压
tar -zxvf kafka_2.12-3.6.0.tgz
# 重命名
mv kafka_2.12-3.6.0 kafka
# pwd 查看基础路径
# 配置文件路径
kafka/config
# vim server.properties
log.retention.hours=48 #数据最多保存48小时
log.retention.bytes=1073741824 #数据最多1G
log.dirs=/home/gl/middleware/kafka/kafka-logs #修改日志文件路径
listeners=PLAINTEXT://127.0.0.1:9092
advertised.listeners=PLAINTEXT://127.0.0.1:9092
# 1. 先启动zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties &
# 2.启动kafka
bin/kafka-server-start.sh config/server.properties &
# 查看进程
ps -ef | grep zookeeper
ps -ef | grep kafka
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic test --partitions 2 --replication-factor 1
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
#发送消息
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
# 接收消息
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning