hadoop完全分布式一键安装、启动、停止脚本

本文提供了一键安装、启动和停止Hadoop完全分布式环境的脚本教程,旨在简化集群配置和管理过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值