首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >卡夫卡-动物园管理员- ACL配置

卡夫卡-动物园管理员- ACL配置
EN

Stack Overflow用户
提问于 2017-03-28 07:33:28
回答 1查看 5.1K关注 0票数 3

上下文

我正在尝试建立一个基于kafka的分布式日志系统(我知道有一些东西,比如logstash .)但是,我希望能够在之后设置一些风暴拓扑,例如,在流变慢时发送通知。

设置

我在8082端口上有一个正在运行的服务器(WilfyS群,keycloack认证),它承载了我的日志功能。我可以通过REST将登录线推送到这个服务器。在幕后,一位卡夫卡制作人正在向卡夫卡传播这些信息。

  • 我在2181港有动物园管理员
  • 我有个经纪人在9092端口运行
  • 我的日志服务器运行在8082端口。

我的server.properties (用于代理):

代码语言:javascript
复制
listeners=PLAINTEXT://localhost:9092
authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
super.users=User:Bob;User:Alice;User:anonymous

我的acl配置:

代码语言:javascript
复制
call kafka\bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic testtopic
call kafka\bin\windows\kafka-acls.bat --add --allow-principal User:anonymous --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=localhost:2181  --allow-host http://localhost:8082 --operation Read --operation Write --topic testtopic
call kafka\bin\windows\kafka-acls.bat --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=localhost:2181 --add --allow-principal User:anonymous --consumer --topic testtopic --group group --allow-host http://localhost:8082
call kafka\bin\windows\kafka-acls.bat --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=localhost:2181 --add --allow-principal User:anonymous --producer --topic testtopic --allow-host http://localhost:8082
call kafka\bin\windows\kafka-acls.bat --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=localhost:2181 --add --allow-principal User:anonymous --producer --topic testtopic --allow-host 192.168.3.63

我的(java)生产者属性:

代码语言:javascript
复制
    @Produces
    private Producer<String, String> stringStringProducer(){
        Properties props = new Properties();
        props.put("bootstrap.servers", "localhost:9092");
        props.put("acks", "all");
        props.put("retries", 0);
        props.put("batch.size", 16384);
        props.put("linger.ms", 1);
        props.put("buffer.memory", 33554432);
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        Producer<String, String> producer = null;
        try {
            producer = new KafkaProducer<>(props);
            return producer;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

问题

当我试图通过Java生成器(和控制台生成器)生成消息时,我得到:

代码语言:javascript
复制
[org.apache.kafka.clients.NetworkClient] (kafka-producer-network-thread | producer-6) Error while fetching metadata with correlation id 10 : {testtopic=UNKNOWN_TOPIC_OR_PARTITION}

有人知道我做错了什么吗?

第一解

通过授予对127.0.0.1的访问权限,我成功地克服了此错误消息:

代码语言:javascript
复制
call kafka\bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic testtopic

call kafka\bin\windows\kafka-acls.bat --add --allow-principal User:anonymous --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=localhost:2181  --allow-host http://localhost:8082 --operation Read --operation Write --topic testtopic
call kafka\bin\windows\kafka-acls.bat --add --allow-principal User:ANONYMOUS --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=localhost:2181  --allow-host 127.0.0.1 --operation Read --operation Write --topic testtopic

call kafka\bin\windows\kafka-acls.bat --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=localhost:2181 --add --allow-principal User:anonymous --consumer --topic testtopic --group group --allow-host http://localhost:8082
call kafka\bin\windows\kafka-acls.bat --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=localhost:2181 --add --allow-principal User:ANONYMOUS --consumer --topic testtopic --group group --allow-host 127.0.0.1

call kafka\bin\windows\kafka-acls.bat --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=localhost:2181 --add --allow-principal User:anonymous --producer --topic testtopic --allow-host http://localhost:8082
call kafka\bin\windows\kafka-acls.bat --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=localhost:2181 --add --allow-principal User:ANONYMOUS --producer --topic testtopic --allow-host 127.0.0.1

通过查看日志文件(即转到kafka文件夹中的log4j.properties并将log4j.logger.kafka.authorizer.logger属性更改为DEBUG ),我发现了这个问题。然后,您将得到具体的错误(即缺少权限)。

新问题

当我想要产生信息时,我现在得到:

代码语言:javascript
复制
[2017-03-28 15:39:07,704] WARN Error while fetching metadata with correlation id 0 : {testtopic=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2017-03-28 15:39:07,800] WARN Error while fetching metadata with correlation id 1 : {testtopic=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2017-03-28 15:39:07,912] WARN Error while fetching metadata with correlation id 2 : {testtopic=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2017-03-28 15:39:08,024] WARN Error while fetching metadata with correlation id 3 : {testtopic=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

有人知道怎么解决吗?

解决了

我在代理配置(server.properties)中向超级用户添加了“匿名”:

代码语言:javascript
复制
authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
super.users=User:Bob;User:Alice;User:ANONYMOUS
#port = 9092
#advertised.host.name = localhost
#listeners=SASL_SSL://localhost:9092
#security.inter.broker.protocol=SASL_SSL
#sasl.mechanism.inter.broker.protocol=PLAIN
#sasl.enabled.mechanisms=PLAIN
host.name=127.0.0.1
advertised.host.name=localhost
advertised.port=9092
EN

回答 1

Stack Overflow用户

发布于 2017-09-11 07:17:27

出现此问题是因为您已在以下行中启用了授权:

代码语言:javascript
复制
authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer

但是代理是与User:ANONYMOUS一起运行的,因为有以下行:

代码语言:javascript
复制
listeners=PLAINTEXT://localhost:9092

也就是说,代理无法对自己进行身份验证。在我的例子中(SSL身份验证),我必须执行以下操作:

  1. 使用security.inter.broker.protocol=SSL启用代理间安全性。
  2. 通过设置listeners=SSL://broker1:9092 (注意没有PLAINTEXT://broker1:9091)禁用代理的明文端口
  3. 使用kafka-acls.sh为在SSL证书中定义的用户定义ACL。
  4. 重新启动代理。

P. S.你的回答中的解决办法是不鼓励的。您可以阅读它的含义这里

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43063289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档