kafka配置SASL/Plain认证以及GBase 8a的相关功能使用方法

本文详细介绍了如何在GBase8a中配置Kafka集群以支持SASL/PLAIN认证,包括编辑jaas配置文件、启动脚本和producer/consumer配置,以及创建并测试topic的过程。
摘要由CSDN通过智能技术生成

GBase 8a目前可以支持kafka集群配置SASL/PLAIN认证,下面讲解kafka端配置SASL/PLAIN认证的方法和如何在使用GBase 8a时配置kafka consumer的参数。

kafka用户名密码认证配置方法:

1、编辑config/kafka_server_jaas.conf

KafkaServer {

org.apache.kafka.common.security.plain.PlainLoginModule required

username="admin"

password="admin"

user_admin="admin"

user_gbase="gbase";

};

可以在user_{username}={password} 自定义需要添加的用户名和密码。

2、编辑 config/kafka_client_jaas.conf,保证客户端和服务端里面配置的用户名和密码是一致的。

KafkaClient {

org.apache.kafka.common.security.plain.PlainLoginModule required

username="gbase"

password="gbase";

};

3、kafka启动脚本kafka-server-start.sh里添加代码

export KAFKA_OPTS=" -Djava.security.auth.login.config=/opt/kafka/config/kafka_server_jaas.conf"   //修改为kafka_server_jaas.conf的路径

4、在 config/server.properties 里面增加内容

listeners=SASL_PLAINTEXT://localhost:9092 

security.inter.broker.protocol=SASL_PLAINTEXT

sasl.mechanism.inter.broker.protocol=PLAIN

sasl.enabled.mechanisms=PLAIN

此时已经可以启动kafka集群服务了。

5、编辑kafka-console-producer.sh,添加代码,在倒数第二行:

export KAFKA_OPTS=" -Djava.security.auth.login.config=/opt/kafka/config/kafka_client_jaas.conf"   //修改为kafka_server_jaas.conf的路径

在config/producer.properties里面编辑:

security.protocol=SASL_PLAINTEXT

sasl.mechanism=PLAIN

6、编辑kafka-console-consumer.sh, 添加代码,在倒数第二行:

export KAFKA_OPTS=" -Djava.security.auth.login.config=/opt/kafka/config/kafka_client_jaas.conf"   //修改为kafka_server_jaas.conf的路径

在consumer.properties里面编辑

security.protocol=SASL_PLAINTEXT

sasl.mechanism=PLAIN

7、创建topic,测试producer和consumer

$kafka_home/bin/kafka-topics.sh --create --zookeeper 10.10.11.167:2181 --replication-factor 2 --partitions 1 --topic yuehaoyu

$kafka_home/bin/kafka-console-producer.sh --broker-list 10.10.11.167:9092 --topic yuehaoyu --producer.config $kafka_home/config/producer.properties

随意写入数据,然后启动consumer脚本,从头开始消费

$kafka_home/bin/kafka-console-consumer.sh  --bootstrap-server 10.10.11.167:9092  --topic yuehaoyu --consumer.config $kafka_home/config/consumer.properties --from-beginning

查看是否成功消费producer生产的数据。

若成功,说明kafka集群配置普通密码加密方式认证成功。

使用GBase 8a:

首先确认一下使用的版本是否有gbase_kafka_auth_mode参数,如果有的话,将它设置成’Plain’,然后正确配置gbase_kafka_username和gbase_kafka_password,就可以正常使用带SASL/PLAIN认证的kafka了。

如果没有gbase_kafka_auth_mode参数,但是有gbase_kafka_username和gbase_kafka_password,那么配置这两个参数后默认使用plain认证方式。其他操作不受影响。

如果上面提到的三个参数都没有,那么这个版本不支持使用带SASL/PLAIN认证的kafka。

  • 19
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值