启用kerberos认证的hadoop集群自动初始化用户脚本

前提条件:
在kdc服务器以root用户执行
提前创建Linux 或ldap用户
提前创建用户数据库所在路径:hdfs://cndatalake/warehouse/tablespace/managed/userdb

脚本功能如下:

  1. 创建principal
  2. 创建Keytab
  3. 复制到用户根目录
  4. 创建hdfs home目录
  5. 创建hive用户个人数据库
#!/bin/bash
if [ $# -eq 0 ];
then
    echo 'Usage:"sh create_hadoop_user.sh username"'
    exit
fi

kadmin.local -q "add_principal -pw $1 $1@LTS.LOCAL"
kadmin.local -q "ktadd -keytab .$1.keytab -norandkey $1@LTS.LOCAL"

mv .$1.keytab /home/$1/
chown $1:$1 /home/$1/.$1.keytab

kinit -kt /etc/security/keytabs/hdfs.headless.keytab hdfs-cndatalake@LTS.LOCAL
hdfs dfs -mkdir /user/$1
hdfs dfs -chown $1:hdfs /user/$1

beeline -u 'jdbc:hive2://hadoop1.lts.local:2181,hadoop2.lts.local:2181,hadoop3.lts.local:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2' -e "CREATE DATABASE $1 LOCATION 'hdfs://cndatalake/warehouse/tablespace/managed/userdb/$1.db'";

Be the first to comment

Leave a Reply

Your email address will not be published.


*