我有一个带有2个代理的Kafka集群,每个代理都在自己的(AWS)服务器上(我使用intstructions here设置集群) . 我正在使用SASL(但没有加密) . 在运行代理2的服务器2上,我创建了一个主题:
KAFKA_OPTS="-Djava.security.auth.login.config=/home/kafka/kafka_2.11-1.0.0/config/jaas.conf -Djava.security.krb5.conf=/etc/krb5.conf" \
bin/kafka-topics.sh --create \
--zookeeper zookeeper-server-01.eigenroute.com:2181,zookeeper-server-02.eigenroute.com:2181,zookeeper-server-03.eigenroute.com:2181/apps/kafka-cluster-demo \
--replication-factor 2 --partitions 9 --topic another-test-topic
看似成功,因为描述主题表明它至少是创建的:
KAFKA_OPTS="-Djava.security.auth.login.config=/home/kafka/kafka_2.11-1.0.0/config/jaas.conf -Djava.security.krb5.conf=/etc/krb5.conf" \
bin/kafka-topics.sh --describe \
--zookeeper zookeeper-server-01.eigenroute.com:2181,zookeeper-server-02.eigenroute.com:2181,zookeeper-server-03.eigenroute.com:2181/apps/kafka-cluster-demo
Topic:another-test-topic PartitionCount:9 ReplicationFactor:2 Configs: MarkedForDeletion:true
Topic: another-test-topic Partition: 0 Leader: none Replicas: 2,1 Isr:
Topic: another-test-topic Partition: 1 Leader: none Replicas: 1,2 Isr:
Topic: another-test-topic Partition: 2 Leader: none Replicas: 2,1 Isr:
Topic: another-test-topic Partition: 3 Leader: none Replicas: 1,2 Isr:
Topic: another-test-topic Partition: 4 Leader: none Replicas: 2,1 Isr:
Topic: another-test-topic Partition: 5 Leader: none Replicas: 1,2 Isr:
Topic: another-test-topic Partition: 6 Leader: none Replicas: 2,1 Isr:
Topic: another-test-topic Partition: 7 Leader: none Replicas: 1,2 Isr:
Topic: another-test-topic Partition: 8 Leader: none Replicas: 2,1 Isr:
如您所见,此主题未分配任何领导者,并且没有同步副本 . 我已经为 生产环境 者分配了写权限:
KAFKA_HEAP_OPTS="-Djava.security.auth.login.config=/home/kafka/kafka_2.11-1.0.0/config/jaas.conf -Dsun.security.krb5.debug=true -Djava.security.krb5.conf=/etc/krb5.conf -Xmx256M -Xms128M" \
bin/kafka-acls.sh --authorizer-properties \
zookeeper.connect=zookeeper-server-01.eigenroute.com:2181,zookeeper-server-02.eigenroute.com:2181,zookeeper-server-03.eigenroute.com:2181/apps/kafka-cluster-demo \
--add --allow-principal User:producer1 --producer --topic another-test-topic
...
Current ACLs for resource `Topic:another-test-topic`:
User:producer1 has Allow permission for operations: Describe from hosts: *
User:producer1 has Allow permission for operations: Write from hosts: *
但是,我的制作人无法写这个主题:
KAFA_HEAP_OPTS="-Djava.security.krb5.conf=/etc/krb5.conf -Dsun.security.krb5.debug=true" \
bin/kafka-console-producer.sh \
--broker-list server-01.eigenroute.com:9092,server-02.eigenroute.com:9092 \
--topic another-test-topic --producer.config config/sasl-producer.properties
>this is a test message
[2018-01-07 21:16:02,650] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 1 : {another-test-topic=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
此主题的ZooKeeper节点上的ACL为:
[zk: zookeeper-server-03.eigenroute.com:2181(CONNECTED) 8] getAcl /apps/kafka-cluster-demo/brokers/topics/another-test-topic
'world,'anyone
: r
'sasl,'kafka/server-02.eigenroute.com@EIGENROUTE.COM
: cdrwa
我觉得奇怪......不应该 kafka/server-01.eigenroute.com@EIGENROUTE.COM
(代理1的Kerberos主体)与 kafka/server-02.eigenroute.com@EIGENROUTE.COM
(代理2的Kerberos主体)具有相同的权限?
有人可以建议 生产环境 者为什么看不到它被授权写的主题?
更新:以下是对@Vladimir Nabokov提供的答案中的问题的回答:
- 我在任一代理节点上都没有看到分区主题:
kafka @ server-02:/ var / log / kafka $ ls -alhtr总计124K -rw-r - r-- 1 kafka kafka 0 Jan 7 23:27 .lock -rw-r - r-- 1 kafka kafka 0 Jan 7 23:27 cleaner-offset-checkpoint -rw-r - r-- 1 kafka kafka 54 Jan 7 23:27 meta.properties drwxr-xr-x 7 root root 4.0K Jan 9 06:25 .. drwxr -xr-x 2 kafka kafka 4.0K 1月18日05:30 __consumer_offsets-29 ... drwxr-xr-x 2 kafka kafka 4.0K 1月18日05:30 __consumer_offsets-1 -rw-r - r-- 1 kafka kafka 600 Jan 18 05:56 replication-offset-checkpoint -rw-r - r-- 1 kafka kafka 600 Jan 18 05:56 recovery-point-offset-checkpoint -rw-r - r-- 1 kafka kafka 4 Jan 18 05:56 log-start-offset-checkpoint drwxr-xr-x 27 kafka kafka 4.0K 1月18日05:56 .
和
kafka@server-01:/var/log/kafka$ ls -alhtr
total 124K
-rw-r--r-- 1 kafka kafka 0 Jan 7 23:26 .lock
-rw-r--r-- 1 kafka kafka 0 Jan 7 23:26 cleaner-offset-checkpoint
-rw-r--r-- 1 kafka kafka 54 Jan 7 23:26 meta.properties
drwxr-xr-x 7 root root 4.0K Jan 17 06:25 ..
drwxr-xr-x 2 kafka kafka 4.0K Jan 18 05:30 __consumer_offsets-0
...
drwxr-xr-x 2 kafka kafka 4.0K Jan 18 05:30 __consumer_offsets-32
-rw-r--r-- 1 kafka kafka 600 Jan 18 05:58 recovery-point-offset-checkpoint
-rw-r--r-- 1 kafka kafka 4 Jan 18 05:58 log-start-offset-checkpoint
-rw-r--r-- 1 kafka kafka 600 Jan 18 05:59 replication-offset-checkpoint
drwxr-xr-x 27 kafka kafka 4.0K Jan 18 05:59 .
- 用户
kafka
,即运行kafka服务器的用户,是两个代理上/var/log/kafka/
目录的所有者:
kafka @ server-02:〜/ kafka_2.11-1.0.0 / confkafka @ server-01:/ var / log $ ll / var / log | grep kafka drwxr-xr-x 27 kafka kafka 4096 1月18日05:49 kafka ig $ ll / var / log | grep kafka
- 看起来telnet对两个经纪人都有效:
sjamal-> telnet server-01.eigenroute.com 9092试用54.175.56.39 ...连接到server-01.eigenroute.com . 逃脱角色是'^]' . ^ CConnection由外国主人关闭 . [〜/ projects / microservices / kafka-tutorial / kafka_2.11-1.0.0] sjamal-> telnet server-02.eigenroute.com 9092试用18.221.32.34 ...连接到server-02.eigenroute.com . 逃脱角色是'^]' . ^ CConnection由外国主人关闭 .
- 没必要 - 他们可以看到对方:
kafka @ server-02:〜/ kafka_2.11-1.0.0 / config $ host server-01.eigenroute.com server-01.eigenroute.com的地址为54.175.56.39 kafka @ server-01:/ var / log $ host server-02.eigenroute.com server-02.eigenroute.com的地址为18.221.32.34
- 我试了这个 . 消费者没有收到任何消息:
[2018-01-18 00:45:31,931] WARN [Consumer clientId = consumer-1,groupId = console-consumer-95024]获取具有相关ID 7022的元数据时出错:(org . apache.kafka.clients.NetworkClient)[2018-01-18 00:45:32,063] WARN [Consumer clientId = consumer-1,groupId = console-consumer-95024]获取相关ID为7024的元数据时出错:{another-test -topic = UNKNOWN_TOPIC_OR_PARTITION}(org.apache.kafka.clients.NetworkClient)[2018-01-18 00:45:32,194] WARN [Consumer clientId = consumer-1,groupId = console-consumer-95024]获取元数据时出错correlation id 7025:(org.apache.kafka.clients.NetworkClient)[2018-01-18 00:45:32,327] WARN [Consumer clientId = consumer-1,groupId = console-consumer -95024]获取具有相关ID 7026的元数据时出错:(org.apache.kafka.clients.NetworkClient)
drwxr-xr-x 27 kafka kafka 4096 Jan 18 05:44 kafka
抱歉格式错误 - 我已粘贴代码并点击“代码”按钮,但它不是格式化为代码,我不知道为什么 .
更新#2:回应弗拉基米尔·纳博科夫在回答中的评论,我正在粘贴我正在使用的制作人和消费者配置和命令:
// sasl-producer.properties
bootstrap.servers=server-01.eigenroute.com:9092
compression.type=none
security.protocol=SASL_PLAINTEXT
sasl.mechanism=GSSAPI
sasl.kerberos.service.name=kafka
sasl.jaas.config=com.sun.security.auth.module.Krb5LoginModule required \
useKeyTab=true \
storeKey=true \
keyTab="/path/to/producer1.whatever.keytab" \
principal="producer1/whatever@EIGENROUTE.COM";
// sasl-consumer.properties
bootstrap.servers=server-01.eigenroute.com:9092
security.protocol=SASL_PLAINTEXT
sasl.mechanism=GSSAPI
sasl.kerberos.service.name=kafka
sasl.jaas.config=com.sun.security.auth.module.Krb5LoginModule required \
useKeyTab=true \
storeKey=true \
keyTab="/path/to/consumer1.whatever.keytab" \
principal="consumer1/whatever@EIGENROUTE.COM";
# producer command
KAFA_HEAP_OPTS="-Djava.security.krb5.conf=/etc/krb5.conf -Dsun.security.krb5.debug=true" bin/kafka-console-producer.sh --broker-list server-01.eigenroute.com:9092,server-02.eigenroute.com:9092 --topic another-test-topic --producer.config config/sasl-producer.properties
# consumer command
KAFA_HEAP_OPTS="-Djava.security.krb5.conf=/etc/krb5.conf -Dsun.security.krb5.debug=true" bin/kafka-console-consumer.sh --bootstrap-server server-01.eigenroute.com:9092,server-02.eigenroute.com:9092 --topic another-test-topic --consumer.config config/sasl-consumer.properties --from-beginning
2 回答
这个错误:
没有义务意味着你没有写到主题 .
这只是意味着,这个话题是“一个新的” .
1)检查,可能是数据已写入数据目录,可以直观地看到cd data_dir / topic / partition,查找增长的文件 . (查看所有分区中的两台服务器)
2)检查,可能是data_dir没有为你的kafka用户写的权限?
3)从 生产环境 机器'telnet kafka_host kafka_port'检查,可能是 生产环境 者在网络中看不到你的kafka服务器
4)在 生产环境 者和kafka经纪人上,输入/ etc / hosts并将IP映射到所有3台机器的主机名 . 他们不仅需要知道彼此IP,但要注意主机名到IP映射(DNS服务是另一种选择)
5)与消费者联系并尝试消费您的主题 .
好吧,我不知道这是否有资格作为答案,但它确实有效 . 解决方案是在Broker 1服务器(原始代理)上创建新主题(“a-test-topic2”),而不是Broker 2服务器(代理添加第二个) .
现在,如果我将Broker 1脱机,那么我可以在Broker 2服务器上创建一个主题(“a-test-topic3”) - 但当然副本号必须是一个,所以我将无法拥有经纪人1上的任何复制品(复制品?) .
接下来,我将Broker 1重新启动,并尝试在Broker 2服务器上创建另一个主题(“a-test-topic4”),副本数为2,并且......它可以工作!对于这个新主题的所有分区,Isr为2,1或1,2,leader为1或2 .
嗯...所以让我们尝试在Broker 1服务器上创建一个主题(“a-test-topic5”) . 怎么了?我得到了我原来的同样的问题 . 新主题分区没有领导者,也没有Isr . 但是我找到了解决这个问题的方法 - 在Broker 1运行的情况下,我停止了Broker 2,然后再次启动了Broker 2,并且瞧了一下 - 对于所有分区,这个主题最终会得到1或2的领导者和1,2或者Isrs 2,1 .
所以我想只能在激活的第一个代理上创建新主题,否则必须重新启动所有其他代理?