kafka 0.10.0.0 配置SASL_PLAINTEXT

2024-01-11 05:08

本文主要是介绍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: Exception while loading Zookeeper JAAS login context ‘Client’

0.11 中zookper的日志中
WARN SASL configuration failed: javax.security.auth.login.LoginException: No JAAS configuration section named ‘Client’ was found in specified JAAS configuration file: ‘./bin/…/config/kafka_server_jaas.conf’. Will continue connection to Zookeep
er server without SASL authentication, if Zookeeper server allows it. (org.apache.zookeeper.ClientCnxn)
也有这个提示,但是不影响kafka启动,1.10报告的是错误,直接kafka启动不起来

解决方法: 需要配置kafka和zookeeper之间也使用用户名密码
  • (1)zookeeper 增加jaas配置文件
Server {org.apache.zookeeper.server.auth.DigestLoginModule requiredusername="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 requiredusername="admin"password="admin"user_admin="admin";
};
Client {org.apache.zookeeper.server.auth.DigestLoginModule requiredusername="kafka"password="kafka";
};

请注意:zookeeper的server和kafka的client 都应该用 org.apache.zookeeper.server.auth.DigestLoginModule required

因为:zookeeper does not support SASL Plain, but DigestMD5 is pretty similar.

3、java.io.IOException: Configuration Error: Line : expected [option key]

KafkaServer 配置的 最后没家分号

在这里插入图片描述

最后:

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

4、org.apache.zookeeper.KeeperException$InvalidACLException: KeeperErrorCode = InvalidACL for /brokers/ids

因为 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日志异常原因—这不是一个报错故障,只是一个user-level KeeperException。可以忽略不做处理的kafka安装好后,第一次启动。zookeeper日志Error:KeeperErrorCode = NoNode for /config/topics/test,是因为kafka请求访问这个路径,但是这个路径还不存在,zookeeper就抛了这个error。kafka会创建这个topic,然后访问zookeeper里topic对应的路径,zookeeper日志抛出error NodeExists for /config/topics(kafka已经把topic创建好了),路径已经存在了。综上所述,这些error是正常的日志信息,可以忽略。

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

所以忽略了,继续进行,创建了topic成功了,再建立生产者的时候,出现了下面的问题,

6、WARN Error while fetching metadata with correlation id 38 : {1001=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

报错内容:leader不可用
原因分析:原因很多 topic正在被删除 正在进行leader选举
给出的解决方案是:使用kafka-topics脚本检查leader信息进而检查broker的存活情况 尝试重启解决问题
没找到怎么使用kafka-topics脚本检查leader信息,但是看日志,发现了选leader失败的日志。尝试重启
在zookeeper的日志中,发现

7、ERROR Missing AuthenticationProvider for sasl (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"

错误消失,可以成功选择leader

8、consumer-property is not a recognized option

[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=PLAIN

这个命令是在2.2中用的,肯定是当前版本不支持,找到官方对应版本

官方文档:
https://kafka.apache.org/0100/documentation.html#quickstart_consume

Step 5: Start a consumerKafka also has a command line consumer that will dump out messages to standard output.> bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
This is a message
This is another message

If you have each of the above commands running in a different terminal then you should now be able to type messages into the producer terminal and see them appear in the consumer terminal.All of the command line tools have additional options; running the command with no arguments will display usage information documenting them in more detail.

可以通过执行.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=5000security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN

命令变为:
./kafka-console-consumer-saal.sh --zookeeper localhost:10181 --topic 1001 --consumer.config consumer.properties

返回:No brokers found in ZK.

9、No brokers found in ZK.

看到网上有人说:
Can you try the consumer without --zookeeper flag. If you are using the new consumer in 0.10.2 it’s not needed. If you provide --zookeeper then it tries to use the old 0.8 consumer.

翻译:您可以在没有–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
在这里插入图片描述

这篇关于kafka 0.10.0.0 配置SASL_PLAINTEXT的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/593254

相关文章

Zookeeper安装和配置说明

一、Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式。 ■ 单机模式:Zookeeper只运行在一台服务器上,适合测试环境; ■ 伪集群模式:就是在一台物理机上运行多个Zookeeper 实例; ■ 集群模式:Zookeeper运行于一个集群上,适合生产环境,这个计算机集群被称为一个“集合体”(ensemble) Zookeeper通过复制来实现

CentOS7安装配置mysql5.7 tar免安装版

一、CentOS7.4系统自带mariadb # 查看系统自带的Mariadb[root@localhost~]# rpm -qa|grep mariadbmariadb-libs-5.5.44-2.el7.centos.x86_64# 卸载系统自带的Mariadb[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7

hadoop开启回收站配置

开启回收站功能,可以将删除的文件在不超时的情况下,恢复原数据,起到防止误删除、备份等作用。 开启回收站功能参数说明 (1)默认值fs.trash.interval = 0,0表示禁用回收站;其他值表示设置文件的存活时间。 (2)默认值fs.trash.checkpoint.interval = 0,检查回收站的间隔时间。如果该值为0,则该值设置和fs.trash.interval的参数值相等。

NameNode内存生产配置

Hadoop2.x 系列,配置 NameNode 内存 NameNode 内存默认 2000m ,如果服务器内存 4G , NameNode 内存可以配置 3g 。在 hadoop-env.sh 文件中配置如下。 HADOOP_NAMENODE_OPTS=-Xmx3072m Hadoop3.x 系列,配置 Nam

wolfSSL参数设置或配置项解释

1. wolfCrypt Only 解释:wolfCrypt是一个开源的、轻量级的、可移植的加密库,支持多种加密算法和协议。选择“wolfCrypt Only”意味着系统或应用将仅使用wolfCrypt库进行加密操作,而不依赖其他加密库。 2. DTLS Support 解释:DTLS(Datagram Transport Layer Security)是一种基于UDP的安全协议,提供类似于

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

搭建Kafka+zookeeper集群调度

前言 硬件环境 172.18.0.5        kafkazk1        Kafka+zookeeper                Kafka Broker集群 172.18.0.6        kafkazk2        Kafka+zookeeper                Kafka Broker集群 172.18.0.7        kafkazk3

沁恒CH32在MounRiver Studio上环境配置以及使用详细教程

目录 1.  RISC-V简介 2.  CPU架构现状 3.  MounRiver Studio软件下载 4.  MounRiver Studio软件安装 5.  MounRiver Studio软件介绍 6.  创建工程 7.  编译代码 1.  RISC-V简介         RISC就是精简指令集计算机(Reduced Instruction SetCom

log4j2相关配置说明以及${sys:catalina.home}应用

${sys:catalina.home} 等价于 System.getProperty("catalina.home") 就是Tomcat的根目录:  C:\apache-tomcat-7.0.77 <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" /> 2017-08-10

DM8数据库安装后配置

1 前言 在上篇文章中,我们已经成功将库装好。在安装完成后,为了能够更好地满足应用需求和保障系统的安全稳定运行,通常需要进行一些基本的配置。下面是一些常见的配置项: 数据库服务注册:默认包含14个功能模块,将这些模块注册成服务后,可以更好的启动和管理这些功能;基本的实例参数配置:契合应用场景和发挥系统的最大性能;备份:有备无患;… 2 注册实例服务 注册了实例服务后,可以使用系统服务管理,