我们已经搭建好了一套完整的Hadoop+spark+jupyter环境,可是总是需要手动配置整个过程,实在是麻烦。更何况在实际的集群当中,也不可能一台机器一台机器的去配置,所以需要使用脚本自动化配置。这个系列就记录一下自己写脚本的历程吧,多有缺点和纰漏之处还望批评指正。(系统:Ubuntu14)。
首先我们希望把一个专门的用户作为我们整套环境的启动用户(当然你也完全可以使用root环境去配置整个环境),因此第一个脚本就从添加新用户并设置sudo免密操作开始吧。
如果还没有expect,先sudo apt-get install expect安装包。
#!/bin/bash
num=$#
if [ $num != 2 ]
then
echo -e "\033[31m Sorry, PLZ run this script as './addNewUser.sh username password' \033[0m"
else
echo -e "\033[32m Start AddUser \033[0m"
user=$1
password=$2
echo -e "\033[32m Start create username:$user & password:$password \033[0m"
useradd -d /home/$user $user
expect << EOF
spawn passwd $user
expect "Enter new UNIX password"
send "${password}\r"
expect "Retype new UNIX password"
send "${password}\r"
expect eof;
EOF
echo -e "\033[32m Succesfully create user $user \033[0m"
#set hadoop sudo
echo 'hadoop ALL=(ALL:ALL) ALL'>>/etc/sudoers
echo 'hadoop ALL=(ALL)NOPASSWD:ALL'>>/etc/sudoers
echo 'configure /etc/sudoers'
fi