kafka windows环境搭建 SASL_PLAINTEXT/SCRAM acl认证记录
一、kafka 下载参考地址
https://kafka.apache.org/downloads
二、环境准备
1)64 bit JDK 1.8+;下载 & 配置。
2)zookeeper,因kafka内置zookeeper,故不需要下载和配置
三、修改配置文件
这里主要修改四个配置文件server.properties、zookeeper.properties、consumer.properties 、producer.properties
1)server.properties
文件位置:kafka\config
#配置启动log存放位
log.dirs=D:\airlook_java_project\kafka_server/kafka-logs
sasl.enabled.mechanisms=SCRAM-SHA-256
sasl.mechanism.inter.broker.protocol=SCRAM-SHA-256
security.inter.broker.protocol=SASL_PLAINTEXT
listeners=SASL_PLAINTEXT://10.21.80.20:9092
listener.name.sasl_plaintext.scram-sha-256.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required
username=“admin”
password=“admin”;
#授权方面
#设置身份验证使用的类
authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
#设置超级账号,如果是多个需要分号分割,例如:User:admin;User:root
super.users=User:admin
#对所有用户topic可见,要禁用。
allow.everyone.if.no.acl.found=false
2)zookeeper.properties
文件位置:kafka\config
dataDir=D:\airlook_java_project\kafka_server/data/zookeeper
#下面这几个参数似乎可以不配
maxClientCnxns=0
authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
requireClientAuthScheme=sasl
jssaLoginRenew=3600000
3)consumer.properties 、producer.properties 文件
文件位置:kafka\config
security.protocol=SASL_PLAINTEXT
sasl.mechanism=SCRAM-SHA-256
#这是一行的配置,这里显示成了两行
sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \ username=“admin” password=“admin”
4)创建授权配置文件 auth.conf 文件,供其他命令使用,比如创建topic ,查询topic,都需要改配置进行权限认证
文件位置:kafka\config
security.protocol=SASL_PLAINTEXT
sasl.mechanism=SCRAM-SHA-256
sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \ username=“admin” password=“admin”
四、授权
在D:\developSOFT\kafka\kafka_2.12-Jaas_Scram\bin\windows 文件夹内输入 cmd 进入dos命令窗口
#动态添加admin用户
kafka-configs.bat --zookeeper 127.0.0.1:2181 --alter --add-config SCRAM-SHA-256=[password=admin] --entity-type users --entity-name admin
五、启动命令
注意:在D:\developSOFT\kafka\kafka_2.12-Jaas_Scram\bin\windows 文件夹内输入 cmd 进入dos命令窗口
1、启动zookeeper服务
zookeeper-server-start.bat …/…/config/zookeeper.properties
2、关闭zookeeper服务
zookeeper-server-stop.bat …/…/config/zookeeper.properties
3、启动kafka
kafka-server-start.bat …/…/config/server.properties
4.关闭kafka ,也可使用 ctil + c 按键关闭
kafka-server-stop.bat …/…/config/server.properties
5、创建主题 test-topic
kafka-topics.bat --create --zookeeper 127.0.0.1:2181 --replication-factor 1 --partitions 3 --topic testxp command-config …/…/config/auth.conf
6、启动消费者
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic testxp --from-beginning --consumer.config …/…/config/consumer.properties
7、启动生产者
kafka-console-producer.bat --broker-list 127.0.0.1:9092 --topic testxp --producer.config …/…/config/producer.properties
8、查看消费组
kafka-consumer-groups.bat --bootstrap-server localhost:9092 --list --command-config …/…/config/auth.conf
9、查看主题命令
kafka-topics.bat --list --bootstrap-server localhost:9092 --command-config …/…/config/auth.conf
10、其他命令记录:
#添加test用户
kafka-configs.bat --zookeeper 127.0.0.1:2181 --alter --add-config SCRAM-SHA-256=[password=123456] --entity-type users --entity-name test
#给test 用户 赋予 testxp 的topic读权限
kafka-acls.bat --authorizer-properties zookeeper.connect=127.0.0.1:2181 --add --allow-principal User:“test” --consumer --topic ‘testxp’ --group ‘*’
#给test 用户赋予 testxp 的topic 写权限
kafka-acls.bat --authorizer-properties zookeeper.connect=127.0.0.1:2181 --add --allow-principal User:“test” --producer --topic ‘testxp’
参考链接:
https://www.jianshu.com/p/704ca9560718
kafaka 的授权认证 SASL/PLANTEXT ACL 参考地址: https://blog.csdn.net/weixin_41835653/article/details/124205519