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" }  开启调试

 

转载于:https://www.cnblogs.com/xxinwen/p/10687973.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值