教程:配置集群专用的 KDC - Amazon EMR
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

教程:配置集群专用的 KDC

本主题引导您创建具有集群专用密钥分发中心(KDC)的集群,手动将 Linux 账户添加到所有集群节点,将 Kerberos 主体添加到主节点上的 KDC 并确保客户端计算机已安装 Kerberos 客户端。

有关 Kerberos 和 KDC 的 Amazon EMR 支持的更多信息以及指向 MIT Kerberos 文档的链接,请参阅使用 Kerberos 通过 Amazon EMR 进行身份验证

步骤 1:创建使用 Kerberos 的集群

  1. 创建启用 Kerberos 的安全配置。以下示例演示使用 Amazon CLI 将安全配置指定为内联 JSON 结构的 create-security-configuration 命令。您也可以引用本地保存的文件。

    aws emr create-security-configuration --name MyKerberosConfig \ --security-configuration '{"AuthenticationConfiguration": {"KerberosConfiguration": {"Provider": "ClusterDedicatedKdc", "ClusterDedicatedKdcConfiguration": {"TicketLifetimeInHours": 24}}}}'
  2. 创建引用安全配置、指定集群的 Kerberos 属性并使用引导操作添加 Linux 账户的集群。以下示例演示使用 Amazon CLI 的 create-cluster 命令。此命令引用您在上面创建的安全配置 MyKerberosConfig。它还引用一个简单脚本 createlinuxusers.sh 作为引导操作,这是您在创建集群之前创建并上载到 Amazon S3 的脚本。

    aws emr create-cluster --name "MyKerberosCluster" \ --release-label emr-5.36.1 \ --instance-type m5.xlarge \ --instance-count 3 \ --ec2-attributes InstanceProfile=EMR_EC2_DefaultRole,KeyName=MyEC2KeyPair \ --service-role EMR_DefaultRole \ --security-configuration MyKerberosConfig \ --applications Name=Hadoop Name=Hive Name=Oozie Name=Hue Name=HCatalog Name=Spark \ --kerberos-attributes Realm=EC2.INTERNAL,\ KdcAdminPassword=MyClusterKDCAdminPwd \ --bootstrap-actions Path=s3://DOC-EXAMPLE-BUCKET/createlinuxusers.sh

    以下编码演示了 createlinuxusers.sh 脚本的内容,它将 user1、user2 和 user3 添加到集群中的每个节点。在下一个步骤中,您将这些用户添加为 KDC 委托人。

    #!/bin/bash sudo adduser user1 sudo adduser user2 sudo adduser user3

步骤 2:将委托人添加到 KDC、创建 HDFS 用户目录并配置 SSH

主节点上运行的 KDC 需要为本地主机和您在集群上创建的每个用户添加主体。您还可以为每个用户创建 HDFS 目录 (如果他们需要连接到集群并运行 Hadoop 任务)。同样,配置 SSH 服务以启用 GSSAPI 身份验证,这是 Kerberos 所必需的。在启用 GSSAPI 后,重新启动 SSH 服务。

完成这些任务的最简单方法是向集群提交步骤。下面的示例将 bash 脚本 configurekdc.sh 提交到您在上一步中创建的集群,引用其集群 ID。该脚本会保存到 Amazon S3 中。或者,您可以使用 EC2 密钥对连接到主节点来运行命令或在集群创建过程中提交步骤。

aws emr add-steps --cluster-id <j-2AL4XXXXXX5T9> --steps Type=CUSTOM_JAR,Name=CustomJAR,ActionOnFailure=CONTINUE,Jar=s3://myregion.elasticmapreduce/libs/script-runner/script-runner.jar,Args=["s3://DOC-EXAMPLE-BUCKET/configurekdc.sh"]

以下编码演示了 configurekdc.sh 脚本的内容。

#!/bin/bash #Add a principal to the KDC for the primary node, using the primary node's returned host name sudo kadmin.local -q "ktadd -k /etc/krb5.keytab host/`hostname -f`" #Declare an associative array of user names and passwords to add declare -A arr arr=([user1]=pwd1 [user2]=pwd2 [user3]=pwd3) for i in ${!arr[@]}; do #Assign plain language variables for clarity name=${i} password=${arr[${i}]} # Create principal for sshuser in the primary node and require a new password on first logon sudo kadmin.local -q "addprinc -pw $password +needchange $name" #Add user hdfs directory hdfs dfs -mkdir /user/$name #Change owner of user's hdfs directory to user hdfs dfs -chown $name:$name /user/$name done # Enable GSSAPI authentication for SSH and restart SSH service sudo sed -i 's/^.*GSSAPIAuthentication.*$/GSSAPIAuthentication yes/' /etc/ssh/sshd_config sudo sed -i 's/^.*GSSAPICleanupCredentials.*$/GSSAPICleanupCredentials yes/' /etc/ssh/sshd_config sudo systemctl restart sshd

您添加的用户现在应该可以使用 SSH 连接到集群。有关更多信息,请参阅通过 SSH 连接使用 Kerberos 的集群