和消息系统类似
消息中间件:生产者和消费者
篮子/框: Kafa
producer: 生产者,就是生产馒头(老妈)
consumer: 消息者,就是吃馒头的(你)
broker:篮子
topic:主题,给馒头带一个标签,topic a 的馒头是给你吃的,topic b的馒头是给你弟弟吃
单节点单Broker部署及使用
单节点多Broker部署及使用
多节点多Broker部署及使用
单节点单broker的部署及使用
1)首先下载zookeeper (zookeeper-3.4.5-cdh5.7.0.jar)
解压、配置bash_profile环境变量
修改zoo.cfg配置文件,添加dataDir=/home/hadoop/app/tmp/zk
开启zookeeper服务测试 zkServer.sh start 关闭 zkServer.sh stop
jps可查看到 xxx QuorumPeerMain
2)再下载kafka (kafka_2.11-0.9.0.0) wget link
解压、配置bash_profile环境变量
修改查看$KAFKA_HOME/config/server.properties
broker.id=0
listeners
host.name
log.dirs
zookeeper.connect 需要进行修改
启动Kafka (前提是先开启zookeeper服务)
kafka-server-start.sh $KAFKA_HOME/config/server.properties
创建topic zk
kafka-topics.sh --create --zookeeper hadoop000:2181 --replication-factor 1 --partitions 1 --topic hello_top
查看所有topic
kafka-topics.sh --list --zookeeper hadoop000:2181
可以查看到hello_top topic
发送消息 broker
kafka-console-producer.sh --broker-list hadoop000:9092 --topic hello_top
消费消息 zk
kafka-console-consumer.sh --zookeeper hadoop000:2181 --topic hello_top --from-beginning
--from-beginning 表示从头开始消费
查看所有topic的详细信息:
kafka-topics.sh --describe --zookeeper hadoop000:2181 --topic hello_top
单节点多Broker部署及使用 jps查看
server-1.properties
server-2.properties
server-3.properties
启动
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
查看所有topic
kafka-topics.sh --list --zookeeper hadoop000:2181
可以查看到hello_top topic
发送消息 broker
kafka-console-producer.sh --broker-list hadoop000:9093,hadoop000:9094,hadoop000:9095 --topic my-replicated-topic
消费消息 zk
kafka-console-consumer.sh --zookeeper hadoop000:2181 --topic my-replicated-topic --from-beginning
--from-beginning 表示从头开始消费
使用java api进行连接的时候,需要修改配置文件,参考https://blog.csdn.net/vtopqx/article/details/78587703
使用java api编写kafka 生产者消费者
整合Flume和Kafka完成实时数据采集
1)启动zookeeper
zkServer.sh start
2)启动Kafka
kafka-server-start.sh $KAFKA_HOME/config/server.properties
3)启动flume数据采集
avro-memory-kafka.conf
avro-memory-kafka.sources = avro-source
avro-memory-kafka.sinks = kafka-sink
avro-memory-kafka.channels = memory-channel
avro-memory-kafka.sources.avro-source.type = avro
avro-memory-kafka.sources.avro-source.bind = hadoop000
avro-memory-kafka.sources.avro-source.port = 44444
avro-memory-kafka.sinks.kafka-sink.type = org.apache.flume.sink.kafka.KafkaSink
avro-memory-kafka.sinks.kafka-sink.brokerList = hadoop000:9092
avro-memory-kafka.sinks.kafka-sink.topic = hello_topic
avro-memory-kafka.sinks.kafka-sink.batchSize = 5
avro-memory-kafka.sinks.kafka-sink.requiredAcks =1
avro-memory-kafka.channels.memory-channel.type = memory
avro-memory-kafka.sources.avro-source.channels = memory-channel
avro-memory-kafka.sinks.kafka-sink.channel = memory-channel
启动avro-memory-kafka.conf
flume-ng agent --name avro-memory-kafka --conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/avro-memory-kafka.conf \
-Dflume.root.logger=INFO,console
启动exec-memory-avro.conf
flume-ng agent --name exec-memory-avro --conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/exec-memory-avro.conf \
-Dflume.root.logger=INFO,console
4)使用Kafka创建一个consumer来消费flume产出的数据
kafka-console-consumer.sh --zookeeper hadoop000:2181 --topic hello_topic
5)向/home/hadoop/data目录中的data.log 输入一定数据,查看是否成功。
echo happy >> data.log 检查consumer是否成功获取到数据