• Kafka


    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、打开binwindows目录下的kafka-server-start.bat文件添加

    set KAFKA_OPTS=-Djava.security.auth.login.config=file:%~dp0../../config/kafka_server_jaas.conf

    6、 打开binwindows目录下的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:.inwindowszookeeper-server-start.bat .configzookeeper.properties

    启动kafka:.inwindowskafka-server-start.bat .configserver.properties

    创建topic:.inwindowskafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

    创建producer:.inwindowskafka-console-producer.bat --broker-list localhost:9092 --topic test --producer.config .configproducer.properties

    创建consumer:.inwindowskafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning --consumer.config .configconsumer.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" }  开启调试
  • 相关阅读:
    Android手势(上,下,左和右的判断)
    我爱意甲
    程序员特有的9个坏习惯
    我爱英超
    VS2010快捷键总结(一)
    C#中导出Excel总结
    MessageDAL
    GDI+ 绘图总结
    .net中绑定日期时,只显示年月日的做法
    Vb线程控制
  • 原文地址:https://www.cnblogs.com/xxinwen/p/10687973.html
Copyright © 2020-2023  润新知