Kafka伪集群搭建

Kafka伪集群搭建
1、下载kafka:https://kafka.apache.org/downloads

tar -zxvf kafka_2.12-2.6.0.tgz

2、Zookeeper配置
启动Zookeeper:

bin/zookeeper-server-start.sh -daemon config/zookeeper.properties

3、kafka配置
1)、复制配置文件

cp server.properties server01.properties
cp server.properties server02.properties
cp server.properties server03.properties

2)、修改配置
分别修改配置文件(设置三个分片)
修改server01.properties文件:

broker.id=0
listeners=PLAINTEXT://192.168.201.133:9092
num.partitions=3
offsets.topic.replication.factor=3
transaction.state.log.replication.factor=3
transaction.state.log.min.isr=3
zookeeper.connect=localhost:2181,localhost:2182,localhost:2183
log.dirs=/tmp/kafka01-logs

修改server02.properties文件:

broker.id=1
listeners=PLAINTEXT://192.168.201.133:9093
num.partitions=3
offsets.topic.replication.factor=3
transaction.state.log.replication.factor=3
transaction.state.log.min.isr=3
zookeeper.connect=localhost:2181,localhost:2182,localhost:2183
log.dirs=/tmp/kafka02-logs

修改server03.properties文件:

broker.id=2
listeners=PLAINTEXT://192.168.201.133:9094
num.partitions=3
offsets.topic.replication.factor=3
transaction.state.log.replication.factor=3
transaction.state.log.min.isr=3
zookeeper.connect=localhost:2181,localhost:2182,localhost:2183
log.dirs=/tmp/kafka03-logs

3)、启动kafka

./kafka-server-start.sh -daemon ../config/server01.properties
./kafka-server-start.sh -daemon ../config/server02.properties
./kafka-server-start.sh -daemon ../config/server03.properties

4)、测试及使用

a. 创建topic

bin/kafka-topics.sh --create --zookeeper 192.168.201.133:2181 --replication-factor 3 --partitions 3 --topic test

b. 查看主题

bin/kafka-topics.sh --list --zookeeper 192.168.201.133:2181

c. 发送消息

bin/kafka-console-producer.sh --broker-list 192.168.201.133:9092 --topic test

d. 接收消息

bin/kafka-console-consumer.sh --bootstrap-server 192.168.201.133:9093 --topic test --from-beginning

e. 查看特定主题的详细信息

bin/kafka-topics.sh --zookeeper localhost:2181 --describe  --topic test

f.删除主题

bin/kafka-topics.sh --zookeeper localhost:2181 --delete  --topic test

g.查看消费组详细信息

 ./kafka-consumer-groups.sh --bootstrap-server 192.168.201.133:9092 --describe --group aaa3

在这里插入图片描述

4、安装可视化工具
下载安装:https://www.kafkatool.com/download.html

在这里插入图片描述

kafka消费后不会自动删除数据,通过消费的offset来判断消费的位置,可以设置消息保留的时间:
全局设置:修改server.properties文件

log.retention.hours=72 #默认7天 按生产时间计算
log.retention.bytes=1073741824 #按文件大小,超过文件大小的话被删除

单独设置某个topic过期时间

./kafka-configs.sh --zookeeper localhost:2181 --alter --entity-name mytopic --entity-type topics --add-config retention.ms=86400000

立即删除某个topic消息

./kafka-topics.sh --zookeeper localhost:2181 --alter --topic mytopic --config cleanup.policy=delete

消费:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值