0


【Kafka SASL认证】

条件:

Kafka配置SASL认证:

1.创建文件中配置用户

①.kafka/config/下创建kafka_client_jaas.conf文件:
KafkaClient {  
org.apache.kafka.common.security.plain.PlainLoginModule required  
  username="admin"  
  password="admin";};
②.kafka/config/下创建kafka_server_jaas.conf文件:
KafkaServer {
        org.apache.kafka.common.security.plain.PlainLoginModule required
        username="admin"
        password="admin"
        user_admin="admin"
        user_test1="123456"
        user_test2="1234567";};

KafkaClient {
    org.apache.kafka.common.security.plain.PlainLoginModule required
        username="admin"
        password="admin";};

Client {
    org.apache.kafka.common.security.plain.PlainLoginModule required
        username="admin"
        password="admin";};
③.kafka/config/下创建kafka_zoo_jaas.conf文件:
ZKServer{
    org.apache.kafka.common.security.plain.PlainLoginModule required
        username="admin"
        password="admin"
        user_admin="admin";};
④.kafka/config/consumer.properties文件,添加下面内容:
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
⑤.kafka/config/producer.properties文件,添加下面内容:
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
⑥.kafka/config/zookeeper.properties文件,添加下面内容:
authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
requireClientAuthScheme=sasl
jaasLoginRenew=3600000
⑦.kafka/config/server.properties文件,添加下面内容:
listeners=SASL_PLAINTEXT://ip:9092
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.enabled.mechanisms=PLAIN
sasl.mechanism.inter.broker.protocol=PLAIN
authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
super.users=User:admin
delete.topic.enable=true
auto.create.topics.enable=false

2.修改Kafka的bin文件(注意:里面有自己的路径需要修改)

①.修改zookeeper-server-start.sh文件:
export KAFKA_OPTS="-Djava.security.auth.login.config=/自己的路径/kafka_2.11-0.11.0.0/config/kafka_zoo_jaas.conf -Dzookeeper.sasl.serverconfig=ZKServer"
②.修改kafka-server-start.sh文件:
export KAFKA_OPTS=" -Djava.security.auth.login.config=/自己的路径/kafka_2.11-0.11.0.0/config/kafka_server_jaas.conf"
③.修改kafka-console-producer.sh文件:
export KAFKA_OPTS=" -Djava.security.auth.login.config=/自己的路径/kafka_2.11-0.11.0.0/config/kafka_client_jaas.conf"
④.修改kafka-console-consumer.sh文件:
export KAFKA_OPTS=" -Djava.security.auth.login.config=/自己的路径/kafka_2.11-0.11.0.0/config/kafka_client_jaas.conf"

3.启动

①.启动zookeeper:
bin/zookeeper-server-start.sh config/zookeeper.properties
②.启动kafka:
bin/kafka-server-start.sh congif/server.properties

4.生产、消费

①.生产:
bin/kafka-console-producer.sh --broker-list ip:9092--topic test --producer.config config/producer.properties
①.消费:
bin/kafka-console-consumer.sh --bootstrap-server ip:9092--topic test --from-beginning --consumer.config config/consumer.properties
标签: kafka php

本文转载自: https://blog.csdn.net/ZhongYuxuanG/article/details/124321612
版权归原作者 ZhongYuxuanG 所有, 如有侵权,请联系我们删除。

“【Kafka SASL认证】”的评论:

还没有评论