kafka SASL/SCRAM安全认证配置及GBase 8a相关功能的使用

kafka支持SASL/SCRAM认证加密,目前8a适配了此功能,下面讲解如何给kafka配置SASL/SCRAM认证。

Zookeeper配置:

1、配置zookeeper,在zookeeper的配置文件里添加如下内容

在zookeeper的配置文件里添加如下内容:

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

requireClientAuthSchema=sasl

2、zookeeper/conf下创建认证文件并编辑

vi config/zookeeper_jaas.conf

Server {

org.apache.zookeeper.server.auth.DigestLoginModule required

user_super="super1234"

user_kafka="kafka1234";

};

3、zookeeper启动脚本zookeeper/bin/zkServer.sh里添加代码,启动zookeeper

vi bin/zkServer.sh

export JVMFLAGS="-Djava.security.auth.login.config=/opt/kafka/zookeeper/conf/zookeeper_jaas.conf -Dzookeeper.4lw.commands.whitelist=*"

其中路径根据实际情况调整。

启动zookeeper:

bin/zkserver.sh start --config conf

4、成功启动后,把超级用户的用户名密码添加到zookeeper中

cd /opt/kafka

bin/kafka-configs.sh --zookeeper 10.10.15.59:2181 --alter --add-config 'SCRAM-SHA-512=[password=admin1234]' --entity-type users --entity-name admin

bin/kafka-configs.sh --zookeeper 10.10.15.59:2181 --alter --add-config 'SCRAM-SHA-512=[password=kafka1234]' --entity-type users --entity-name kafka

5、检查一下上一步是否添加成功

bin/kafka-configs.sh --zookeeper 10.10.15.59:2181  --entity-type users --entity-name admin --describe

bin/kafka-configs.sh --zookeeper 10.10.15.59:2181  --entity-type users --entity-name kafka --describe

Kafka Server配置:

1、编辑server.properties

vi /opt/kafka/config/server.properties

listeners=SASL_PLAINTEXT://10.10.15.59:9092

advertised.listeners=SASL_PLAINTEXT://10.10.15.59:9092

security.inter.broker.protocol=SASL_PLAINTEXT

sasl.mechanism.inter.broker.protocol=SCRAM-SHA-512      

sasl.enabled.mechanisms=PLAIN,SCRAM-SHA-512

authorizer.class.name=kafka.security.authorizer.AclAuthorizer

super.users=User:admin;User:kafka

allow.everyone.if.no.acl.found=false

SCRAM-SHA-512和SCRAM-SHA-256可以同时存在,sasl.mechanism.inter.broker.protocol和sasl.enabled.mechanisms可以同时配置这两种加密。

超级用户对应上面zookeeper中添加的那两个用户,根据需要可以自己添加。

2、kafka/config下创建认证文件并编辑

vi /opt/kafka/config/kafka-broker-jaas.conf

添加以下内容

KafkaServer {

    org.apache.kafka.common.security.scram.ScramLoginModule required

    username="admin"

    password="admin1234";

};

Client {

    org.apache.zookeeper.server.auth.DigestLoginModule required

    username="kafka"

    password="kafka1234";

};

3、编辑kafka的启动脚本

vi bin/kafka-server-start.sh

倒数第二行添加以下内容:

export KAFKA_OPTS=" -Djava.security.auth.login.config=/opt/kafka/config/kafka-broker-jaas.conf"

根据实际情况调整路径。

4、启动kafka

nohup $kafka_home/bin/kafka-server-start.sh $kafka_home/config/server.properties >$kafka_home/logs/kk.log &

以上命令供参考

5、配置consumer和producer

consumer:

编辑 config/kafka_client_jaas.conf

KafkaClient {

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

username="kafka"

password="kafka1234";

};

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

export KAFKA_OPTS=" -Djava.security.auth.login.config=/opt/kafka/config/kafka_client_jaas.conf"

编辑consumer配置文件config/consumer.properties,添加以下两行:

security.protocol=SASL_PLAINTEXT

sasl.mechanism=SCRAM-SHA-512

producer:

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

export KAFKA_OPTS=" -Djava.security.auth.login.config=/opt/kafka/config/kafka_client_jaas.conf"

编辑producer配置文件config/producer.properties,添加以下两行:

security.protocol=SASL_PLAINTEXT

sasl.mechanism=SCRAM-SHA-512

使用GBase 8a:

首先确认一下使用的版本是否有gbase_kafka_auth_mode参数,如果有的话,将它设置成’SCRAM-SHA-512’或’SCRAM-SHA-256’,然后正确配置gbase_kafka_username和gbase_kafka_password。

如果没有gbase_kafka_auth_mode参数,那么此版本不支持使用SCRAM加密的kafka。

  • 22
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值