本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
教程:配置集群专用 KDC
本主题将指导您创建具有群集专用密钥分发中心 (KDC) 的群集、手动向所有群集节点添加 Linux 帐户、向主节点KDC上添加 Kerberos 主体以及确保客户端计算机安装了 Kerberos 客户端。
有关亚马逊对 Kerberos 的EMR支持以及指向 Kerberos 文档的链接的更多信息,MIT请参阅。KDC 使用 Kerberos 通过亚马逊进行身份验证 EMR
步骤 1:创建使用 Kerberos 的集群
-
创建启用 Kerberos 的安全配置。以下示例演示了一个使用 AWS CLI 将安全配置指定为内联JSON结构的
create-security-configuration
命令。您也可以引用本地保存的文件。aws emr create-security-configuration --name
MyKerberosConfig
\ --security-configuration '{"AuthenticationConfiguration": {"KerberosConfiguration": {"Provider": "ClusterDedicatedKdc", "ClusterDedicatedKdcConfiguration": {"TicketLifetimeInHours":24
}}}}' -
创建引用安全配置、指定集群的 Kerberos 属性并使用引导操作添加 Linux 账户的集群。以下示例演示使用 AWS CLI的
create-cluster
命令。此命令引用您在上面创建的安全配置MyKerberosConfig
。它还引用一个简单脚本createlinuxusers.sh
作为引导操作,这是您在创建集群之前创建并上载到 Amazon S3 的脚本。aws emr create-cluster --name "
MyKerberosCluster
" \ --release-labelemr-7.2.0
\ --instance-typem5.xlarge
\ --instance-count3
\ --ec2-attributes InstanceProfile=EMR_EC2_DefaultRole,KeyName=MyEC2KeyPair
\ --service-role EMR_DefaultRole \ --security-configurationMyKerberosConfig
\ --applications Name=Hadoop
Name=Hive
Name=Oozie
Name=Hue
Name=HCatalog
Name=Spark
\ --kerberos-attributes Realm=EC2.INTERNAL
,\ KdcAdminPassword=MyClusterKDCAdminPwd
\ --bootstrap-actionsPath=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运行需要为本地主机和您在集群上创建的每个用户添加一个主体。如果每个用户需要连接到集群并运行 Hadoop 作业,您也可以为他们创建HDFS目录。同样,将SSH服务配置为启用GSSAPI身份验证,这是 Kerberos 所必需的。启用后GSSAPI,重新启动该SSH服务。
完成这些任务的最简单方法是向集群提交步骤。下面的示例将 bash 脚本 configurekdc.sh
提交到您在上一步中创建的集群,引用其集群 ID。该脚本会保存到 Amazon S3 中。或者,您可以使用 EC2 key pair 连接到主节点以运行命令或在创建集群期间提交步骤。
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到 Kerberized 集群。