当前位置:   article > 正文

自动化安装部署hadoop_hadoop 自动化部署

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56

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..."

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

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..."

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124

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..."

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

4.免密操作

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

5.格式化

## source 环境变量文件
source /etc/profile
## 格式化hdfs
hdfs namenode -fromat
  • 1
  • 2
  • 3
  • 4

6.启动

start-dfs.sh
  • 1

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/403593
推荐阅读
相关标签
  

闽ICP备14008679号