kafka添加安全验证配置
spring kafka 添加安全验证配置
综合考虑性能影响、管理成本、安全等级要求,接入便利程度。 鉴权采用SASL+PLAINTEXT 方式。每个集群会分配统一的访问账号及密码用于客户端访问。
服务端配置:
1. config 目录添加kafka_server_jaas.conf 配置文件, 内容:
KafkaServer {org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin"
password="7f8d9dsf789ds7ffsdfdsfu9"
user_admin="7f8d9dsf789ds7ffsdfdsfu9"
user_alice="xjfkddjfdssifds";
};
2. kafka-run-class.sh 添加
KAFKA_OPTS="$KAFKA_OPTS -Djava.security.auth.login.config=/home/finance/App/kafka_2.12-2.5.1/config/kafka_server_jaas.conf"
3. config/server.properties
添加
security.inter.broker.protocol=SASL_PLAINTEXTsasl.mechanism.inter.broker.protocol=PLAINsasl.enabled.mechanisms=PLAINlistener, advertised.listeners 添加对应SASL_PLAINTEXT 监听器listeners=SASL_PLAINTEXT://10.193.196.112:9092advertised.listeners=SASL_PLAINTEXT://10.193.196.112:9092
客户端接入改造
就是在java程序中将安全参数配置进来
生产者、消费者属性配置加入一下配置
props.put("sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=alice password=alice;");
props.put("security.protocol", "SASL_PLAINTEXT");
props.put("sasl.mechanism", "PLAIN");
springboot 高版本估计有支持在properties文件中直接配置,此处没有验证。
完整配置示例
此方法,可以用KafkaProperties 获取properties配置文件中的参数后,再往里面添加新的参数
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.EnableKafka;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.config.KafkaListenerContainerFactory;
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;import java.util.Map;/*** kafka配置*/
@Configuration
@EnableKafka
public class KafkaProducerConfig {@Autowiredprivate KafkaProperties kafkaProperties;/*** 消费者配置*/@Beanpublic KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() {ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();Map<String, Object> props = kafkaProperties.buildConsumerProperties();props.put("sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=user1 password=pass1;");props.put("security.protocol", "SASL_PLAINTEXT");props.put("sasl.mechanism", "PLAIN");factory.setConsumerFactory(new DefaultKafkaConsumerFactory<>(props));factory.setConcurrency(2);factory.getContainerProperties().setPollTimeout(1500);return factory;}/*** 生产者配置*/@Beanpublic KafkaTemplate<String, String> kafkaTemplate() {Map<String, Object> props = kafkaProperties.buildProducerProperties();props.put("sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=user1 password=pass1;");props.put("security.protocol", "SASL_PLAINTEXT");props.put("sasl.mechanism", "PLAIN");return new KafkaTemplate<>(new DefaultKafkaProducerFactory<>(props));}}
kafka添加安全验证配置相关推荐
- Kafka的安装与配置
一 jar包方式安装Kafka jar包下载地址:https://kafka.apache.org/downloads下载 1.配置java环境 1.1.上传jdk-8u341-linux-x6 ...
- 美多商城之用户中心(添加和验证邮箱)
二.添加和验证邮箱 2.1 添加邮箱后端逻辑 1. 添加邮箱接口设计和定义 1.请求方式 选项 方案 请求方法 PUT 请求地址 /emails/ # 添加邮箱url(r'^emails/$', vi ...
- 【kafka】Kafka中的动态配置源码分析
1.概述 2.源码分析 Broker启动加载动态配置 KafkaServer.startup 启动加载动态配置总流程 2.1 动态配置初始化 config.dynamicConfig.initiali ...
- 为MongoDB添加身份验证
MongoDB 默认没有开户身份验证,除非不开放外网访问,否则这种模式极不安全,现纪录添加身份验证步骤如下: 配置创建用户的时候,需要关闭: #security: ##副本集之间通信用到的认证文件 # ...
- aws rds监控慢sql_AWS RDS SQL Server中的初始Windows身份验证配置
aws rds监控慢sql In this article, we will be exploring the process of enabling Windows authentication i ...
- aws rds监控慢sql_AWS RDS SQL Server中的高级Windows身份验证配置
aws rds监控慢sql This article will cover advanced configurations for Windows Authentication in AWS RDS ...
- 添加网站验证,让搜索引擎收录你的网站
hexo buttferfly网站添加网站验证 欢迎访问个人博客网站:http://melony.fun/ 个人博客网站框架是基于hexo 主题:butter-fly 主题作者:JerryC 我所使用 ...
- 思科-实验10:路由器接口 PPP 协议封装和 PAP、CHAP 验证配置
[实验内容] (1) 选择两台C2811 路由器,分别关闭电源后添加WIC-2T 模块,添加位置为插槽0/接口适配器0(提示:在4个插槽中右下角的位置).开启电源之后使用Serial 电缆将两台路由器 ...
- Subversion的安装部署与用户验证配置
注:本例采取subversion+apache的模式 一:所需软件包下载 编译svn需要依赖sqlite库,RHEL5自带的rpm包版本太低,编译不能通过. #wget http://www.sqli ...
最新文章
- Linux中bashrc河bash_profile
- 京东主图怎么保存原图_京东自营怎么做?详解京东平台操作方法
- 我和大师Jeffrey Richter相约@北京
- AI现在能教你画画了
- Android Studio快捷键——编辑篇
- css 商城 两列_CSS 居中?来一探究竟
- ***redis linux 命令使用总结
- 一个时代的落幕!继苹果、火狐、Linux Lite之后,微软也放弃Flash
- python 随机森林分类 代码
- 光谱分辨率单位_【ENVI入门系列】16.基本光谱分析
- 2020校招互联网公司Offer白菜价!看完TM我酸了
- 英语在计算机上比汉语有优势吗,英语和汉语分别有什么优缺点?
- 门店怎么申请共享充电宝
- 产品狗的Python之路(1):按照行数将excel表格拆分成多个
- 【小黑屋】——总结反馈
- Coin-row problem
- 315再曝数据安全问题,短信钓鱼、App窃密等成焦点
- fread()和fwrite()函数分析
- 卸载流氓软件最后的奥义
- 国产替代AM26LS31, AM26LS32A, AM26C31, AM26C32
热门文章
- 使用网络模拟器 Packet Tracer和交换机的端口配置与管理及Telnet远程登陆配置
- 台式WIN7和os x yosemite 10.10.1懒人版双系统安装教程
- POJ1723士兵站队问题
- Mac安装并配置Git+SourceTree使用
- 「大冰撸设计模式」java 创建型模式之单例模式
- 小论电阻1(电阻的参数)
- 201224-MacOS使用Mounty非安全退出NFTS后磁盘无法加载
- Mac菜鸟必备小工具- Mounty 原生支持 NTFS 读写驱动应用
- oracle11g_R2 exp imp 用法
- mac安装虚拟机配置win10系统