hadoop完全分布式一键安装脚本
#!/bin/bash
#配置HADOOP的安装目录 修改的地方1 脚本可以自己创建
##在windows编写的代码可能运行有问题执行以下 1>vim redisshell.sh 2>:set ff=unix
echo -e "请输入hadoop的安装目录,不存在脚本自动创建,最后一个/不要写 /bigdata/install"
read esinstallpath
#创建HADOOP安装的目录
if [ ! -d $esinstallpath ]; then
mkdir -p $esinstallpath
fi
if [ ! -d $esinstallpath ]; then
echo "创建目录$esinstallpat失败!请检查目录是否有权限"
exit
fi
#解压tar包
currentdir=$(cd $(dirname $0); pwd)
ls | grep 'hadoop-.*[gz]$'
if [ $? -ne 0 ]; then
#当前目录没有hadoop的压缩包
echo "在$currentdir下没有发现hadoop-*.tar.gz,请自行上传!"
exit
else
#解压
tar -zxvf $currentdir/$(ls | grep 'hadoop-.*[gz]$') -C $esinstallpath
fi
esbanben=`ls $esinstallpath| grep 'hadoop-.*'`
#PATH设置
#末行插入
echo "">>~/.bash_profile
echo '#HADOOP'>>~/.bash_profile
echo "export HADOOP_HOME=$esinstallpath/$esbanben">>~/.bash_profile
echo 'export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin'>>~/.bash_profile
source ~/.bash_profile
hadooppath=$esinstallpath/$esbanben
confpath=$esinstallpath/$esbanben/etc/hadoop
javahome=`echo $JAVA_HOME`
bak_dir='export JAVA_HOME=${JAVA_HOME}'
new_dir='export JAVA_HOME='$javahome
sed -i "s!${bak_dir}!${new_dir}!g" $confpath/hadoop-env.sh
#修改core-site.xml
echo -e "请输入hadoop集群服务器名称 例如 mycluster"
read mycluster
sed -i '/<\/configuration>/i\<!--配置hadoop集群服务器名称 -->' $confpath/core-site.xml
sed -i '/<\/configuration>/i\<property>' $confpath/core-site.xml
sed -i '/<\/configuration>/i\ <name>fs.defaultFS</name>' $confpath/core-site.xml
sed -i "/<\/configuration>/i\ <value>hdfs://$mycluster</value>" $confpath/core-site.xml
sed -i "/<\/configuration>/i\</property>" $confpath/core-site.xml
echo -e "请输入hadoop运行时产生文件的存储目录 不需要自己创建目录 集群自己会创建 指定一个空间大的 用来保存hadoop数据 例如 /bigdata/hadoop"
read hadooptmpdir
sed -i '/<\/configuration>/i\<!--hadoop运行时产生文件的存储目录 -->' $confpath/core-site.xml
sed -i '/<\/configuration>/i\<property>' $confpath/core-site.xml
sed -i '/<\/configuration>/i\ <name>hadoop.tmp.dir</name>' $confpath/core-site.xml
sed -i "/<\/configuration>/i\ <value>$hadooptmpdir</value>" $confpath/core-site.xml
sed -i "/<\/configuration>/i\</property>" $confpath/core-site.xml
echo -e "请输入zk集群 例如 cdh01:2181,cdh02:2181,cdh03:2181"
read zkhosts
sed -i '/<\/configuration>/i\<!--配置zookeeper集群,容灾 -->' $confpath/core-site.xml
sed -i '/<\/configuration>/i\<property>' $confpath/core-site.xml
sed -i '/<\/configuration>/i\ <name>ha.zookeeper.quorum</name>' $confpath/core-site.xml
sed -i "/<\/configuration>/i\ <value>$zkhosts</value>" $confpath/core-site.xml
sed -i "/<\/configuration>/i\</property>" $conf