一.Kafka架构
producer:生产馒头
consumer:吃馒头
broker:篮子来装馒头
topic:馒头的标签 馒头A,馒头B
二.安装zookeeper
配置环境变量
zoo.cfg 配置tmp路径(自己定义位置) 默认端口2181
启动:./zkServer.sh start
三.安装Kafka
配置环境变量
server.properties 配置:
broker.id(要唯一,一个Kafka相当于一个篮子)
接听端口默认 9092
log.dirs(配置tmp路径,自己定义位置)
hostname=hadoop000
zookeeper.connection=hadoop000:2181
启动:kafka-server-start.sh $KAFKA_HOME/config/server.properties
创建topic:kafka-topics.sh --create --zookeeper hadoop000:2181 --replication-factor 1 --partitions 1 --topic test
查看topic:kafka-topics.sh --list --zookeeper hadoop000:2181
发送消息:kafka-console-producer.sh --broker-list hadoop000:9092 --topic test
消费:kafka-console-consumer.sh --zookeeper hadoop000:2181 --topic test --from-beginning(保留以前信息)
topic信息:kafka-topics.sh --describe --zookeeper hadoop000:2181 --topic test(不加可查看全部topic)
四.单节点多broker
server-1.properties broker.id=1,端口9093,log.dirs改一下
server-2.properties broker.id=2,端口9094,log.dirs
server-3.properties broker.id=3,端口9095,log.dirs
启动:
kafka-server-start.sh -daemon $KAFKA_HOME/config/server-1.properties &
kafka-server-start.sh -daemon $KAFKA_HOME/config/server-2.properties &
kafka-server-start.sh -daemon $KAFKA_HOME/config/server-3.properties &
创建topic:kafka-topics.sh --create --zookeeper hadoop000:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic
发送消息:kafka-console-producer.sh --broker-list hadoop000:9093,hadoop000:9094,hadoop000:9095 --topic my-replicated-topic
消费:kafka-console-consumer.sh --zookeeper hadoop000:2181 --from-beginning --topic my-replicated-topic
来源:CSDN
作者:程研板
链接:https://blog.csdn.net/qq_38258720/article/details/104150778