您当前的位置: 首页 >  彭世瑜 kafka

Kafka单机模式和集群模式环境搭建

彭世瑜 发布时间:2019-06-14 17:14:43 ,浏览量:2

快速开始教程:http://kafka.apache.org/quickstart

单节点服务

1、下载解压: http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.2.1/kafka_2.11-2.2.1.tgz

2、启动服务 需要先启动ZooKeeper服务

$ zkServer.sh start

# 如果没有,可以使用单节点的ZooKeeper
$ bin/zookeeper-server-start.sh config/zookeeper.properties

启动Kafka

> bin/kafka-server-start.sh config/server.properties

3、创建话题

$ 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、发送消息

$ bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
This is a message
This is another message

5、接收消息

$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
This is a message
This is another message
多节点服务

1、修改配置 broker.id 在集群中需要唯一

$ 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、创建话题

> 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个(我的天)

$ jps
72513 Kafka             # 3个Kafka组成集群
72816 Kafka
73081 Kafka 
73872 Jps
73347 ConsoleProducer   # 生产者
73609 ConsoleConsumer   # 消费者
35198
68590 QuorumPeerMain    # Zookeeper
关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 2浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0570s