当前位置: 首页 > news >正文

Kafka配置SASL_PLAINTEXT权限。常用操作命令,创建用户,topic授权

查看已经创建的topic

./bin/kafka-topics.sh --bootstrap-server localhost:9092 --list

创建topic

创建分区和副本数为1的topic

./bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --topic acltest --partitions 1 --replication-factor 1

创建kafka用户

创建writer用户

./bin/kafka-configs.sh --bootstrap-server localhost:9092 --alter -add-config 'SCRAM-SHA-256=[iterations=8192,password=pwd],SCRAM-SHA-512=[password=pwd]' --entity-type users --entity-name kafkawriter

创建reader用户

./bin/kafka-configs.sh --bootstrap-server localhost:9092 --alter -add-config 'SCRAM-SHA-256=[iterations=8192,password=pwd],SCRAM-SHA-512=[password=pwd]' --entity-type users --entity-name kafkareader

删除指定用户

./bin/kafka-configs.sh --zookeeper localhost:2181 --alter --delete-config 'SCRAM-SHA-512' --delete-config 'SCRAM-SHA-256' --entity-type users --entity-name admin

查看指定用户

./bin/kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type users --entity-name kafkawriter

./bin/kafka-configs.sh --zookeeper localhost:2181 --describe --entity-type users --entity-name kafkareader

给topic授权

./bin/kafka-acls.sh --authorizer kafka.security.authorizer.AclAuthorizer --authorizer-properties zookeeper.connect=192.168.5.54:2181 --add --allow-principal User:kafkawriter --operation Write --topic bigData

./bin/kafka-acls.sh --authorizer kafka.security.authorizer.AclAuthorizer --authorizer-properties zookeeper.connect=192.168.5.54:2181 --add --allow-principal User:admin --operation Read --topic bigData

查看topic权限

./bin/kafka-acls.sh --authorizer kafka.security.authorizer.AclAuthorizer --authorizer-properties zookeeper.connect=192.168.5.54:2181 --list --topic bigData

修改server.properties,开启sasl

listeners=SASL_PLAINTEXT://192.168.1.214:9092

advertised.listeners=SASL_PLAINTEXT://192.168.1.214:9092

authorizer.class.name=kafka.security.authorizer.AclAuthorizer

allow.everyone.if.no.acl.found=false

super.users=User:admin

# 启用SCRAM机制,采用SCRAM-SHA-512算法

sasl.enabled.mechanisms=SCRAM-SHA-256

# 为broker间通讯开启SCRAM机制,采用SCRAM-SHA-512算法

sasl.mechanism.inter.broker.protocol=SCRAM-SHA-256

# broker间通讯使用PLAINTEXT,本例中不演示SSL配置

security.inter.broker.protocol=SASL_PLAINTEXT

重启kafka服务

新建生产者配置

config/producer.conf

security.protocol=SASL_PLAINTEXT

sasl.mechanism=SCRAM-SHA-256

sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="kafkawriter" password="pwd";

给生产者授权

./bin/kafka-acls.sh --authorizer kafka.security.authorizer.AclAuthorizer --authorizer-properties zookeeper.connect=192.168.1.214:2181 --add --allow-principal User:kafkawriter --operation Write --topic bigData

生产者发送消息

./bin/kafka-console-producer.sh --broker-list 192.168.1.214:9092 --topic bigData --producer.config ./config/producer.conf

新建消费者配置

security.protocol=SASL_PLAINTEXT

sasl.mechanism=SCRAM-SHA-256

sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="kafkareader" password="pwd";

cat config/producer.conf

给消费者授权

./bin/kafka-acls.sh --authorizer kafka.security.authorizer.AclAuthorizer --authorizer-properties zookeeper.connect=192.168.1.214:2181 --add --allow-principal User:kafkareader --operation Read --topic bigData

授权group分组

./bin/kafka-acls.sh --authorizer kafka.security.authorizer.AclAuthorizer --authorizer-properties zookeeper.connect=192.168.1.214:2181 --add --allow-principal User:kafkareader --operation Read --topic bigData --group testgroup

消费者消费消息

./bin/kafka-console-consumer.sh --bootstrap-server 192.168.1.214:9092 --topic bigData --consumer.config ./config/consumer.conf  --from-beginning --group testgroup

以上就是配置sasl的全过程了,kafka使用版本为kafka_2.13-3.7.0,文章中的ip地址经过变动,测试人员需保证ip地址一致

http://www.lryc.cn/news/318655.html

相关文章:

  • [Java、Android面试]_05_内存泄漏和内存溢出
  • MySQL-HMA 高可用故障切换
  • 深度学习 精选笔记(11)深度学习计算相关:GPU、参数、读写、块
  • 深度学习 Day27——J7对于ResNeXt-50算法的思考
  • 华为配置敏捷分布式SFN漫游实验
  • 续上篇 qiankun 微前端配置
  • AI日报:欧盟人工智能法案通过后行业面临合规障碍
  • 音视频如何快速转二维码?在线生成音视频活码的教程
  • 开源堡垒机Jumpserver安装教程
  • CentOS 7 socat命令端口转发 —— 筑梦之路
  • SeaTunnel 2.3.4 Cluster in K8S
  • 多模态学习 - 视觉语言预训练综述-2023-下游任务、数据集、基础知识、预训练任务、模型
  • Vite为什么比Webpack快
  • 因聚而生 数智有为丨软通动力携子公司鸿湖万联亮相华为中国合作伙伴大会2024
  • 724.寻找数组的中心下标
  • Selenium 是什么?简单了解Selenium
  • 钡铼技术有限公司R40路由器工业4G让养殖环境监控更高效
  • vue2 / vue3 路由(返回跳转)时判断 + 取消跳转
  • 【设计模式】Java 设计模式之代理模式(Proxy Pattern)
  • 逻辑数据平台的 NoETL 之道(内含QA)
  • 低代码与数智制造:引领软件开发的革新之旅
  • 安装 AWS Load Balancer Controller 附加组件
  • 性能测试什么时候开始?性能测试流程介绍
  • 爬虫逆向实战(36)-某建设监管平台(RSA,魔改)
  • DeepLearning in Pytorch|共享单车预测NN详解(思路+代码剖析)
  • 如何配置Apache的反向代理
  • Vue.js 应用实现监控可观测性最佳实践
  • Rust 语言中符号 :: 的使用场景
  • Java 获取笔记本WiFi网络基站信息的方法
  • Python如何处理拥塞控制