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

相关文章

SQL Server配置管理器无法打开的四种解决方法

《SQLServer配置管理器无法打开的四种解决方法》本文总结了SQLServer配置管理器无法打开的四种解决方法,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录方法一:桌面图标进入方法二:运行窗口进入检查版本号对照表php方法三:查找文件路径方法四:检查 S

Linux中SSH服务配置的全面指南

《Linux中SSH服务配置的全面指南》作为网络安全工程师,SSH(SecureShell)服务的安全配置是我们日常工作中不可忽视的重要环节,本文将从基础配置到高级安全加固,全面解析SSH服务的各项参... 目录概述基础配置详解端口与监听设置主机密钥配置认证机制强化禁用密码认证禁止root直接登录实现双因素

嵌入式数据库SQLite 3配置使用讲解

《嵌入式数据库SQLite3配置使用讲解》本文强调嵌入式项目中SQLite3数据库的重要性,因其零配置、轻量级、跨平台及事务处理特性,可保障数据溯源与责任明确,详细讲解安装配置、基础语法及SQLit... 目录0、惨痛教训1、SQLite3环境配置(1)、下载安装SQLite库(2)、解压下载的文件(3)、

Linux如何快速检查服务器的硬件配置和性能指标

《Linux如何快速检查服务器的硬件配置和性能指标》在运维和开发工作中,我们经常需要快速检查Linux服务器的硬件配置和性能指标,本文将以CentOS为例,介绍如何通过命令行快速获取这些关键信息,... 目录引言一、查询CPU核心数编程(几C?)1. 使用 nproc(最简单)2. 使用 lscpu(详细信

Nginx 重写与重定向配置方法

《Nginx重写与重定向配置方法》Nginx重写与重定向区别:重写修改路径(客户端无感知),重定向跳转新URL(客户端感知),try_files检查文件/目录存在性,return301直接返回永久重... 目录一.try_files指令二.return指令三.rewrite指令区分重写与重定向重写: 请求

Nginx 配置跨域的实现及常见问题解决

《Nginx配置跨域的实现及常见问题解决》本文主要介绍了Nginx配置跨域的实现及常见问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来... 目录1. 跨域1.1 同源策略1.2 跨域资源共享(CORS)2. Nginx 配置跨域的场景2.1

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

MySQL MCP 服务器安装配置最佳实践

《MySQLMCP服务器安装配置最佳实践》本文介绍MySQLMCP服务器的安装配置方法,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下... 目录mysql MCP 服务器安装配置指南简介功能特点安装方法数据库配置使用MCP Inspector进行调试开发指

Redis Cluster模式配置

《RedisCluster模式配置》:本文主要介绍RedisCluster模式配置,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录分片 一、分片的本质与核心价值二、分片实现方案对比 ‌三、分片算法详解1. ‌范围分片(顺序分片)‌2. ‌哈希分片3. ‌虚

SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志

《SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志》在SpringBoot项目中,使用logback-spring.xml配置屏蔽特定路径的日志有两种常用方式,文中的... 目录方案一:基础配置(直接关闭目标路径日志)方案二:结合 Spring Profile 按环境屏蔽关