在Debian上设置Kafka的安全认证,通常涉及配置SASL(Simple Authentication and Security Layer)和SSL(Secure Sockets Layer)两种安全策略。SASL用于身份验证,而SSL用于加密通信。以下是设置Kafka安全认证的步骤:
修改Zookeeper配置文件 (/usr/local/zookeeper-3.4.14/conf/zoo.cfg
):
ticktime=2000
initlimit=1
synclimit=5
datadir=/data/zookeeper/data
datalogdir=/data/zookeeper/datalog
clientport=2181
admin.serverport=8888
maxclientcnxns=3000
autopurge.snapretaincount=3
autopurge.purgeinterval=24
server.1=192.xxx.xxx.112:2888:3888
server.2=192.xxx.xxx.114:2888:3888
server.3=192.xxx.xxx.115:2888:3888
fourlw.commands.whitelist=conf,stat,srvr,mntr
saslauthprovider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
jaasloginrenew=3600000
requireclientauthscheme=sasl
zookeeper.sasl.client=true
配置Zookeeper JAAS文件 (/usr/local/zookeeper-3.4.14/conf/zk_jaas.conf
):
server {
org.apache.zookeeper.server.auth.DigestLoginModule required
username="admin"
password="admin123"
user_kafka="kafka123";
};
将JAAS配置文件添加到Zookeeper的环境变量中 (/usr/local/zookeeper-3.4.14/bin/zkenv.sh
):
zoobindir="${zoobindir:-/usr/bin}"
zookeeper_prefix="${zoobindir}/.."
# 新增变量
server_jvmflags="-djava.security.auth.login.config=/usr/local/zookeeper-3.4.14/conf/zk_jaas.conf"
引入Kafka依赖包:将Kafka安装包下的相关依赖包拷贝到Zookeeper的目录下。
配置Kafka的SASL动态认证:
Broker的JAAS配置:
编辑Kafka的server.properties
文件,添加或修改以下配置:
security.inter.broker.protocol=SASL_SSL
sasl.mechanism.inter.broker.protocol=SCRAM-SHA-256
sasl.enabled.mechanisms=SCRAM-SHA-256,SCRAM-SHA-512
客户端的JAAS配置: 客户端也需要配置JAAS文件,例如:
client {
org.apache.kafka.common.security.scram.ScramLoginModule required
username="admin_sasl_plaintext_username"
password="admin_sasl_plaintext_password";
};
启动Zookeeper集群节点并查看集群状态:
zkserver.sh restart
zkserver.sh status
启动Kafka Broker: 确保Kafka Broker配置文件中也启用了SASL和SSL相关设置,然后启动Kafka Broker。
以上步骤提供了一个基本的框架来设置Debian上的Kafka安全认证。根据具体的生产环境和需求,可能还需要进一步的定制和优化。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:Debian Kafka安全设置有哪些