Kafka - SASL认证
kafka SASL认证配置
1、找到kafka安装根目录,在config文件夹下创建kafka_server_jaas.conf,写入
KafkaServer { org.apache.kafka.common.security.plain.PlainLoginModule required username= "admin" password= "admin-secret" user_admin= "admin-secret" user_alice= "alice-secret" ; }; |
2、在config文件夹下创建kafka_client_jaas.conf,写入
KafkaClient { org.apache.kafka.common.security.plain.PlainLoginModule required username="alice" password="alice-secret"; };
3、打开config文件夹下server.properties,添加
listeners=SASL_PLAINTEXT: //localhost:9092 # 使用的认证协议 security.inter.broker.protocol=SASL_PLAINTEXT # SASL机制 sasl.enabled.mechanisms=PLAIN sasl.mechanism.inter.broker.protocol=PLAIN # 完成身份验证的类 authorizer. class .name=kafka.security.auth.SimpleAclAuthorizer # 如果没有找到ACL(访问控制列表)配置,则允许任何操作。 allow.everyone. if .no.acl.found= true |
4、打开config文件夹下producer.properties、consumer.properties,分别添加
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
5、打开bin\windows目录下的kafka-server-start.bat文件添加
set KAFKA_OPTS=-Djava.security.auth.login.config=file:%~dp0../../config/kafka_server_jaas.conf
6、 打开bin\windows目录下的kafka-console-producer.bat和kafka-console-consumer.bat文件分别添加
set KAFKA_OPTS=-Djava.security.auth.login.config=file:%~dp0../../config/kafka_client_jaas.conf
7、通过以上步骤基本的配置已经完成, 现在开始逐个启动
启动zookeeper:.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
启动kafka:.\bin\windows\kafka-server-start.bat .\config\server.properties
创建topic:.\bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
创建producer:.\bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test --producer.config .\config\producer.properties
创建consumer:.\bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning --consumer.config .\config\consumer.properties
在producer窗口下输入信息进行测试,每输入一行回车后消息马上就会出现在consumer中,表明kafka SASL已经安装测试成功
Confluent.Kafka使用
在producer和consumer config中添加
{ "security.protocol","SASL_PLAINTEXT" }, { "sasl.mechanism","PLAIN" }, { "sasl.username", "alice"}, { "sasl.password", "alice-secret" }, //{ "debug", "security,broker,protocol" } 开启调试
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构