当前位置:   article > 正文

kafka安全权限验证sasl配置_kafka的sasl认证怎么查看消费组

kafka的sasl认证怎么查看消费组

Kafka

安全认证配置 SASL

常规配置(kafka和zk)

kafka server配置

  1. #进入kafka的配置目录config
  2. cd /mnt/data/kafka/config
  3. #新建配置文件
  4. touch kafka_server.jaas.conf
  5. vim kafka_server.jaas.conf
  6. #注意password后边有;
  7. KafkaServer {
  8.   org.apache.kafka.common.security.plain.PlainLoginModule required
  9.   username="admin"
  10.   password="admin-secret"
  11.   user_admin="admin-secret";
  12. };
  13. KafkaClient {
  14.   org.apache.kafka.common.security.plain.PlainLoginModule required
  15.   username="admin"
  16.   password="admin-secret";
  17. };
  18. Client {
  19.   org.apache.kafka.common.security.plain.PlainLoginModule required
  20.   username="admin"
  21.   password="admin-secret";
  22. };
 

修改server.properties

  1. vim server.properties
  2. # 允许外部端口连接
  3. listeners=SASL_PLAINTEXT://0.0.0.0:9092
  4. # 外部代理地址 外网地址
  5. advertised.listeners=SASL_PLAINTEXT://101.xx.xx.xx:29092
  6. security.inter.broker.protocol=SASL_PLAINTEXT
  7. sasl.enabled.mechanisms=PLAIN
  8. sasl.mechanism.inter.broker.protocol=PLAIN
  9. # Add acl
  10. allow.everyone.if.no.acl.found=true
  11. auto.create.topics.enable=true
  12. delete.topic.enable=true
  13. advertised.host.name=dn1
  14. super.users=User:admin
  15. # Add class
  16. #authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
  17. #kafka3.0之后版本弃用了SimpleAclAuthorizer验证,改为
  18. authorizer.class.name=kafka.security.authorizer.AclAuthorizer

修改kafka/bin

  1. 进入kafka的bin目录bin:
  2. vim kafka-server-start.sh
  3. export KAFKA_OPTS="-Djava.security.auth.login.config=file:$base_dir/../config/kafka_server_jaas.conf"

配置zookeeper

kafka_zoo.jaas.conf

  1. touch kafka_zoo.jaas.conf
  2. vim kafka_zoo.jaas.conf
  3. ZKServer{
  4. org.apache.kafka.common.security.plain.PlainLoginModule required
  5. username="admin"
  6.   password="admin-secret"
  7.   user_kafka="admin-secret";
  8. };

修改zookeeper-server-start.sh

export KAFKA_OPTS="-Djava.security.auth.login.config=file:$base_dir/../config/kafka_zoo_jaas.conf -Dzookeeper.allowSaslFailedClients=false"

如果需要使用kafka自带客户端 需要配置

kafka client配置 kafka/config目录

  1. touch kafka_client.jaas.conf
  2. vim kafka_client.jaas.conf
  3. Client {
  4.   org.apache.kafka.common.security.plain.PlainLoginModule required
  5.   username="admin"
  6.   password="admin-secret"
  7.   user_kafka="admin-secret";
  8. };
 

修改producer.properties

  1. vim producer.properties
  2. security.protocol=SASL_PLAINTEXT
  3. sasl.mechanism=PLAIN

修改consumer.properties

  1. vim consumer.properties
  2. security.protocol=SASL_PLAINTEXT
  3. sasl.mechanism=PLAIN

新增consumer-group-ssl.properties

  1. security.protocol=SASL_PLAINTEXT
  2. sasl.mechanism=PLAIN
  3. sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="账号" password="密码";

修改启动脚本 kafka/bin目录

  1. vim kafka-console-producer.sh
  2. export KAFKA_OPTS="-Djava.security.auth.login.config=file:$base_dir/../config/kafka_client_jaas.conf"
  3. vim kafka-console-consumer.sh
  4. export KAFKA_OPTS="-Djava.security.auth.login.config=file:$base_dir/../config/kafka_client_jaas.conf"

kafka-java配置

1.properties配置

  1. properties.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SASL_PLAINTEXT");
  2. properties.put(SaslConfigs.SASL_MECHANISM,"PLAIN");
  3. properties.put(SaslConfigs.SASL_JAAS_CONFIG,"org.apache.kafka.common.security.plain.PlainLoginModule required username=\"admin\" password=\"admin_secret\";");

kafka脚本

windows

  1. #kafka\bin\windows目录
  2. .\zookeeper-server-start.bat ..\..\config\zookeeper.properties
  3. .\kafka-server-start.bat ..\..\config\server.properties

linux

  1. #kafka/bin目录
  2. #启动zookeeper
  3. ./zookeeper-server-start.sh -daemon /mnt/data/kafka/config/zookeeper.properties
  4. #启动kafka
  5. ./kafka-server-start.sh -daemon /mnt/data/kafka/config/server.properties
  6. #启动eagle
  7. ./ke.sh start
  8. #查询topic信息
  9. ./kafka-topics.sh --describe --zookeeper localhost:2181 --topic member_modify_model
  10. #查询topic内容
  11. ./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic member_modify_model --from-beginning
  12. 查看指定的消费者
  13. ./kafka-consumer-groups.sh --bootstrap-server 192.168.0.75:9092 --command-config config/consumer-group-ssl.properties --group PROVINCE_KAFKA_GROUP --describe
  14. 查看所有的消费者组
  15. ./kafka-consumer-groups.sh --bootstrap-server 192.168.31.253:9092 --all-groups --describe
  16. 查看指定组里的成员
  17. ./kafka-consumer-groups.sh --bootstrap-server 192.168.31.253:9092 --group CountryCounter --describe --members
  18. 查看有那些 group ID 正在进行消费:
  19. ./kafka-consumer-groups.sh --new-consumer --bootstrap-server 192.168.75.128:9092 --list
  20. 查看指定group.id 的消费者消费情况
  21. ./kafka-consumer-groups.sh --bootstrap-server 192.168.0.75:9092 --command-config config/consumer-group-ssl.properties --group PROVINCE_KAFKA_GROUP --describe
  22. 删除消费者组的偏移量
  23. ./kafka-consumer-groups.sh --bootstrap-server 192.168.31.253:9092 --delete-offsets --group CountryCounter --topic t1

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/840386
推荐阅读
相关标签
  

闽ICP备14008679号