栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

hadoop 一键安装和环境变量配置脚本

hadoop 一键安装和环境变量配置脚本

背景

每次安装Hadoop的时候都需要配置环境变量,写个脚本记着下次速度刚刚的。(从一个安装jdk的版本修修补补出来的)

脚本和参数说明 

脚本

#!/bin/sh
###检查是否是 管理员账户root
[ $(id -u) != "0" ] && { echo "***Error: You must be root to run this script"; exit 1; }

###默认安装路径
install_dir="/my/hadoop"
echo ${var%/*}
###读取文件名称
install_file_name=$2

install_folder_name=${install_file_name%.tar*}
###查询当前路径
current_dir="$(pwd)"

exit_ok=0
exit_fail=1

if [ -z "$1" ]
then
        echo "use default install dir:$install_dir"
else
        echo "use input param install_dir:$1"
        install_dir=$1
fi

###检查目录是否存在不存在则安装
if [ ! -d $install_dir ]; then
    mkdir -p $install_dir || exit $exit_fail
fi
hadoop_install_dir=$install_dir/$install_folder_name
if [ ! -d $hadoop_install_dir ]; then
    mkdir -p $hadoop_install_dir || exit $exit_fail
fi

###检查安装目录下是否已经存在其他版本 已经安装就退出 ---------------------
if [ -f $hadoop_install_dir/bin/hadoop ]; then
    echo "****notice***  $hadoop_install_dir/bin/hadoop  found, nothing will install"
    echo "****notice***  if you really want to install , please rm -fr $hadoop_install_dir manually first,then run again"
    echo "env HADOOP_HOME:$hadoop_install_dir"
    exit $exit_fail
fi

###解压安装文件
tar -zxvf ${install_file_name} -C $install_dir

#自动配置系统变量
if [ -z `cat /etc/profile|grep 'HADOOP_HOME='` ]; then
        echo " " >> /etc/profile
        echo "##HADOOP_HOME  " >> /etc/profile
        echo "export HADOOP_HOME=$hadoop_install_dir" >> /etc/profile
        echo 'export PATH=$PATH:$HADOOP_HOME/bin'  >> /etc/profile
        echo 'export CLASSPATH=.:$HADOOP_HOME/sbin' >> /etc/profile
else
        echo `cat /etc/profile|grep 'HADOOP_HOME='`
        echo `cat /etc/profile|grep 'HADOOP_HOME/bin'`
        echo `cat /etc/profile|grep 'HADOOP_HOME/lib'`
fi
#source /etc/profile
echo "success install hadoop, please use 'source /etc/profile' to enable"

运行说明

./install.sh /my/hadoop/ hadoop-3.3.0.tar.gz

./install.sh {安装的目录} {Hadoop的文件(必须是当前目录)}

一个常见问题说明

如果运行中出现了“/bin/sh^M: bad interpreter”的错误大概率是因为编码问题解决方法

.sh文件的格式为dos格式。而linux只能执行格式为unix格式的脚本

可以使用vi命令进行修改,步骤如下:

  1. 使用vi命令打开文件
  2. 查看编码 输入: set ff
  3. :set ff
  4. 如果不是unix就需要修改成unix 输入:set ff=unix
  5. : set ff=unix

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/651492.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号