美文网首页
Kafka—配置SASL/PLAIN认证客户端及常用命令

Kafka—配置SASL/PLAIN认证客户端及常用命令

作者: Hughman | 来源:发表于2022-04-07 09:39 被阅读0次

    介绍

      SASL/PLAIN 是一种简单的 username/password安全认证机制,本文主要总结服务端开启该认证后,命令行客户端进行配置的操作流程。

    配置

    增加jaas.properties

    在kafka的config目录下增加jaas.properties文件指定认证协议为SASL_PLAINTEXT

    security.protocol=SASL_PLAINTEXT
    sasl.mechanism=PLAIN
    

    增加kafka_client_jaas.conf

    配置客户端JAAS文件,在kafka的config目录下添加kafka_client_jaas.conf文件配置KafkaClient

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

    修改对应启动脚本

    可以修改kafka-topic.shkafka-console-producer.shkafka-console-consumer.sh启动脚本,增加export信息
    export KAFKA_OPTS=" -Djava.security.auth.login.config=/opt/kafka_2.11-2.2.2/config/kafka_client_jaas.conf

    操作执行

    查看topic列表list

    ./bin/kafka-topic.sh --bootstrap-server localhost:9092 --command-config config/jaas.properties --list 
    

    查看详情describe

    ./bin/kafka-topic.sh --bootstrap-server localhost:9092 --command-config config/jaas.properties --describe --topic topic01
    

    生产producer

    ./bin/kafka-console-producer.sh --broker-list localhost:9092 --producer-config config/jaas.properties --topic topic01
    

    消费consumer

    ./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --consumer-config config/jaas.properties --group group01 --topic topic01
    

    查看消费组

    ./bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --command-config config/jaas.properties --group group01 --describe
    

    相关文章

      网友评论

          本文标题:Kafka—配置SASL/PLAIN认证客户端及常用命令

          本文链接:https://www.haomeiwen.com/subject/noyjsrtx.html