2021.11.8单机版自动安装jdk、hadoop、zookeeper脚本记录

2021.11.8单机版自动安装jdk、hadoop、zookeeper脚本记录,第1张

2021.11.8单机版自动安装jdk、hadoop、zookeeper脚本记录
#!/bin/bash

jdk=true
zk=true
hadoop=true

hostname=`hostname`
echo "current host name is $hostname"
whoami=`whoami`
echo "current user is $whoami"

installdir=/opt/soft
if [ ! -d "$installdir" ]
then
	mkdir $installdir
fi

if [ "$jdk" = true ]
then
	echo "---------- 安装jdk ----------"
	tar -zxf /opt/install/jdk-8u221-linux-x64.tar.gz -C /opt/soft/
	mv /opt/soft/jdk1.8.0_221 /opt/soft/jdk180
	echo "#jdk" >> /etc/profile
	echo "export JAVA_HOME=/opt/soft/jdk180" >> /etc/profile
        echo "export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" >> /etc/profile
        echo "export PATH=$PATH:$JAVA_HOME/bin" >> /etc/profile
fi

if [ "$hadoop" = true ]
then
	echo '---------- 安装hadoop ----------'
	tar -zxf /opt/install/hadoop-2.6.0-cdh5.14.2.tar.gz -C /opt/soft
	mv /opt/soft/hadoop-2.6.0-cdh5.14.2 /opt/soft/hadoop260

	echo '---------- 修改配置hadoop-env.sh ----------'
	sed -i "/^export JAVA_HOME=/cexport JAVA_HOME=$JAVA_HOME/" /opt/soft/hadoop260/etc/hadoop/hadoop-env.sh

	echo '---------- 修改配置mapred-env.sh ----------'
	sed -i "/^# export JAVA_HOME=/cexport JAVA_HOME=$JAVA_HOME/" /opt/soft/hadoop260/etc/hadoop/mapred-env.sh

	echo '---------- 修改配置yarn-env.sh ----------'
	sed -i "/^# export JAVA_HOME=/cexport JAVA_HOME=$JAVA_HOME/" /opt/soft/hadoop260/etc/hadoop/yarn-env.sh

	echo '---------- 修改配置core-site.xml ----------'
	core_path="/opt/soft/hadoop260/etc/hadoop/core-site.xml"
	sed -i '19ahadoop.proxyuser.bigdata.groups*' $core_path
	sed -i '19ahadoop.proxyuser.bigdata.hosts*' $core_path
	sed -i '19ahadoop.tmp.dir/opt/soft/hadoop260/hadooptmp' $core_path
	sed -i "19afs.defaultFShdfs://$hostname:9000" $core_path

	echo '---------- 修改配置hdfs-site.xml ----------'
	hdfs_path="/opt/soft/hadoop260/etc/hadoop/hdfs-site.xml"
	sed -i "19adfs.namenode.secondary.http-address$hostname:50090" $hdfs_path
	sed -i '19adfs.replication1' $hdfs_path

	echo '---------- 修改配置mapred-site.xml ----------'
        mapred_path="/opt/soft/hadoop260/etc/hadoop/mapred-site.xml"
	cp /opt/soft/hadoop260/etc/hadoop/mapred-site.xml.template /opt/soft/hadoop260/etc/hadoop/mapred-site.xml
	sed -i "19amapreduce.jobhistory.webapp.address$hostname:19888" $mapred_path
	sed -i "19amapreduce.jobhistory.address$hostname:10020" $mapred_path
	sed -i '19amapreduce.framework.nameyarn' $mapred_path

	echo '---------- 修改配置yarn-site.xml ----------'
        yarn_path="/opt/soft/hadoop260/etc/hadoop/yarn-site.xml"
	sed -i '15ayarn.log-aggregation.retain-seconds86400' $yarn_path
        sed -i '15ayarn.log-aggregation-enabletrue' $yarn_path
        sed -i "15ayarn.resourcemanager.hostname$hostname" $yarn_path
        sed -i '15ayarn.nodemanager.aux-services.mapreduce.shuffle.classorg.apache.hadoop.mapred.ShuffleHandler' $yarn_path
        sed -i '15ayarn.nodemanager.aux-servicesmapreduce_shuffle' $yarn_path

	echo '---------- 修改配置slaves ----------'
	sed -i "s/localhost/$hostname/g" /opt/soft/hadoop260/etc/hadoop/slaves

	echo "#hadoop" >> /etc/profile
	echo 'export HADOOP_HOME=/opt/soft/hadoop260' >> /etc/profile
        echo 'export HADOOP_MAPRED_HOME=$HADOOP_HOME' >> /etc/profile
        echo 'export HADOOP_COMMON_HOME=$HADOOP_HOME' >> /etc/profile
        echo 'export HADOOP_HDFS_HOME=$HADOOP_HOME' >> /etc/profile
        echo 'export YARN_HOME=$HADOOP_HOME' >> /etc/profile
        echo 'export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native' >> /etc/profile
	echo 'export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib"' >> /etc/profile
	echo 'export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin' >> /etc/profile

	/opt/soft/hadoop260/bin/hadoop namenode -format
fi

if [ "$zk" = true ]
then
        echo "---------- 安装zookeeper ----------"
        tar -zxf /opt/install/zookeeper-3.4.5-cdh5.14.2.tar.gz -C /opt/soft/
        mv /opt/soft/zookeeper-3.4.5-cdh5.14.2 /opt/soft/zookeeper345
        cp /opt/soft/zookeeper345/conf/zoo_sample.cfg /opt/soft/zookeeper345/conf/zoo.cfg
	sed -i '/^dataDir=/cdataDir=/opt/soft/zookeeper345/datatmp' /opt/soft/zookeeper345/conf/zoo.cfg
	echo "server.1=$hostname:2888:3888" >> /opt/soft/zookeeper345/conf/zoo.cfg
	mkdir -p /opt/soft/zookeeper345/datatmp/
	echo "1"> /opt/soft/zookeeper345/datatmp/myid

	echo "#zookeeper" >> /etc/profile
	echo 'export ZOOKEEPER_HOME=/opt/soft/zookeeper345' >> /etc/profile
	echo 'export PATH=$PATH:$ZOOKEEPER_HOME/bin' >> /etc/profile	
fi

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5432613.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存