本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
Configuring a Cluster for Kerberos-Authenticated HDFS Users and SSH Connections
Amazon EMR 为集群上运行的应用程序创建通过 Kerberos 进行身份验证的客户端,例如,hadoop 用户、spark 用户等。您还可以添加已通过使用 Kerberos 的集群过程的身份验证的用户。然后,已通过身份验证的用户可以使用其 Kerberos 凭证连接到集群并使用应用程序。对于用户向集群进行身份验证,需要以下配置:
A Linux user account matching the Kerberos principal in the KDC must exist on the
cluster. Amazon EMR does this automatically in architectures that integrate with Active
Directory.
You must create an HDFS user directory on the master node for each user, and give
the user permissions to the directory.
You must configure the SSH service so that GSSAPI is enabled on the master node. In
addition, users must have an SSH client with GSSAPI enabled.
Adding Linux Users and Kerberos Principals to the Master Node
如果您不使用 Active Directory,则必须在集群主节点上创建 Linux 账户,并将这些 Linux 用户的委托人添加到 KDC。这包括主节点的 KDC
中的委托人。除了用户委托人之外,运行在主节点上的 KDC 需要本地主机的委托人。
重要
在主节点终止时,KDC 连同委托人的数据库将会丢失,因为主节点使用短暂存储。如果您为 SSH 连接创建用户,我们建议您建立一个跨领域信任,并为高可用性配置一个外部
KDC。或者,如果您使用 Linux 用户账户为 SSH 连接创建用户,则使用引导操作和脚本自动执行账户创建过程,以便在创建新的群集时可以重复这些步骤。
在创建之后或者创建集群时提交步骤到集群,这是添加用户和 KDC 委托人的最简单方法。或者,您可以作为默认 hadoop 用户,使用 EC2 密钥对连接到主节点来运行命令。有关更多信息,请参阅 使用 SSH 连接到主节点。)
下面的示例引用集群 ID,将 bash 脚本 configureCluster.sh 提交到已有的集群。该脚本会保存到 Amazon S3 中。
aws emr add-steps --cluster-id j-01234567 \
--steps Type=CUSTOM_JAR,Name=CustomJAR,ActionOnFailure=CONTINUE,\
Jar=s3://myregion.elasticmapreduce/libs/script-runner/script-runner.jar,\
Args=["s3://mybucket/configureCluster.sh"]
以下示例演示了 configureCluster.sh 脚本的内容。该脚本还处理创建 HDFS 用户目录和为 SSH 启用 GSSAPI 的过程,这些内容在下面的部分中介绍。
#!/bin/bash
#Add a principal to the KDC for the master node, using the master 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=([lijuan]=pwd1 [marymajor]=pwd2 [richardroe]=pwd3)
for i in ${!arr[@]}; do
#Assign plain language variables for clarity
name=${i}
password=${arr[${i}]}
# Create a principal for each user in the master node and require a new password on first logon
sudo kadmin.local -q "addprinc -pw $password +needchange $name"
#Add hdfs directory for each user
hdfs dfs -mkdir /user/$name
#Change owner of each user's hdfs directory to that 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 /etc/init.d/sshd restart
Adding User HDFS Directories
要允许您的用户登录到集群来运行 Hadoop 任务,您必须为其 Linux 用户账户添加 HDFS 用户目录,并为每个用户授予对其目录的所有权。
在创建之后或者创建集群时提交步骤到集群,这是创建 HDFS 目录的最简单方法。或者,您可以作为默认 hadoop 用户,使用 EC2 密钥对连接到主节点来运行命令。有关更多信息,请参阅 使用 SSH 连接到主节点。)
下面的示例引用集群 ID,将 bash 脚本 AddHDFSUsers.sh 提交到已有的集群。该脚本会保存到 Amazon S3 中。
aws emr add-steps --cluster-id ClusterID \
--steps Type=CUSTOM_JAR,Name=CustomJAR,ActionOnFailure=CONTINUE,\
Jar=s3://MyRegion.elasticmapreduce/libs/script-runner/script-runner.jar,Args=["s3://MyBucketPath/AddHDFSUsers.sh"]
以下示例演示了 AddHDFSUsers.sh 脚本的内容。
#!/bin/bash
# AddHDFSUsers.sh script
# Initialize an array of user names from AD, or Linux users created manually on the cluster
ADUSERS=("lijuan" "marymajor" "richardroe" "myusername")
# For each user listed, create an HDFS user directory
# and change ownership to the user
for username in ${ADUSERS[@]}; do
hdfs dfs -mkdir /user/$username
hdfs dfs -chown $username:$username /user/$username
done
Enabling GSSAPI for SSH
对于通过 Kerberos 进行身份验证的用户,要使用 SSH 连接到主节点,SSH 服务必须启用了 GSSAPI 身份验证。要启用 GSSAPI,请从主节点命令行运行以下命令或者使用步骤来将其作为脚本运行。重新配置
SSH 之后,您必须重新启动服务。
sudo sed -i 's/^.*GSSAPIAuthentication.*$/GSSAPIAuthentication yes/' /etc/ssh/sshd_config
sudo sed -i 's/^.*GSSAPICleanupCredentials.*$/GSSAPICleanupCredentials yes/' /etc/ssh/sshd_config
sudo /etc/init.d/sshd restart
















