首页 > 系统相关 >Centos7 Kafka+zookeeper SASL认证实践

Centos7 Kafka+zookeeper SASL认证实践

时间:2023-02-25 18:31:53浏览次数:64  
标签:zookeeper kafka Centos7 conf sasl SASL security password config

一、概述

上回已经完成kafka+zookeeper的基础功能的实现,但是因为默认不认证存在很大的安全风险,这次完成SASL_PLAINTEXT的认证类型实践。

二、安全配置

2.1 zookeeper SASL配置部分

2.1.1 创建conf/java.env文件,添加以下配置信息

export SERVER_JVMFLAGS="-Djava.security.auth.login.config=/opt/soft/zookeeper/conf/sasl.conf -Dzookeeper.allowSaslFailedClients=false"
export CLIENT_JVMFLAGS="-Djava.security.auth.login.config=/opt/soft/zookeeper/conf/sasl.conf -Dzookeeper.allowSaslFailedClients=false"                                                                                                                                   

2.1.2 创建conf/sasl.conf文件,添加如下配置信息,该配置会用于kafka登陆认证

Server {
       org.apache.zookeeper.server.auth.DigestLoginModule required
       user_admin="password";
};

2.1.3 在conf/zoo.conf文件添加如下配置信息

authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
requireClientAuthScheme=sasl                

2.2 kafka配置部分

2.2.1 创建config/kafka_server_jaas.conf配置文件,内容如下

KafkaServer {
  org.apache.kafka.common.security.plain.PlainLoginModule required
  username="admin"
  password="password"
  user_admin="admin123"
  user_test="test123";
};
### Client为登陆zookeeper配置 
Client {
  org.apache.kafka.common.security.plain.PlainLoginModule required
  username="admin"
  password="password";
};
### kafka客户端登陆配置
KafkaClient {
  org.apache.kafka.common.security.plain.PlainLoginModule required
  username="admin"
  password="admin123";
};

2.2.2 在config/server.properties文件增加一下关于SASL的认证配置信息

####################################SASL SETTING########################################
sasl.enabled.mechanisms=PLAIN
sasl.mechanism.inter.broker.protocol=PLAIN
#authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer ##3.0版本已经弃用
authorizer.class.name=kafka.security.authorizer.AclAuthorizer
allow.everyone.if.no.acl.found=true

2.2.3 修改bin/kafka-run-class.sh文件,增加认证配置

  KAFKA_OPTS="-Djava.security.auth.login.config=/opt/soft/kafka/config/kafka_server_jaas.conf"

image.png

2.2.4 在config/producer.properties 和 config/consumer.properties均需要添加以下认证配置

sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin123";
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN

2.2.5 在bin/kafka-console-producer.sh 和bin/kafka-console-consumer.sh均需要添加以下配置

    export KAFKA_HEAP_OPTS="-Xmx512M -Djava.security.auth.login.config=kafka_server_jaas.conf"

image.png

三、测试验证

3.1 控制台生产者测试,需要配置producer.properties

bin/kafka-console-producer.sh --bootstrap-server 10.126.38.160:9092 --topic test2023 \
--producer.config config/producer.properties

image.png

3.2 控制台消费者测试,需要配置consumer.properties

./bin/kafka-console-consumer.sh --bootstrap-server 10.126.38.160:9092 --topic test2023 \
--consumer.config config/consumer.properties

image.png

3.3 使用python作为消费者连接测试

from kafka import KafkaConsumer
import time
import json

BOOTSTRAP_SERVERS = '10.126.38.160:9092'
TOPIC = 'test2023'
consumer = KafkaConsumer(TOPIC,
                         bootstrap_servers=BOOTSTRAP_SERVERS,
                         auto_offset_reset='earliest',
                         security_protocol='SASL_PLAINTEXT',
                         sasl_mechanism='PLAIN',
                         sasl_plain_username='admin',
                         sasl_plain_password='password',
                         api_version=(0, 10),
                         receive_buffer_bytes=1024,
                         enable_auto_commit='False')
for msg in consumer:
    print(msg)

image.png

四、总结

通过以上配置基本能够实现SASL的配置功能。

标签:zookeeper,kafka,Centos7,conf,sasl,SASL,security,password,config
From: https://blog.51cto.com/u_15131458/6085644

相关文章

  • system管理zookeeper
    [root@ajsh-dev006systemd]#cat/usr/lib/systemd/system/zk.service[Unit]Description=zookeeper.serviceAfter=network.target[Service]User=rootGroup=root......
  • CentOS7加入AD域(winbind)
    作者:独笔孤行官网:​​ ​http://anyamaze.com​​公众号:云实战前言AD域(ActiveDirectory)是Windows服务器的活动目录,在目录中可以收录公司的电脑账号,用户账号,组等信息,......
  • centos7-分区2T以上大硬盘
    centos7-分区2T以上大硬盘1.centos7-分区2T以上大硬盘由于使用fdisk进行分区默认在2T内,大于2T后fdisk就无法进行大硬盘进行分区,需要对大于2TB进行分区,使用parted进行......
  • Centos7.4搭建FTP服务器
    【Centos7.4搭建FTP服务器】搭建环境:Centos7.4版本、生产服务器、计划默认端口5000、被动模式端口5001-5005 一、关闭防火墙1systemctlstatusfirewalld.service#......
  • Linux centos7升级内核(两种方法:内核编译和yum更新)
          Linuxcentos7升级内核(两种方法:内核编译和yum更新)Linux的内核概念不用说大家也很清楚,正是内核版本的不同,才有Linux发行版本的说法,现在主流的centos应该都......
  • 【小白】FileZilla Window安装并连接 Centos7
    本文是小白教程 通过 FileZilla来实现 windows系统到Centos7 服务器的文件传输。FTP概述文件传输协议(FileTransferProtocol,FTP)是用于在网络上进行文......
  • Centos7 K8S基础镜像设置
    1.1硬件基础配置指标指标值CPU2核内存2048M1.2操作系统基础配置配置项配置值Date&TimeAsia/ShanghaitimezoneKeyBOARDEnglish(US)......
  • Zookeeper原生客户端操作
    在Linux系统中安装了Zookeeper服务器,对Zookeeper命令有一些了解的情况下,学习如何在客户端操作Zookeeper。目前,Zookeeper服务器有三种Java客户端:Zookeeper、Zkclient和Cura......
  • 理论:第十二章:Dubbo的运行原理,支持什么协议,与SpringCould相比它为什么效率要高一些,Zook
    Dubbo简单的介绍一下Dubbo?(Dubbo是什么)dubbo就是个服务调用的东东。为什么怎么说呢?因为Dubbo是由阿里开源的一个RPC分布式框架那么RPC是什么呢?就是不同的应用部署到......
  • Centos7 yum源的变更及常用依赖的安装(转)
    零、背景当我们要用yum安装一些软件的时候,常常会遇到由于缺少配套工具软件而产生的失败。因此,在这里做一个汇总,将常用的一些配套软件作为一个配置项都写在这里,以备后续使用......