快速开始教程:http://kafka.apache.org/quickstart
单节点服务
国内镜像
- https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/
1、下载解压:
http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.2.1/kafka_2.11-2.2.1.tgz
2、启动服务
需要先启动ZooKeeper服务
复制代码
1
2
3
4
5$ zkServer.sh start # 如果没有,可以使用单节点的ZooKeeper $ bin/zookeeper-server-start.sh config/zookeeper.properties
启动Kafka
复制代码
1
2> bin/kafka-server-start.sh config/server.properties
3、创建话题
复制代码
1
2
3
4
5
6$ bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test # 查看话题 $ bin/kafka-topics.sh --list --bootstrap-server localhost:9092
4、发送消息
复制代码
1
2
3
4$ bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test This is a message This is another message
5、接收消息
复制代码
1
2
3
4$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning This is a message This is another message
多节点服务
1、修改配置
broker.id 在集群中需要唯一
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13$ cp config/server.properties config/server-1.properties $ cp config/server.properties config/server-2.properties $ cat config/server-1.properties: broker.id=1 listeners=PLAINTEXT://:9093 log.dirs=/tmp/kafka-logs-1 $ config/server-2.properties: broker.id=2 listeners=PLAINTEXT://:9094 log.dirs=/tmp/kafka-logs-2
2、创建话题
复制代码
1
2
3
4
5
6
7> bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 3 --partitions 1 --topic my-replicated-topic # 查看话题描述 > bin/kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic test > bin/kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic my-replicated-topic
3、查看进程,一共有6个(我的天)
复制代码
1
2
3
4
5
6
7
8
9
10$ jps 72513 Kafka # 3个Kafka组成集群 72816 Kafka 73081 Kafka 73872 Jps 73347 ConsoleProducer # 生产者 73609 ConsoleConsumer # 消费者 35198 68590 QuorumPeerMain # Zookeeper
最后
以上就是无限音响最近收集整理的关于Kafka单机模式和集群模式环境搭建单节点服务多节点服务的全部内容,更多相关Kafka单机模式和集群模式环境搭建单节点服务多节点服务内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复