kafka 0.10.0.0 配置SASL_PLAINTEXT

まず、kafka-jaas 構成ファイルを追加し、server.properties を変更し、起動スクリプト sh を変更します。

1. Security.inter.broker.protocol=SASL_PLAINTEXT を設定する必要があります

この項目は2.2では設定されておらず、0.11でも設定されていなかったことが分かりました。このバージョンでは設定なしではkafkaを起動できないため、設定を追加します

security.inter.broker.protocol=SASL_PLAINTEXT

listeners=SASL_PLAINTEXT://0.0.0.0:10092
sasl.enabled.mechanisms=PLAIN
sasl.mechanism.inter.broker.protocol=PLAIN
security.inter.broker.protocol=SASL_PLAINTEXT

2、org.apache.kafka.common.KafkaException: Zookeeper JAAS ログイン コンテキスト 'クライアント' のロード中に例外が発生しました

警告 SASL 構成が失敗しました: javax.security.auth.login.LoginException: 指定された JAAS 構成ファイルに「Client」という名前の JAAS 構成セクションが見つかりませんでした: 0.11 のzookper ログの
「./bin/…/config/kafka_server_jaas.conf」
。Zookeeper サーバーが許可している場合、SASL 認証なしで Zookeeper サーバーへの接続を続行します。(org.apache.zookeeper.ClientCnxn)
にもこのプロンプトが表示されますが、Kafka の起動には影響しません。1.10 ではエラーが報告され、Kafka は実行できません直接始めました。

解決策: Kafka と Zookeeper の間でユーザー名とパスワードを設定する必要があります。

  • (1) Zookeeper は jaas 設定ファイルを追加します
Server {
    org.apache.zookeeper.server.auth.DigestLoginModule required
    username="kafka"
    password="kafka"
    user_kafka="kafka";
};
  • (2)zookeeper-server-start.sh
export KAFKA_OPTS="-Djava.security.auth.login.config=file:$base_dir/../config/zk_server_jaas.conf -Dzookeeper.authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationP
rovider -Dzookeeper.requireClientAuthScheme=sasl"
  • (3)kafka_server_jaas.conf
KafkaServer {
    org.apache.kafka.common.security.plain.PlainLoginModule required
    username="admin"
    password="admin"
    user_admin="admin";
};
Client {
    org.apache.zookeeper.server.auth.DigestLoginModule required
    username="kafka"
    password="kafka";
};

: Zookeeper サーバーと Kafka クライアントの両方で org.apache.zookeeper.server.auth.DigestLoginModule を使用する必要があります必須

理由:zookeeper は SASL Plain をサポートしていませんが、DigestMD5 はかなり似ています。

3、java.io.IOException: 構成エラー: 行: 期待される [オプションキー]

KafkaServer 構成の末尾にセミコロンはありません

ここに画像の説明を挿入

やっと:

KafkaServer {
    org.apache.kafka.common.security.plain.PlainLoginModule required
    username="admin"
    password="admin"
    user_admin="admin";
};
Client {
    org.apache.zookeeper.server.auth.DigestLoginModule required
    username="kafka"
    password="kafka";
};

4、org.apache.zookeeper.KeeperException$InvalidACLException: KeeperErrorCode = /brokers/ids の無効な ACL

server.propertiesに以下の設定を追加するため、zookeeper.set.acl=trueがエラーになるためネットで検索した人がいたため、この部分にアノテーションを付けました

#super.users=User:kafka
#authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
#zookeeper.set.acl=true

5、org.I0Itec.zkclient.Exception.ZkException: org.apache.zookeeper.KeeperException$InvalidACLException: KeeperErrorCode = InvalidACL

上記のエラーと似ていますが、インターネットで情報を検索したところ、Zookeeper ログ例外の原因がわかりました。これはエラー レポートではなく、ユーザー レベルの KeeperException です。処理されない Kafka は無視して、インストール後に初めて起動することができます。Zookeeper ログ エラー: KeeperErrorCode = NoNode for /config/topics/test。kafka はこのパスへのアクセスを要求していますが、このパスはまだ存在しないため、zookeeper はこのエラーをスローします。Kafka はこのトピックを作成し、zookeeper のトピックに対応するパスにアクセスします。zookeeper のログでは、/config/topics に対してエラー NodeExists がスローされ (kafka はすでにトピックを作成しています)、パスはすでに存在します。要約すると、これらのエラーは通常のログ情報であり、無視して問題ありません。

https://stackoverflow.com/questions/43559328/got-user-level-keeperException-when-processing

無視して続行したところ、トピックは正常に作成されたのですが、再度プロデューサーを作成したところ、以下の問題が発生しました。

6、警告 相関 ID 38 のメタデータを取得中にエラーが発生しました: {1001=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

エラー内容: リーダーが利用できません
理由分析: 多くのトピックが削除されており、リーダーの選挙が進行中であることが原因です
解決策としては、kafka-topics スクリプトを使用してリーダー情報を確認し、リーダーの生存を確認してください。ブローカーを再起動して問題を解決してください
kafka の使い方 - topic スクリプトはリーダー情報をチェックしますが、ログを見るとリーダーの選出に失敗したログが見つかります。再起動してみてください
飼育員のログで次のことが見つかりました

7、エラー sasl の AuthenticationProvider がありません (org.apache.zookeeper.server.PrepRequestProcessor)

Zookeeper-server-start.sh で設定します:
-Dzookeeper.authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
-Dzookeeper.requireClientAuthScheme=sasl

ついに:

export KAFKA_OPTS="-Djava.security.auth.login.config=file:$base_dir/../config/zk_server_jaas.conf -Dzookeeper.authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider -Dzookeeper.requireClientAuthScheme=sasl"

エラーが消えてリーダーが正常に選択できるようになりました

8、消費者財産は認められたオプションではありません

[root@aiot bin]# ./kafka-console-consumer-saal.sh --bootstrap-server 10.221.13.102:10092 --topic 1001 --consumer-property security.protocol=SASL_PLAINTEXT --consumer-property sasl.mechanism =プレーン

このコマンドは 2.2 で使用されています。現在のバージョンではサポートされていない必要があります。公式の対応するバージョンを見つけてください。

公式ドキュメント:
https://kafka.apache.org/0100/documentation.html#quickstart_consume

ステップ 5: コンシューマを開始するKafka には、標準出力にメッセージをダンプするコマンド ライン コンシューマもあります。> bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning これはメッセージ
です
これは別のメッセージです

上記の各コマンドを別の端末で実行している場合は、プロデューサー端末にメッセージを入力し、コンシューマー端末にメッセージが表示されることを確認できるはずです。すべてのコマンド ライン ツールには追加のオプションがあります。引数なしでコマンドを実行すると、より詳細に文書化された使用法情報が表示されます。

パラメータを指定せずに .sh を実行すると、この sh でサポートされているパラメータを表示できます。

[root@aiot bin]# ./kafka-console-consumer.sh 
The console consumer is a tool that reads data from Kafka and outputs it to standard output.
Option                                  Description                            
------                                  -----------                            
--blacklist <blacklist>                 Blacklist of topics to exclude from    
                                          consumption.                         
--bootstrap-server <server to connect                                          
  to>                                                                          
--consumer.config <config file>         Consumer config properties file.       
--csv-reporter-enabled                  If set, the CSV metrics reporter will  
                                          be enabled                           
--delete-consumer-offsets               If specified, the consumer path in     
                                          zookeeper is deleted when starting up
--enable-systest-events                 Log lifecycle events of the consumer   
                                          in addition to logging consumed      
                                          messages. (This is specific for      
                                          system tests.)                       
--formatter <class>                     The name of a class to use for         
                                          formatting kafka messages for        
                                          display. (default: kafka.tools.      
                                          DefaultMessageFormatter)             
--from-beginning                        If the consumer does not already have  
                                          an established offset to consume     
                                          from, start with the earliest        
                                          message present in the log rather    
                                          than the latest message.             
--key-deserializer <deserializer for                                           
  key>                                                                         
--max-messages <Integer: num_messages>  The maximum number of messages to      
                                          consume before exiting. If not set,  
                                          consumption is continual.            
--metrics-dir <metrics directory>       If csv-reporter-enable is set, and     
                                          this parameter isset, the csv        
                                          metrics will be outputed here        
--new-consumer                          Use the new consumer implementation.   
--property <prop>                       The properties to initialize the       
                                          message formatter.                   
--skip-message-on-error                 If there is an error when processing a 
                                          message, skip it instead of halt.    
--timeout-ms <Integer: timeout_ms>      If specified, exit if no message is    
                                          available for consumption for the    
                                          specified interval.                  
--topic <topic>                         The topic id to consume on.            
--value-deserializer <deserializer for                                         
  values>                                                                      
--whitelist <whitelist>                 Whitelist of topics to include for     
                                          consumption.                         
--zookeeper <urls>                      REQUIRED: The connection string for    
                                          the zookeeper connection in the form 
                                          host:port. Multiple URLS can be      
                                          given to allow fail-over.    

当然のことですが、サポートされていませんが、--consumer.config というパラメーターがあるので、consumer.properties を変更します。

[root@at config]# cat consumer.properties 
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
# 
#    http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# see kafka.consumer.ConsumerConfig for more details

# Zookeeper connection string
# comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
zookeeper.connect=127.0.0.1:10181

# timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=6000

#consumer group id
group.id=test-consumer-group

#consumer timeout
#consumer.timeout.ms=5000

security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN

コマンドは次のようになります:
./kafka-console-consumer-saal.sh --zookeeper localhost:10181 --topic 1001 --consumer.config Consumer.properties

戻り値: ZK にブローカーが見つかりません。

9、ZKにはブローカーが見つかりません。

サイト上の人文:
--zookeeper フラグを付けずにコンシューマーを試してみてはいかがでしょうか。0.10.2 の新しいコンシューマを使用している場合は、必要ありません。--zookeeper を指定すると、古い 0.8 コンシューマを使用しようとします。

翻訳: --zookeeper フラグを付けずにコンシューマーを使用してみてはいかがでしょうか? 0.10.2 で新しいコンシューマを使用している場合は必要ありません。--zookeeper が指定されている場合は、古い 0.8 コンシューマを使用しようとします。

–zookeeper を直接削除することは間違いなく不可能です。はいREQUIRED、引き続き kafka-console-consumer.sh を確認します。パラメーターには --new-consumer があるため、
次のように変更します。

/kafka-console-consumer-saal.sh --bootstrap-server 127.0.0.1:10092 --topic 1001 --consumer.config …/config/consumer.properties --new-consumer

最後に、プロデューサーのメッセージを正常に受信できます。

公式ドキュメント: https://kafka.apachecn.org/documentation.html
ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/small_tu/article/details/109534634