hadoop,pySpark环境安装与运行实战《一》

2023-11-12

一、环境准备

环境最好再mac或者liunx环境搭建最为友好,不建议在windows上折腾。

1)安装java jdk

下载java jdk 并在~/.bash_profile配置,jdk  mac路径查找方式

#export JAVA_HOME=/Users/wangyun/Documents/BigData/App/jdk1.8.0_60
#export PATH=$JAVA_HOME/bin:$PATH

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
export CLASS_PATH=$JAVA_HOME/lib

输入:java -version验证环境

2)安装scala

下载scala 并在~/.bash_profile配置环境变量,并source ~/.bash_profile

export SCALA_HOME=/Users/wangyun/Documents/BigData/App/scala-2.13.2
export PATH=$SCALA_HOME/bin:$PATH

输入:scala -version验证

3)安装 hadoop

下载hadoop 并在~/.bash_profile配置环境变量,并source ~/.bash_profile

export HADOOP_HOME =/Users/wangyun/Documents/BigData/App/hadoop-2.10
export PATH=$HADOOP_HOME/bin:$PATH

4)安装spark

下载spark 并在~/.bash_profile配置环境变量,并source ~/.bash_profile

export SPARK_HOME=/Users/wangyun/Documents/BigData/App/spark-3.0.0-preview2-bin-hadoop2.7
export PATH=$SPARK_HOME/bin:$PATH
export PYSPARK_PYTHON=python3

二、hadoop配置

进入

hadoop/etc/hadoop/目录 文件配置
hadoop-env.sh 增加:export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home

# 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}

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/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.


core-site.xml  增加

<property>
  <name>fs.default.name</name>
  <value>hdfs://127.0.0.1:8020</value>
</property>

<?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>fs.default.name</name>
  <value>hdfs://127.0.0.1:8020</value>
</property>
</configuration>


hdfs-site.xml  增加三组 property

<?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.namenode.name.dir</name>
   <value>/Users/wangyun/Documents/BigData/App/tmp/dfs/name</value>
 </property>

 <property>
   <name>dfs.datanode.data.dir</name>
   <value>/Users/wangyun/Documents/BigData/App/tmp/dfs/data</value>
 </property>

 <property>
   <name>dfs.replication</name>
   <value>1</value>
 </property>

</configuration>


mapred-site.xml   增加一组 property

<?xml version="1.0"?>
<?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>mapreduce.framework.name</name>
    <value>yarn</value>
  </property>
</configuration>


yarn-site.xml 增加 property

<?xml version="1.0"?>
<!--
  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.
-->
<configuration>

<!-- Site specific YARN configuration properties -->
   <property>
      <name>yarn.nodemanager.aux-services</name>
      <value>mapr educe_shuffle</value>
   </property>
</configuration>

到此hadoop配置完成

初始化: 进入hadoop bin目录

mac 出现Starting namenodes on [localhost]
localhost: ssh: connect to host localhost port 22: Connection refused
localhost: ssh: connect to host localhost port 22: Connection refused
Starting secondary namenodes [0.0.0.0]
0.0.0.0: ssh: connect to host 0.0.0.0 port 22: Connection refused报错参见 https://blog.csdn.net/wywinstonwy/article/details/105996077

./hadoop nodename -format

启动dfs sbin目录 启动报错的情况之一

./start-dfs.sh

查看文件夹
./hadoop fs -ls /
创建文件夹
./hadoop fs -mkdir /test

 

上传文件:
./hadoop fs -put /Users/wangyun/Desktop/lala.txt /test/

查看文件
./hadoop fs -ls /test

读取文件
./hadoop fs -text /test/lala.txt

 

访问: http://127.0.0.1:50070/explorer.html#/test

 

驱动yarn,sbin目录下
执行:./start-yarn.sh
访问:http://127.0.0.1:8088/cluster

进入spark bin目录启动spark
./spark-shell

Spark context Web UI available at http://bogon:4040
Spark context available as 'sc' (master = local[*], app id = local-1588985838107).
Spark session available as 'spark'.

注意:端口占用会自动+1

 

启动pySpark   bin目录
./pyspark  默认启动的是python 2
需要就该配置文件
修改spark-env.sh文件,在末尾添加
PYSPARK_PYTHON=/usr/bin/python3    实际的路径地址

到此spark相关配置和启动完成,可进入编程模式,参见官网写个简单demo

 

data =[1,2,3,4,5]
distData = sc.parallelize(data)
print(distData.collect())

创建spark001.py 测试demo

from pyspark import SparkContext,SparkConf

if __name__ =="__main__":
    conf = SparkConf().setMaster("local[2]").setAppName('spark002')
    sc = SparkContext(conf=conf)
    #map 算子
    def mymap():
        data = [1,2,3,4,5]
        rdd1 = sc.parallelize(data)
        rdd2 = rdd1.map(lambda x:x*2)
        print(rdd2.collect())

    def mymap2():
        a = ['dog','pig','tiger','lion','cat','bird','dog']
        rdd1 = sc.parallelize(a)
        rdd2 = rdd1.map(lambda x:(x,1))
        print(rdd2.collect())

    def myfilter():
        data = [1,2,3,4,5]
        rdd1 = sc.parallelize(data)
        mapRdd = rdd1.map(lambda x:x*2)
        filterRdd = mapRdd.filter(lambda x:x>5)
        print(filterRdd.collect())
        #简化写法
        # rdd = rdd1.map(lambda x:x*2).filter(lambda x:x>5)
        # print(rdd.collect())

    def myflatMap():
        data =['hello spark','hello world','hello world']
        rdd1 = sc.parallelize(data)
        rdd2 = rdd1.flatMap(lambda line:line.split(" "))
        print(rdd2.collect())

    def mygroupByKey():
         data = ['hello spark', 'hello world',
                 'hello world']
         rdd1 = sc.parallelize(data)
         rdd2 = rdd1.flatMap(
             lambda line: line.split(" ")).map(lambda x:(x,1))
         groupRdd = rdd2.groupByKey()

         print(groupRdd.collect())
         print(groupRdd.map(lambda x:{x[0]:list(x[1])}).collect())

    def myReduceByKey():
        data = ['hello spark', 'hello world',
                'hello world']
        rdd1 = sc.parallelize(data)
        rdd2 = rdd1.flatMap(
            lambda line: line.split(" ")).map(
            lambda x: (x, 1))
        reduceByKeyRdd = rdd2.reduceByKey(lambda x,y:x+y)
        print(reduceByKeyRdd.collect())
    myReduceByKey()


    sc.stop()

 

相关推荐:

hadoop,pySpark环境安装与运行实战《一》
Spark RDD操作,常用算子《二》
PySpark之算子综合实战案例《三》
Spark运行模式以及部署《四》
Spark Core解析《五》
PySpark之Spark Core调优《六》
PySpark之Spark SQL的使用《七》
 

 

 

持续更新中...

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

hadoop,pySpark环境安装与运行实战《一》 的相关文章

  • 如何使用 cython 编译扩展?

    我正在尝试从示例页面编译一个简单的 cython 扩展here http docs cython org src userguide tutorial html在我安装了 Python 2 6 64 位版本的 Windows 7 64 位计
  • Django:如何测试“HttpResponsePermanentRedirect”

    我正在为我的 django 应用程序编写一些测试 在我看来 它使用 HttpResponseRedirect 重定向到其他一些网址 那么我该如何测试呢 姜戈TestCase类有一个方法assertRedirects https docs d
  • 行未从树视图复制

    该行未在树视图中复制 我在按行并复制并粘贴到未粘贴的任何地方后制作了弹出复制 The code popup tk Menu tree opportunity tearoff 0 def row copy item tree opportun
  • 在Python3.6中调用C#代码

    由于完全不了解 C 编码 我希望在我的 python 代码中调用 C 函数 我知道有很多关于同一问题的问答 但由于一些奇怪的原因 我无法从示例 python 模块导入简单的 c 类库 以下是我所做的事情 C 类库设置 我使用的是 VS 20
  • 一次将Python dict的内容分配给多个变量?

    我想做这样的事情 def f return a 1 b 2 c 3 a b f or a b f IE 这样 a 被分配为 1 b 被分配为 2 并且 c 是未定义的 这与此类似 def f return 1 2 a b f 依赖于变量名称
  • Python BeautifulSoup XML 解析

    我编写了一个简单的脚本来使用 BeautifulSoup 模块解析 XML 聊天日志 标准 soup prettify 工作正常 只是聊天日志中有很多绒毛 您可以在下面看到我正在使用的脚本代码和一些 XML 输入文件 Code import
  • Paramiko - 使用私钥连接 - 不是有效的 OPENSSH 私钥/公钥文件

    我正在尝试找到解决方案 但无法理解我做错了什么 在我的 Linux 服务器上 我运行了以下命令 ssh keygen t rsa 这产生了一个id rsa and id rsa pub file 然后我将它们复制到本地并尝试运行以下代码 s
  • 如何限制Django CreateView中ForeignKey字段的选择?

    我有一个沿着这些思路的模型结构 models py class Foo models Model class Bar models Model foo models ForeignKey Foo class Baz models Model
  • Python Kivy - 在本机网络浏览器中打开 url 的应用程序

    我尝试制作一个简单的应用程序 在单击 Screen One 上的按钮后 在 Kivy 中打开一个网页 我使用了这个主题 Python 在应用程序中直接显示网络浏览器 iframe https stackoverflow com questi
  • 如何列出 python PDB 中的当前行?

    在 perl 调试器中 如果重复列出离开当前行的代码段 可以通过输入命令返回到当前行 点 我无法使用 python PDB 模块找到任何类似的东西 如果我list如果我自己离开当前行并想再次查看它 似乎我必须记住当前正在执行的行号 对我来说
  • Pandas Dataframe:将包含列表的行扩展到多行,并为所有列提供所需的索引

    我在 pandas 数据框中有时间序列数据 索引为测量开始时的时间 列中包含以固定采样率记录的值列表 连续索引 列表中元素数量的差异 这是它的样子 Time A B Z 0 1 2 3 4 1 2 3 4 2 5 6 7 8 5 6 7 8
  • 在 MacO 和 Linux 上安装 win32com [重复]

    这个问题在这里已经有答案了 我的问题很简单 我可以安装吗win32com蟒蛇API pywin32特别是 在非 Windows 操作系统上 我一直在Mac上尝试多个版本pip install pywin32 都失败了 下面是一个例子 如果你
  • Airflow Python 单元测试?

    我想为我们的 DAG 添加一些单元测试 但找不到任何单元测试 有 DAG 单元测试框架吗 有一个端到端的测试框架存在 但我猜它已经死了 https issues apache org jira browse AIRFLOW 79 https
  • 导入错误:没有名为 google.auth 的模块

    当我尝试导入时firebase admin in python 2 7我收到错误 导入错误 没有名为 google auth 的模块 这是Docker文件 https github com ammaratef45 Attendance bl
  • 如何在与应用程序初始化文件不同的文件中迭代 api 路由

    我有一个 apiroutes py 文件 其中定义了许多路由 例如 api route api read methods GET api route api write methods POST 其中 api 是导入 from import
  • 如何通过字符串匹配加速 pandas 行过滤?

    我经常需要过滤 pandas 数据框df by df df col name string value 并且我想加快行选择操作 有没有快速的方法可以做到这一点 例如 In 1 df mul df 3000 2000 3 reset inde
  • 为什么实现 __iter__ 的对象不被识别为可迭代的?

    假设您使用包装对象 class IterOrNotIter def init self self f open tmp toto txt def getattr self item try return self getattribute
  • 张量流:注册 numpy bfloat16 扩展

    正如我所见 tensorflow 中有 bfloat16 的 numpy 扩展 https github com tensorflow tensorflow blob 24ffe9f729160a095a5cab8f592392018280
  • 如何禁止 celery 中的 pickle 序列化

    Celery 默认使用 pickle 作为任务的序列化方法 如中所述FAQ http ask github com celery faq html isn t using pickle a security concern 这代表一个安全漏
  • 在 Python 模块中使用 InstaLoader

    我正在尝试使用 Instaloader 下载与主题标签相关的照片以进行图像分析 我在GitHub存储库中找到了一个全面的方法 如何在终端中执行它 但是 我需要将脚本集成到Python笔记本中 这是脚本 instaloader no vide

随机推荐

  • linux汇编编译器:GAS和NASM的比较

    GAS即GNU AS汇编编译器 其属于AT T风格 我们常用的GNU的产品还有GCC G NASM是Linux平台下常用的汇编编译器 是intel风格的汇编编译器 MASM是Windows平台下的汇编编译器 也使用Intel风格 我们学80
  • C语言之简单版本银行储蓄系统4(结构体版本)

    1 老学长的唠叨 在上一个编的数组版本的简化银行系统的基础上改为结构体存储 为还没有学到结构体的学弟学妹们提供一个迁就的方案 现在将程序改为结构体存储了 也希望学弟学妹们有个c语言学习缓冲的时间 这个代码没有用多文件组织的目的是方便代码的拷
  • STM32-CubeMx-HAL库-串口空闲中断+DMA——利用HAL_UARTEx_ReceiveToIdle_DMA实现不定长数据接收

    STM32 CubeMx HAL库 串口空闲中断 DMA 利用HAL UARTEx ReceiveToIdle DMA实现不定长数据接收 1 主要函数 2 CubeMX配置 2 1 在串口配置中添加DMA USART Rx 2 2 中断设置
  • CTP的交易指令类型

    在入场进行期货交易的时候 我们会向期货交易所放送订单 除了最基本的多空方向以及价格之外 订单还有不同的执行时机 触发条件 和执行方式 不清楚不同交易订单的特性 很容易造成本来可以避免的交易损失 我花点时间捋一遍CTP系统支持的不同种类的交易
  • 右值引用

    文章目录 一 右值引用简介 二 右值引用的使用 三 性能优化 一 右值引用简介 C 11增加了一个新的类型 称为右值引用 R value reference 标记为 在介绍右值引用类型之前要先了解什么是左值和右值 lvalue是locato
  • Git patch生成以及更新的命令

    1 使用git format patch生成所需要的patch 当前分支所有超前master的提交 git format patch M master 某次提交以后的所有patch git format patch 4e16 4e16指的是
  • VS2019+QGIS开发库二次开发环境搭建

    VS2019 QGIS开发库二次开发环境搭建 总共分为以下步骤 下载qgis和二次开发库 VS2019搭建开发环境 配置VS2019中的Qt插件 配置完Qt版本后对工程属性进行配置 编写测试代码 运行测试代码 拷贝运行程序需要用的动态库文件
  • ajax改变input框属性,ajax怎么实现输入框文字改变展示下拉列表的效果

    ajax怎么实现输入框文字改变展示下拉列表的效果 发布时间 2021 07 26 18 16 59 来源 亿速云 阅读 72 作者 chen 本篇内容主要讲解 ajax怎么实现输入框文字改变展示下拉列表的效果 感兴趣的朋友不妨来看看 本文介
  • 考研刷题小程序

    2020年12月28号 今年的考研已于昨天结束 小肥羊携手考研刷题小程序 祝各位考研学子一战上岸 话说2020年我开发了一个考研刷题小程序 今天非常好奇 竟然还有人在刷题 在签到打卡 在邀请好友 1 这个刷题小程序从2020年年初开发到6月
  • JQ源码分析(环境处理)

    JQ可以在哪运行 浏览器 手机端app中 有window环境 不支持commonJS规范 支持es6 module规范 node环境 没有window 支持commonJS 但不支持Es6Module 可以用webpack进行编译 支持wi
  • c++中的vector容器(笔记练习)

    笔记 1 about vector vector是可变大小数组的序列容器 同数组一样 vector也采用连续存储空间存储元素 因此可采用下标对元素进行访问 与普通数组不同的是 它的大小是可动态改变 vector使用动态数组存储元素 与其它动
  • 【黑马程序员】MySQL 基础篇

    文章目录 前言 一 MySQL 概述 1 数据库相关概念 2 MySQL 数据库 1 版本 2 下载 3 安装 4 启动与停止 5 客户端连接 3 数据模型 1 关系型数据库 RDBMS 2 数据模型 二 SQL 1 SQL 通用语法 2
  • 企业应如何减少云配置错误?

    在当今技术驱动的环境中 大多数公司都会在云上拥有一些工作负载 与本地网络不同 这些云环境缺乏安全的外部边界和特定的关闭时间 云网络始终开启且始终可用 虽然方便 但这也意味着黑客可以随时访问它们 因此 这些网络中的任何漏洞 例如云配置错误 都
  • 项目回顾(一)-----原型的建立

    距离实习结束也有一段时间了 这段时间里我从前到后参加的过的一个项目 收获颇丰 故在博客中自我总结 积累经验 从了解到需求开始 就要开始着手思考功能 功能联系 数据存储等问题 根据客户的需求来进行原型的设计 这一步操作不单单是给客户一个样例
  • Java JDK动态代理

    Java JDK动态代理 一 代理是什么 二 示例 三 总结 一 代理是什么 代理是一种设计模式 被代理对象 真实对象 实现具体的服务方法 委托给代理来进行处理 代理类可以在被代理对象的方法上附加更多的处理 一般有静态代理和动态代理 区别在
  • Rancher部署Flink集群

    目录 一 添加flink conf yaml 二 配置flink jobmanager 三 配置flink taskmanager 一 添加flink conf yaml 资源 gt 配置映射 添加配置项
  • 解决npm install各种报错的6种方案 Error: Command failed: cmd.exe autoreconf -ivf以及gifsicle pre-build test fail

    解决npm install各种报错的6种方案 报错示例 方案零 刷新刷新 DNS 解析缓存 还有 可以尝试重启电脑 方案一 使用yarn 方案二 使用cnpm 方案三 修改配置host 方案四 这种解决其他报错比较多 修改npm源 方案五
  • Jmeter查看结果树之查看响应的13种详解方法

    Jmeter查看结果树查看响应有哪几种方法 可通过左侧面板底部的下拉框选择 01 Text 查看结果树中请求的默认格式为Text 显示取样器结果 请求 响应数据3个部分内容 取样器结果 默认Raw展示 可以切换为Parsed视图 表单展示更
  • 域名导向服务器 开源项目,让 Page 服务指向自己域名

    正常情况下如果只买了域名 但是没有买云主机 所以可以利用现有的 Page 服务并让域名跳转到该Page来实现 码云 自定义域名是收费的 但是服务文档 推荐 码云pro版自定义域名解析 Step 1 绑定你已备案的域名 Step 2 通过解析
  • hadoop,pySpark环境安装与运行实战《一》

    一 环境准备 环境最好再mac或者liunx环境搭建最为友好 不建议在windows上折腾 1 安装java jdk 下载java jdk 并在 bash profile配置 jdk mac路径查找方式 export JAVA HOME U