Kafka 简易使用指南

安装

mkdir /app/kafka 
cd /app/kafka
wget  https://mirrors.bfsu.edu.cn/apache/kafka/2.8.0/kafka_2.13-2.8.0.tgz
tar -xzf kafka_2.13-2.8.0.tgz
cd kafka_2.13-2.8.0

## 安装 JDK
yum install java-1.8.0-openjdk.x86_64 -y

# 启动 zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties

# 启动 kafka broker
bin/kafka-server-start.sh config/server.properties

消息操作

# 创建 Topic
bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092

# 生产消息
bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092

# 消费消息
bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092

配置 supervisor 启动

kafka-zookeeper.conf
[program:kafka-zookeeper]
command = /app/kafka/kafka_2.13-2.8.0/bin/zookeeper-server-start.sh /app/kafka/kafka_2.13-2.8.0/config/zookeeper.properties
autostart = true       
startsecs = 5          
autorestart = true     
startretries = 3       
user = root            
redirect_stderr = true 
stdout_logfile_maxbytes = 20MB  
stdout_logfile_backups = 20     
stdout_logfile = /app/kafka/log/zookepper.log
kafka-server.conf
[program:kafka-server]
command = /app/kafka/kafka_2.13-2.8.0/bin/kafka-server-start.sh /app/kafka/kafka_2.13-2.8.0/config/server.properties
autostart = true       
startsecs = 5          
autorestart = true     
startretries = 3       
user = root            
redirect_stderr = true          
stdout_logfile_maxbytes = 20MB  
stdout_logfile_backups = 20     
stdout_logfile = /app/kafka/log/server.log

你可能感兴趣的:(kafka)