2011-05-27 16:35:02 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2011-09-13 00:31:29 +00:00
|
|
|
this="${BASH_SOURCE-$0}"
|
|
|
|
bin=$(cd -P -- "$(dirname -- "$this")" && pwd -P)
|
|
|
|
script="$(basename -- "$this")"
|
|
|
|
this="$bin/$script"
|
2011-05-27 16:35:02 +00:00
|
|
|
|
|
|
|
if [ "$HADOOP_HOME" != "" ]; then
|
|
|
|
echo "Warning: \$HADOOP_HOME is deprecated."
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
|
2011-11-18 00:48:54 +00:00
|
|
|
DEFAULT_LIBEXEC_DIR="$bin"/../libexec
|
|
|
|
HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
|
|
|
|
. $HADOOP_LIBEXEC_DIR/hadoop-config.sh
|
2011-05-27 16:35:02 +00:00
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo "
|
|
|
|
usage: $0 <parameters>
|
|
|
|
Require parameter:
|
2011-09-13 00:31:29 +00:00
|
|
|
--config /etc/hadoop Location of Hadoop configuration file
|
|
|
|
-u <username> Create user on HDFS
|
2011-05-27 16:35:02 +00:00
|
|
|
Optional parameters:
|
2011-09-13 00:31:29 +00:00
|
|
|
-h Display this message
|
|
|
|
--kerberos-realm=KERBEROS.EXAMPLE.COM Set Kerberos realm
|
|
|
|
--super-user=hdfs Set super user id
|
|
|
|
--super-user-keytab=/etc/security/keytabs/hdfs.keytab Set super user keytab location
|
2011-05-27 16:35:02 +00:00
|
|
|
"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2011-09-13 00:31:29 +00:00
|
|
|
OPTS=$(getopt \
|
|
|
|
-n $0 \
|
|
|
|
-o '' \
|
|
|
|
-l 'kerberos-realm:' \
|
|
|
|
-l 'super-user:' \
|
|
|
|
-l 'super-user-keytab:' \
|
|
|
|
-o 'h' \
|
|
|
|
-o 'u' \
|
|
|
|
-- "$@")
|
|
|
|
|
|
|
|
if [ $? != 0 ] ; then
|
2011-05-27 16:35:02 +00:00
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-09-13 00:31:29 +00:00
|
|
|
create_user() {
|
|
|
|
if [ "${SETUP_USER}" = "" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
HADOOP_HDFS_USER=${HADOOP_HDFS_USER:-hdfs}
|
|
|
|
export HADOOP_PREFIX
|
|
|
|
export HADOOP_CONF_DIR
|
|
|
|
export JAVA_HOME
|
|
|
|
export SETUP_USER=${SETUP_USER}
|
|
|
|
export SETUP_PATH=/user/${SETUP_USER}
|
|
|
|
|
|
|
|
if [ ! "${KERBEROS_REALM}" = "" ]; then
|
|
|
|
# locate kinit cmd
|
|
|
|
if [ -e /etc/lsb-release ]; then
|
|
|
|
KINIT_CMD="/usr/bin/kinit -kt ${HDFS_USER_KEYTAB} ${HADOOP_HDFS_USER}"
|
|
|
|
else
|
|
|
|
KINIT_CMD="/usr/kerberos/bin/kinit -kt ${HDFS_USER_KEYTAB} ${HADOOP_HDFS_USER}"
|
|
|
|
fi
|
|
|
|
su -c "${KINIT_CMD}" ${HADOOP_HDFS_USER}
|
|
|
|
fi
|
|
|
|
|
|
|
|
su -c "${HADOOP_PREFIX}/bin/hadoop --config ${HADOOP_CONF_DIR} fs -mkdir ${SETUP_PATH}" ${HADOOP_HDFS_USER}
|
|
|
|
su -c "${HADOOP_PREFIX}/bin/hadoop --config ${HADOOP_CONF_DIR} fs -chown ${SETUP_USER}:${SETUP_USER} ${SETUP_PATH}" ${HADOOP_HDFS_USER}
|
|
|
|
su -c "${HADOOP_PREFIX}/bin/hadoop --config ${HADOOP_CONF_DIR} fs -chmod 711 ${SETUP_PATH}" ${HADOOP_HDFS_USER}
|
|
|
|
|
|
|
|
if [ "$?" == "0" ]; then
|
|
|
|
echo "User directory has been setup: ${SETUP_PATH}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
eval set -- "${OPTS}"
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
-u)
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--kerberos-realm)
|
|
|
|
KERBEROS_REALM=$2; shift 2
|
|
|
|
;;
|
|
|
|
--super-user)
|
|
|
|
HADOOP_HDFS_USER=$2; shift 2
|
|
|
|
;;
|
|
|
|
--super-user-keytab)
|
|
|
|
HDFS_USER_KEYTAB=$2; shift 2
|
|
|
|
;;
|
|
|
|
-h)
|
2011-05-27 16:35:02 +00:00
|
|
|
usage
|
|
|
|
;;
|
|
|
|
--)
|
2011-09-13 00:31:29 +00:00
|
|
|
while shift; do
|
|
|
|
SETUP_USER=$1
|
|
|
|
create_user
|
|
|
|
done
|
|
|
|
break
|
2011-05-27 16:35:02 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown option: $1"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|