大数据之shell脚本配置伪分布式Hadoop

Posted Mr.zhou_Zxy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了大数据之shell脚本配置伪分布式Hadoop相关的知识,希望对你有一定的参考价值。

shell脚本配置伪分布式Hadoop

一 hadoop安装

install_hadoop.sh

## !/bin/bash

## 安装jdk
./install_java.sh
##安装前的路径
INSTALL_PROFIX=/opt/apps
## 环境变量
ETC_PROFILE=/etc/profile
## hadoop安装路径
HADOOP_DIR=${INSTALL_PROFIX}/hadoop-2.8.1
## 安装包的前缀路径
HADOOP_PROFIX=/opt/software
## hadoop的安装包路径
HADOOP_TAR=${HADOOP_PROFIX}/hadoop-2.8.1.tar.gz

## 判断安装路径是否存在,如果存在说明此软件已经安装过了
if [ -e "${HADOOP_DIR}" ];then
        echo "warning:${HADOOP_DIR} is exists"
        exit 0
fi

## 判断安装包是否存在,如果不存在,就不用安装了
if [ ! -e "${HADOOP_TAR}" ];then
        echo "warving:${HADOOP_TAR} is not exists"
        exit -1
fi

tar -zxvf ${HADOOP_TAR} -C ${INSTALL_PROFIX}

cat << EOF >> ${ETC_PROFILE}
export HADOOP_HOME=${HADOOP_DIR}
export PATH=\\$PATH:\\${HADOOP_HOME}/bin:\\${HADOOP_HOME}/sbin
EOF

## 修改hadoop-env.sh配置文件
./hadoop-env.sh

## 修改core-site.xml配置文件
./core-site.sh

## 修改hdfs-site.xml配置文件
./hdfs-site.sh

## 免密操作
ssh-keygen
ssh-copy-id 192.168.130.130

## 格式化namenode
source /etc/profile
hdfs namenode -format

## 关闭防火墙
systemctl stop firewalld

二 jdk安装

install_java.sh

## !/bin/bash

## 安装前缀路径
INSTALL_PREFIX=/opt/apps
## 配置环境变量
ETC_PROFILE=/etc/profile
## jdk安装路径
JAVA_DIR=${INSTALL_PREFIX}/jdk1.8.0_261
## 安装包的路径
TAR_PROFIX=/opt/software
## JDK的路径
JAVA_TAR=${TAR_PROFIX}/jdk-8u261-linux-x64.tar.gz

## 判断安装路径是否存在,如果存在说明我们已经安装过此应用
if [ -e "${JAVA_DIR}" ];then
	echo "warning:${JAVA_DIR} is exists"
	exit 0
fi

## 判断安装包是否存在,如果不存在,就不用安装
if [ ! -e "${JAVA_TAR}" ];then
	echo "warning:${JAVA_TAR} is not exists"
	exit -1
fi

tar -zxvf ${JAVA_TAR} -C ${INSTALL_PREFIX}

cat << EOF >> ${ETC_PROFILE}
 export JAVA_HOME=${JAVA_DIR}
 export PATH=\\$PATH:\\${JAVA_HOME}/bin
 export CLASS_PATH=./\\${JAVA_HOME}/lib
EOF

三 修改Hadoop配置文件

hadoop-env.sh

## 更新配置文件
 source /etc/profile

## 更改Hadoop配置文件

echo '# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Set Hadoop-specific environment variables here.

# The only required environment variable is JAVA_HOME.  All others are
# optional.  When running a distributed configuration it is best to
# set JAVA_HOME in this file, so that it is correctly defined on
# remote nodes.

# The java implementation to use.
export JAVA_HOME=/opt/apps/jdk1.8.0_261

# The jsvc implementation to use. Jsvc is required to run secure datanodes
# that bind to privileged ports to provide authentication of data transfer
# protocol.  Jsvc is not required if SASL is configured for authentication of
# data transfer protocol using non-privileged ports.
#export JSVC_HOME=${JSVC_HOME}

export HADOOP_CONF_DIR=${HADOOP_CONF_DIR:-"/etc/hadoop"}

# Extra Java CLASSPATH elements.  Automatically insert capacity-scheduler.
    export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$f
  else
done

# The maximum amount of heap to use, in MB. Default is 1000.
#export HADOOP_HEAPSIZE=
#export HADOOP_NAMENODE_INIT_HEAPSIZE=""

# Kerberos security.
# export HADOOP_JAAS_DEBUG=true

# Extra Java runtime options.  Empty by default.
# For Kerberos debugging, an extended option set logs more invormation
# export HADOOP_OPTS="-Djava.net.preferIPv4Stack=true -Dsun.security.krb5.debug=true -Dsun.security.spnego.debug"
export HADOOP_OPTS="$HADOOP_OPTS -Djava.net.preferIPv4Stack=true"

# Command specific options appended to HADOOP_OPTS when specified
export HADOOP_DATANODE_OPTS="-Dhadoop.security.logger=ERROR,RFAS $HADOOP_DATANODE_OPTS"


export HADOOP_NFS3_OPTS="$HADOOP_NFS3_OPTS"
export HADOOP_PORTMAP_OPTS="-Xmx512m $HADOOP_PORTMAP_OPTS"

# The following applies to multiple commands (fs, dfs, fsck, distcp etc)
export HADOOP_CLIENT_OPTS="$HADOOP_CLIENT_OPTS"
# set heap args when HADOOP_HEAPSIZE is empty
if [ "$HADOOP_HEAPSIZE" = "" ]; then
  export HADOOP_CLIENT_OPTS="-Xmx512m $HADOOP_CLIENT_OPTS"
fi
#HADOOP_JAVA_PLATFORM_OPTS="-XX:-UsePerfData $HADOOP_JAVA_PLATFORM_OPTS"

# On secure datanodes, user to run the datanode as after dropping privileges.
# This **MUST** be uncommented to enable secure HDFS if using privileged ports
# to provide authentication of data transfer protocol.  This **MUST NOT** be
# defined if SASL is configured for authentication of data transfer protocol
# using non-privileged ports.
export HADOOP_SECURE_DN_USER=${HADOOP_SECURE_DN_USER}

# Where log files are stored.  $HADOOP_HOME/logs by default.
#export HADOOP_LOG_DIR=${HADOOP_LOG_DIR}/$USER

# Where log files are stored in the secure data environment.
#export HADOOP_SECURE_DN_LOG_DIR=${HADOOP_LOG_DIR}/${HADOOP_HDFS_USER}

###
# HDFS Mover specific parameters
###
# Specify the JVM options to be used when starting the HDFS Mover.
# These options will be appended to the options specified as HADOOP_OPTS
# and therefore may override any similar flags set in HADOOP_OPTS
#
# export HADOOP_MOVER_OPTS=""

###
# Advanced Users Only!
###

# The directory where pid files are stored. /tmp by default.
# NOTE: this should be set to a directory that can only be written to by
#       the user that will run the hadoop daemons.  Otherwise there is the
#       potential for a symlink attack.
export HADOOP_PID_DIR=${HADOOP_PID_DIR}
export HADOOP_SECURE_DN_PID_DIR=${HADOOP_PID_DIR}

# A string representing this instance of hadoop. $USER by default.
export HADOOP_IDENT_STRING=$USER ' > ${HADOOP_HOME}/etc/hadoop/hadoop-env.sh

core-site.sh

## 更新配置文件
 source /etc/profile

## 更改Hadoop配置文件

echo '<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>

        <!-- 配置的namenode的内部通信地址  -->
        <property>
                <name>fs.defaultFS</name>
                <value>hdfs://192.168.130.130:9000</value>
        </property>

        <!-- hadoop的内部的数据或者元数据真是的存放路径 -->
        <property>
                <name>hadoop.tmp.dir</name>
                <value>/opt/apps/hadoop-2.8.1/hdpdata</value>
        </property>
</configuration> ' > ${HADOOP_HOME}/etc/hadoop/core-site.xml 

hdfs-site.sh

## 更新配置文件
 source /etc/profile

## 更改Hadoop配置文件

echo '<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
        <property>
                <name>dfs.replication</name>
                <value>1</value>
        </property>
</configuration> ' > ${HADOOP_HOME}/etc/hadoop/hdfs-site.xml

四 帮助文档

启动命令:sh install_hadoop.sh
启动内容:
1.调用install_jdk.sh,安装jdk和配置环境
2.安装hadoop和配置hadoop环境
3.调用hadoop-env.sh,修改jdk的路径
4.调用core-site.sh和hdfs-site.sh修改hadoop文件中的core-site.xml和hdfs-site.xml
完成操作:启动sh install_hadoop.sh成功后
通过start-dfs.sh启动
通过http://192.168.130.130:50070查看webGUI 

参考资源:

在这里插入图片描述

以上是关于大数据之shell脚本配置伪分布式Hadoop的主要内容,如果未能解决你的问题,请参考以下文章

大数据之---hadoop伪分布式部署(HDFS)全网终极篇

大数据之---hadoop伪分布式部署(HDFS)全网终极篇

大数据(hdfs集群及其集群的高级管理)

大数据分析Hadoop + Spark 10分钟搭建Hadoop(伪分布式 )+ Spark(Local模式)环境

黑马12期大数据教程(hadoop,storm,kafka,hbase,hive,sqoop)

大数据应用——Hadoop运行模式(伪分布式运行)