配置Kafka用户Token认证信息
操作场景
用户可以通过登录Kafka客户端,使用kafka-delegation-tokens.sh脚本来生成Token、查询特定用户下的Token信息、刷新Token有效期、销毁Token等操作。
前提条件
- 已安装客户端,例如安装目录为“/opt/client”,以下操作的客户端目录只是举例,请根据实际安装目录修改。
下载并安装集群客户端的具体操作,请参考安装MRS集群客户端。
- 各组件业务用户由MRS集群管理员根据业务需要创建。“机机”用户需要下载keytab文件。“人机”用户第一次登录时需修改密码。(集群未启用Kerberos认证(普通模式)时不涉及)
创建用户相关操作请参考创建Kafka用户并绑定角色。
- 已开启Token认证机制。相关操作请参考调测Kafka Token认证机制样例程序章节。
约束与限制
本章节内容适用于MRS 3.x及后续版本的启用Kerberos认证的集群。
操作步骤
- 登录MRS集群Manager。
登录集群Manager具体操作,请参考访问MRS集群Manager。
- 获取Kafka节点业务IP及端口。
- 以客户端安装用户,登录安装客户端的节点。
- 执行以下命令,切换到客户端安装目录,例如安装目录为“/opt/client”,具体以实际替换。
cd /opt/client - 执行以下命令配置环境变量。
source bigdata_env
- 执行以下命令,进行用户认证。(集群未启用Kerberos认证(普通模式)时跳过此步骤)
kinit 组件业务用户 - 执行以下命令进入Kafka客户端“bin”目录。
cd Kafka/kafka/bin
- 使用kafka-delegation-tokens.sh对Token进行操作。
其中,IP1、IP2...表示Kafka节点业务IP,PORT表示Kafka集群端口号,详细取值请参考2获取。
- 为用户生成Token:
./kafka-delegation-tokens.sh --create --bootstrap-server <IP1:PORT, IP2:PORT,...> --max-life-time-period <Long: max life period in milliseconds> --command-config <config file> --renewer-principal User:<user name>
例如: ./kafka-delegation-tokens.sh --create --bootstrap-server 192.168.1.1:21007,192.168.1.2:21007,192.168.1.3:21007 --command-config ../config/producer.properties --max-life-time-period -1 --renewer-principal User:username
- 列出归属在特定用户下的所有Token信息:
./kafka-delegation-tokens.sh --describe --bootstrap-server <IP1:PORT, IP2:PORT,...> --command-config <config file> --owner-principal User:<user name>
例如: ./kafka-delegation-tokens.sh --describe --bootstrap-server 192.168.1.1:21007,192.168.1.2:21007,192.168.1.3:21007 --command-config ../config/producer.properties --owner-principal User:username
- Token有效期刷新:
./kafka-delegation-tokens.sh --renew --bootstrap-server <IP1:PORT, IP2:PORT,...> --renew-time-period <Long: renew time period in milliseconds> --command-config <config file> --hmac <String: HMAC of the delegation token>
例如: ./kafka-delegation-tokens.sh --renew --bootstrap-server 192.168.1.1:21007,192.168.1.2:21007,192.168.1.3:21007 --renew-time-period -1 --command-config ../config/producer.properties --hmac ABCDEFG
- 销毁Token:
./kafka-delegation-tokens.sh --expire --bootstrap-server <IP1:PORT, IP2:PORT,...> --expiry-time-period <Long: expiry time period in milliseconds> --command-config <config file> --hmac <String: HMAC of the delegation token>
例如: ./kafka-delegation-tokens.sh --expire --bootstrap-server 192.168.1.1:21007,192.168.1.2:21007,192.168.1.3:21007 --expiry-time-period -1 --command-config ../config/producer.properties --hmac ABCDEFG
- 为用户生成Token: