Kafka安装

文章目录
[隐藏]
kafka是一个分布式消息队列。具有高性能、持久化、多副本备份、横向扩展能力。
环境要求:JAVA JDK
文档:http://kafka.apachecn.org
1.下载kafka
wget http://mirrors.hust.edu.cn/apache/kafka/2.0.0/kafka_2.12-2.0.0.tgz
wget http://archive.apache.org/dist/kafka/1.0.0/kafka_2.12-1.0.0.tgz
2.解压
tar -zxf kafka_2.12-2.0.0.tgz
mv kafka_2.12-2.0.0 /usr/local/bin/kafka
cd /usr/local/bin/kafka/bin
3.启动服务器
启动自带Zookeeper:
bin/zookeeper-server-start.sh config/zookeeper.properties
不挂断后台启动,无输出
nohup bin/zookeeper-server-start.sh config/zookeeper.properties >/dev/null 2>&1 &
不挂断后台运行 日志输出zookeeper.log
nohup bin/zookeeper-server-start.sh config/zookeeper.properties > zookeeper.log & 


OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
...

启动kafka:
bin/kafka-server-start.sh config/server.properties
不挂断后台启动,无输出
nohup bin/kafka-server-start.sh config/server.properties >/dev/null 2>&1 &
不挂断后台运行 日志输出kafka.log
nohup bin/kafka-server-start.sh config/server.properties > kafka.log & 

OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
...
4.创建Topic
创建Topic
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

Created topic "test".

查看Topic列表
bin/kafka-topics.sh --list --zookeeper localhost:2181

test
5.生成者发送消息
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

>this is test Message
6.消费者接收消息
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

this is test Message
7.kafaka中Zookeeper作用:
1. Zookeeper在kafka的作
    1>. kafaka使用Zookeeper分布式协调服务,将生产者、消费者、消息存储(broker、用户存储信息、消息读写等)结合在一起。同时kafaka借助Zookeeper能够将生成者、消费者和broker在内的所有组件在无状态的条件下建立起生产者和消费者订阅关系,实现生产者的负载均衡。
    2>. Kafka集群中有一个broker会被选举为Controller,负责管理集群broker的上下线,所有topic的分区副本分配和leader选举等工作。Controller的管理工作都是依赖于Zookeeper的
2. 开启kafka服务器需要先开启Zookeeper服务器。
3. kafka有两种方式开启Zookeeper:(Zookeeper可以不用和kafka在一个设备上)
    1>. kafka自带Zookeeper
    2>. 自定义安装Zookeeper,kafka配置连接
276 人浏览过

发表评论

邮箱地址不会被公开。 必填项已用*标注