簡體   English   中英

多代理,多服務器集群中的Kafka生產者無法寫入新創建的主題

[英]Kafka producer in a multi-broker, multi-server cluster cannot write to newly created topic

我有一個帶有2個代理的Kafka集群,每個代理都在自己的(AWS)服務器上(我使用這里的intstructions設置集群)。 我正在使用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具有相同的權限(經紀人的Kerberos本金2)?

有人可以建議生產者為什么看不到它被授權寫的主題?

更新:以下是對@Vladimir Nabokov提供的答案中的問題的回答:

  1. 我在任一代理節點上都沒有看到分區主題:

    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 .
  1. 用戶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

  2. 對於兩個經紀人來說,看起來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由外國主人關閉。

  3. 沒必要 - 他們可以看到對方:

    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

  4. 我試過這個。 消費者不會收到任何消息:

    [2018-01-18 00:45:31,931] WARN [Consumer clientId = consumer-1,groupId = console-consumer-95024]獲取具有相關ID 7022的元數據時出錯:{another-test-topic = UNKNOWN_TOPIC_OR_PARTITION}(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:{another-test-topic = UNKNOWN_TOPIC_OR_PARTITION}(org.apache.kafka.clients.NetworkClient)[2018-01-18 00:45:32,327] WARN [Consumer clientId = consumer-1,groupId = console-consumer -95024]獲取具有相關ID 7026的元數據時出錯:{another-test-topic = UNKNOWN_TOPIC_OR_PARTITION}(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

這個錯誤:

WARN [Producer clientId = console-producer]獲取關聯ID為1的元數據時出錯:{another-test-topic = UNKNOWN_TOPIC_OR_PARTITION}(org.apache.kafka.clients.NetworkClient)

沒有義務意味着你沒有寫到主題。

這只是意味着,這個話題是“一個新的”。

1)檢查,可能是已經寫入數據的數據dir,可以直觀地看到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和Isrs 1,2或者2,1。

所以我想只能在激活的第一個代理上創建新主題,否則必須重新啟動所有其他代理?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM