自动化安装部署hadoop

1.安装hadoop的shell脚本

#! /bin/bash

## filename: install-hadoop.sh
## author: hyy
## date: 2021-5-21
## desc: install hadoop

## 主机名(需要在hosts文件中配置)
hostname=server
## 在后边的配置文件中会用到这个变量,所以设为全局变量
export hostname
## 安装路径前缀
install_prefix=/opt/apps
## 压缩包所在路径前缀
tar_prefix=/opt/software
## 压缩包路径
hadoop_tar=${tar_prefix}/hadoop-2.8.1.tar.gz
## 安装路径
hadoop_dir=${install_prefix}/hadoop-2.8.1
## 将该变量更改为全局变量,便于后面调用
export hadoop_dir
## 配置系统环境变量文件的路径
etc_file=/etc/profile

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

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

echo ${hadoop_tar}
echo ${hadoop_dir}

## 解压压缩包安装
tar -zxvf ${hadoop_tar} -C ${install_prefix}/

## 配置环境变量,符号“\”可以转义$避免写入时被识别为变量
cat << EOF >> ${etc_file}
export HADOOP_HOME=${hadoop_dir}
export PATH=\$PATH:\${HADOOP_HOME}/bin:\${HADOOP_HOME}/sbin
EOF

# 配置hadoop-env.sh
./config-hadoop-env.sh

## 配置core-site.xml
./config-core-site.sh

## 配置hdfs-site.xml
./config-hdfs-site.sh

2.配置core-site.xml

#! /bin/bash

## filename: config-core-site.sh
## author: hyy
## date: 2021-5-21
## desc: config the file core-site.xml

## the path of core-site.xml,之前的配置文件中已经配置hadoop_dir为全局变量,所以此处可以应用
file_path=${hadoop_dir}/etc/hadoop/core-site.xml

## config the content
cat << EOF > ${file_path}
<?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://${hostname}:9000</value>
        </property>

        <!-- hadoop的内部的数据或者元数据真是的存放路径 -->
        <property>
                <name>hadoop.tmp.dir</name>
                <value>${hadoop_dir}/hdpdata</value>
        </property>
</configuration>
EOF

echo "config core-site.xml finished..."

3.配置hadoop-env.sh

#! /bin/bash

## filename: config-hadoop-env.sh
## author: hyy
## date: 2021-5-21
## desc: config the file hadoop-env.sh

## the path of hadoop-env.sh
file_path=${hadoop_dir}/etc/hadoop/hadoop-env.sh

## 配置文件内容
cat << EOF > ${file_path}
# 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=${JAVA_HOME}

# 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.
for f in \$HADOOP_HOME/contrib/capacity-scheduler/*.jar; do
  if [ "\$HADOOP_CLASSPATH" ]; then
    export HADOOP_CLASSPATH=\$HADOOP_CLASSPATH:$f
  else
    export HADOOP_CLASSPATH=\$f
  fi
done

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

# Enable extra debugging of Hadoop's JAAS binding, used to set up
# 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_NAMENODE_OPTS="-Dhadoop.security.logger=\${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=\${HDFS_AUDIT_LOGGER:-INFO,NullAppender} \$HADOOP_NAMENODE_OPTS"
export HADOOP_DATANODE_OPTS="-Dhadoop.security.logger=ERROR,RFAS \$HADOOP_DATANODE_OPTS"

export HADOOP_SECONDARYNAMENODE_OPTS="-Dhadoop.security.logger=\${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=\${HDFS_AUDIT_LOGGER:-INFO,NullAppender} \$HADOOP_SECONDARYNAMENODE_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
EOF

echo "config hadoop-env.sh finished..."

3.配置hdfs-site.xml

#! /bin/bash

## filename: config-core-site.sh
## author: hyy
## date: 2021-5-21
## desc: config the file hdfs-site.xml

## the path of hdfs-site.xml
file_path=${hadoop_dir}/etc/hadoop/hdfs-site.xml

## config the content
cat << EOF > ${file_path}
<?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>
EOF

echo "config hdfs-site.xml finished..."

4.免密操作

ssh-keygen
## 过程中一直回车就好
ssh-copy-id [本机的ip地址]
## 输入密码就好

5.格式化

## source 环境变量文件
source /etc/profile
## 格式化hdfs
hdfs namenode -fromat

6.启动

start-dfs.sh

关闭防火墙后可以正常访问http://[你的机器ip地址]:50070/
在这里插入图片描述
至此,伪分布式的hadoop搭建完成。

每天进步一点点,你终会成为你想成为的那个人!!!!

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值