《Hadoop系列》Hadoop实操记录

7 篇文章 0 订阅
3 篇文章 4 订阅

Hadoop实操记录

一、shell脚本配置伪分布式Hadoop

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

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

3.修改Hadoop配置文件

3.1 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

3.2 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 

3.3 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

4.帮助文档

启动命令: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 

二、数据直接上传到分区目录上,让分区表和数据产生关联的三种方式

1.上传数据后修复

  • 上传数据

dfs -mkdir -p /user/dept_partition/day=20210725/hour=8

dfs -put /opt/apps/dept_20210725.log /user/dept_partition/day=20210725/hour=8

  • 查询数据

select * from dept_partition where day=‘20210725’ and hour=‘8’

查询不到

  • 修复数据

msck repair table dept_partition;

  • 再次查询数据

select * from dept_partition where day=‘20210725’ and hour=‘8’

2.上传数据后添加分区

  • 上传数据

dfs -mkdir -p /user/dept_partition/day=20210725/hour=8

dfs -put /opt/apps/dept_20210725.log /user/dept_partition/day=20210725/hour=8

  • 添加分区

alter table ddept_partition add partition(day=‘20210725’,hour=‘8’)

  • 查询数据

select * from dept_partition where day=‘20210725’ and hour =‘8’

3.创建文件夹后load数据到分区

  • 上传数据

dfs -mkdir -p /user/dept_partition/day=20210725/hour=8

  • 上传数据

load data local inpath ‘/opt/apps/dept_20210725.log’ into table dept_partiton partition(day=‘20210725’,hour=‘8’)

  • 查询数据

select * from dept_partition where day=‘20210725’ and hour =‘8’

  • 8
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 13
    评论
### 回答1: 大数据开发工程师系列是指专门从事大数据开发的一类职业。Hadoop和Spark是大数据领域中最受欢迎的两个开源框架。 Hadoop是一个分布式计算框架,用于处理大规模数据集的分布式存储和计算。Hadoop的核心是Hadoop分布式文件系统(HDFS)和MapReduce计算模型。HDFS将数据分布存储在集群的多个节点上,MapReduce可以并行处理这些分布式数据。Hadoop具有高可靠性、高扩展性和高容错性的特点,并且还提供了许多其他工具和库,如Hive、Pig和HBase等。 Spark是一个快速、通用的大数据处理引擎,可以在多种数据源上进行高效的分布式计算。相比于Hadoop的MapReduce,Spark具有更快的数据处理速度和更强的扩展性。Spark提供了一个称为弹性分布式数据集(RDD)的抽象,可以在内存中高效地处理大规模数据集。此外,Spark还提供了许多高级组件和库,如Spark SQL、Spark Streaming和MLlib等,用于处理结构化数据、流式数据和机器学习。 作为大数据开发工程师,掌握Hadoop和Spark是非常重要的。使用Hadoop可以处理海量数据,并且具有高可靠性和容错性。而Spark则能够快速高效地处理大规模数据,并提供了更多的数据处理和分析功能。 大数据开发工程师需要熟悉Hadoop和Spark的使用和调优技巧,以及相关的编程语言和工具,如Java、Scala和Python。他们需要了解数据处理的算法和模型,并能够设计和实现高效的分布式计算方案。此外,大数据开发工程师还需要具备良好的沟通能力和团队合作能力,能够与数据科学家和业务团队紧密合作,共同解决实际问题。 总之,大数据开发工程师系列是一个专门从事大数据开发的职业群体。而Hadoop和Spark则是这个职业群体中最重要的两个工具,他们分别用于大规模数据处理和分布式计算。掌握Hadoop和Spark的使用和优化技巧,是成为一名优秀的大数据开发工程师的关键能力。 ### 回答2: 大数据开发工程师系列主要涉及到两个重要的技术:Hadoop和Spark。 Hadoop是一个开源的分布式计算框架,主要用于存储和处理大规模数据集。它通过将数据分散存储在集群中的多个节点上,并在节点之间进行数据通信和计算,实现了数据的并行处理和高可靠性。Hadoop的核心工具是HDFS(Hadoop分布式文件系统)和MapReduce(一种用于分布式计算的编程模型)。HDFS用于将数据分布式存储在集群中,而MapReduce则是用于分布式计算的框架,通过将计算任务分解成多个小任务并在各个节点上并行执行,大大提高了数据处理的效率和性能。 Spark是当前最受欢迎的大数据计算框架之一,也是一个开源项目。与Hadoop相比,Spark具有更快的数据处理速度和更强大的功能。Spark提供了一个可扩展的分布式数据处理框架,支持数据处理、机器学习、图计算等多种大数据应用场景。与传统的基于磁盘的计算框架相比,Spark利用内存计算的优势,可以快速地对大规模数据进行处理和分析。此外,Spark还提供了丰富的API和开发工具,使开发人员可以更轻松地构建和调试大数据应用程序。 作为大数据开发工程师,掌握Hadoop和Spark是必不可少的。熟悉Hadoop的使用和原理,能够有效地存储和处理大规模数据集。而对于Spark的掌握,则可以提高数据处理的速度和效率,使得大数据分析和挖掘更加容易实现。因此,大数据开发工程师需要具备对Hadoop和Spark的深入理解和熟练应用,同时还需要具备数据分析、算法和编程等多方面的技能,以应对复杂的大数据挑战。 ### 回答3: 大数据开发工程师是一个专注于处理大数据的职位,主要负责使用各种工具和技术来处理和分析大规模的数据集。 Hadoop和Spark是目前在大数据处理领域中非常流行的两个开源工具。Hadoop是一个分布式系统基础架构,可以在集群中存储和处理大规模数据。它的核心是Hadoop分布式文件系统(HDFS)和MapReduce计算模型。HDFS将数据分散存储在集群的不同节点上,而MapReduce模型则提供了一种并行处理数据的方式。大数据开发工程师需要熟悉Hadoop的架构和命令行工具,能够编写MapReduce程序来处理数据。 Spark是一个快速和通用的大数据处理引擎,可以在大规模集群上执行数据处理任务。它拥有比Hadoop更高的性能和更丰富的功能。Spark提供了强大的机器学习、图计算和流处理等功能。大数据开发工程师需要熟悉Spark的API和编程模型,能够使用Spark的各种组建和工具进行数据处理和分析。 作为大数据开发工程师,掌握Hadoop和Spark是非常重要的。使用Hadoop和Spark可以有效地处理大规模数据,提取有价值的信息。大数据开发工程师通过编写和优化MapReduce程序来实现数据处理的需求,同时也能利用Spark提供的机器学习和流处理等功能来进行更复杂的数据分析。通过合理地使用Hadoop和Spark,大数据开发工程师可以减少数据处理的时间和成本,提高数据处理的效率和准确性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DATA数据猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值