spark

单机启动 spark-shell
集群启动

/usr/local/spark-2.4.5-bin-hadoop2.7/sbin/start-all.sh

提交任务
1.打包python环境:

whereis python
# /usr/local/python3/

zip -r py_env.zip py_env
2.spark提交
参考:
pyspark打包依赖包&使用python虚拟环境

notebook集成:https://blog.csdn.net/qq_42899028/article/details/101918056

PYSPARK_PYTHON 写python而不是python3

export PYSPARK_PYTHON=python # 指定的是python3
export PYSPARK_DRIVER_PYTHON=jupyter
export PYSPARK_DRIVER_PYTHON_OPTS=“notebook”

开发部署spark应用有三步:
1.编写spark应用
2.使用sbt,maven构建应用
4.使用spark submit脚本部署
spark submit脚本支持选项

spark-submit --help

sage: spark-submit [options] <app jar | python file | R file> [app arguments]
Usage: spark-submit --kill [submission ID] --master [spark://...]
Usage: spark-submit --status [submission ID] --master [spark://...]
Usage: spark-submit run-example [options] example-class [example args]

Options:
  --master MASTER_URL         spark://host:port, mesos://host:port, yarn,
                              k8s://https://host:port, or local (Default: local[*]).
  --deploy-mode DEPLOY_MODE   Whether to launch the driver program locally ("client") or
                              on one of the worker machines inside the cluster ("cluster")
                              (Default: client).
  --class CLASS_NAME          Your application's main class (for Java / Scala apps).
  --name NAME                 A name of your application.
  --jars JARS                 Comma-separated list of jars to include on the driver
                              and executor classpaths.
  --packages                  Comma-separated list of maven coordinates of jars to include
                              on the driver and executor classpaths. Will search the local
                              maven repo, then maven central and any additional remote
                              repositories given by --repositories. The format for the
                              coordinates should be groupId:artifactId:version.
  --exclude-packages          Comma-separated list of groupId:artifactId, to exclude while
                              resolving the dependencies provided in --packages to avoid
                              dependency conflicts.
  --repositories              Comma-separated list of additional remote repositories to
                              search for the maven coordinates given with --packages.
  --py-files PY_FILES         Comma-separated list of .zip, .egg, or .py files to place
                              on the PYTHONPATH for Python apps.
  --files FILES               Comma-separated list of files to be placed in the working
                              directory of each executor. File paths of these files
                              in executors can be accessed via SparkFiles.get(fileName).
  --archives ARCHIVES         Comma-separated list of archives to be extracted into the
                              working directory of each executor.

  --conf, -c PROP=VALUE       Arbitrary Spark configuration property.
  --properties-file FILE      Path to a file from which to load extra properties. If not
                              specified, this will look for conf/spark-defaults.conf.

  --driver-memory MEM         Memory for driver (e.g. 1000M, 2G) (Default: 1024M).
  --driver-java-options       Extra Java options to pass to the driver.
  --driver-library-path       Extra library path entries to pass to the driver.
  --driver-class-path         Extra class path entries to pass to the driver. Note that
                              jars added with --jars are automatically included in the
                              classpath.

  --executor-memory MEM       Memory per executor (e.g. 1000M, 2G) (Default: 1G).

  --proxy-user NAME           User to impersonate when submitting the application.
                              This argument does not work with --principal / --keytab.

  --help, -h                  Show this help message and exit.
  --verbose, -v               Print additional debug output.
  --version,                  Print the version of current Spark.

 Cluster deploy mode only:
  --driver-cores NUM          Number of cores used by the driver, only in cluster mode
                              (Default: 1).

 Spark standalone or Mesos with cluster deploy mode only:
  --supervise                 If given, restarts the driver on failure.

 Spark standalone, Mesos or K8s with cluster deploy mode only:
  --kill SUBMISSION_ID        If given, kills the driver specified.
  --status SUBMISSION_ID      If given, requests the status of the driver specified.

 Spark standalone, Mesos and Kubernetes only:
  --total-executor-cores NUM  Total cores for all executors.

 Spark standalone, YARN and Kubernetes only:
  --executor-cores NUM        Number of cores used by each executor. (Default: 1 in
                              YARN and K8S modes, or all available cores on the worker
                              in standalone mode).

 Spark on YARN and Kubernetes only:
  --num-executors NUM         Number of executors to launch (Default: 2).
                              If dynamic allocation is enabled, the initial number of
                              executors will be at least NUM.
  --principal PRINCIPAL       Principal to be used to login to KDC.
  --keytab KEYTAB             The full path to the file that contains the keytab for the
                              principal specified above.

 Spark on YARN only:
  --queue QUEUE_NAME          The YARN queue to submit to (Default: "default").

hadoop

介绍

Hadoop是一个能够对大量数据进行分布式处理的软件框架。

特性:
高可靠、高有效性、高扩展性、高容错性、
成本低、linux平台上运行、支持多种编程语言。

基于几个重要概念:
成本:

  • 以软件形式来容错比通过硬件实现更便宜
  • 使用上用服务器集群来同时存储和处理大量数据比使用高端服务器便宜

易用性:

  • 把核心数据处理逻辑和分布式计算逻辑分开,使得编写一个分布式应用更简单。
  • 通过网络把信息传输到另一台计算机比移动大数据集更有效快速。

组成:集群管理器(YARN)、分布式计算引擎(MapReduce)、分布式文件系统(HDFS)

HDFS

用来存储和访问大文件与大数据集。

  • 一个可扩展可容错的系统
  • 一个块结构的文件系统(把文件分成固定大小的块,默认128MB)

实现方式:
HDFS集群包括两种类型的节点:
NameNode存储一个文件所有元数据,比如追踪 文件名、权限和文件块位置。NameNode把所有元数据都存储在内存中。NameNode周期性接受HDFS集群中DataNode两种类型信息,心跳信息(是否工作正常)、块报告信息(包含一个DataNode上所有数据块的列表)

DataNode
以文件块的形式存储实际的文件内容。

MapReduce

作用:抽象了集群计算,提供了分布式数据处理应用的高级结构,使得程序员可以关注于数据处理的逻辑本身

实现方式:自动在集群中各计算机上调度应用的执行,它会处理负载均衡、节点迭机、复杂的节点内通信。

组成:map,reduce
map函数以键值对作为输入,输出中间产物键值对,对输入数据集中每一个键值对调用map函数,接下来对map函数的输出进行排序,根据值进行分组,作为输入传给reduce函数,reduce函数聚合值,输出最终聚合值。

优缺点:
用于处理批量数据,有大吞吐量和高延迟
缺点:不适合交互式查询
低延迟的分布式SQL查询引擎有:
Impala、Presto(一个高性能的、分布式的大数据SQL查询引擎。Presto非常有特色的一点就是,它支持的数据源非常多。例如:Hadoop、AWS S3、Alluxio、MySQL、Cassandra、Kafka、ES、Kudu、MongoDB、MySQL等等。就是在市面能看到的存储,它基本上都支持。而对比Impala却没有支持这么多的组件。Trino 是一个分布SQL查询引擎,设计用来查询大的分布式数据集,分布在一个或更多不同总类的数据源.)、Drill

hadoop常用命令

启动hadoop

/usr/local/hadoop-2.7.7/sbin/start-all.sh

web访问http://50070端口

文件常用操作

参考:https://blog.csdn.net/ywl470812087/article/details/100589940
https://blog.csdn.net/suixinlun/article/details/81630902
总结

hdfs dfs  查看Hadoop HDFS支持的所有命令   
hdfs dfs –ls  列出目录及文件信息   
hdfs dfs –lsr  循环列出目录、子目录及文件信息      
hdfs dfs –tail /user/sunlightcs/test.txt  查看最后1KB的内容   

hdfs dfs –copyFromLocal test.txt /user/sunlightcs/test.txt  从本地文件系统复制文件到HDFS文件系统,等同于put命令   
hdfs dfs –copyToLocal /user/sunlightcs/test.txt test.txt  从HDFS文件系统复制文件到本地文件系统,等同于get命令   

hdfs dfs –chgrp [-R] /user/sunlightcs  修改HDFS系统中/user/sunlightcs目录所属群组,选项-R递归执行,跟linux命令一样   
hdfs dfs –chown [-R] /user/sunlightcs  修改HDFS系统中/user/sunlightcs目录拥有者,选项-R递归执行   
hdfs dfs –chmod [-R] MODE /user/sunlightcs  修改HDFS系统中/user/sunlightcs目录权限,MODE可以为相应权限的3位数或+/-{rwx},选项-R递归执行

hdfs dfs –count [-q] PATH  查看PATH目录下,子目录数、文件数、文件大小、文件名/目录名   
hdfs dfs –cp SRC [SRC …] DST       将文件从SRC复制到DST,如果指定了多个SRC,则DST必须为一个目录   
hdfs dfs –du PATH  显示该目录中每个文件或目录的大小   
hdfs dfs –dus PATH  类似于du,PATH为目录时,会显示该目录的总大小   

hdfs dfs –expunge  清空回收站,文件被删除时,它首先会移到临时目录.Trash/中,当超过延迟时间之后,文件才会被永久删除   

hdfs dfs –getmerge SRC [SRC …] LOCALDST [addnl]   获取由SRC指定的所有文件,将它们合并为单个文件,并写入本地文件系统中的LOCALDST,选项addnl将在每个文件的末尾处加上一个换行符   

hdfs dfs –test –[ezd] PATHPATH进行如下类型的检查:-e PATH是否存在,如果PATH存在,返回0,否则返回1;-z 文件是否为空,如果长度为0,返回0,否则返回1; -d 是否为目录,如果PATH为目录,返回0,否则返回1  

hdfs dfs –text PATH  显示文件的内容,当文件为文本文件时,等同于cat;文件为压缩格式(gzip以及hadoop的二进制序列文件格式)时,会先解压缩    

hdfs dfs –help ls  查看某个[ls]命令的帮助文档

上传、删除文件
# hdfs dfs -put [本地目录] [hadoop目录]
hdfs dfs -put xxx/py_env.zip /user/xxx/

显示hadoop目录结构

#hdfs dfs -ls [文件目录]
hdfs dfs -ls -R /

在hadoop指定目录内创建新目录

hdfs dfs -mkdir /folder

将hadoop上某个文件重命名

hdfs dfs -mv /xxx/xxx.txt /xxx/xxx.txt

删除hadoop上指定文件夹(包含子目录等)

hdfs dfs -rm -r [目录地址]
hdfs dfs -rmr [目录地址]

删除hadoop上指定文件

hdfs dfs -rm [文件地址]

在hadoop指定目录下新建一个空文件

hdfs dfs -touchz /***/***.txt

打开某个已存在文件

hdfs dfs -cat [file_path]
查看
hadoop job 

将正在运行的hadoop作业kill掉

hadoop job -kill [job-id]

查看帮助

hdfs dfs -help
下载文件

将hadoop上某个文件down至本地已有目录下

hdfs dfs -get [文件目录] [本地目录]

将hadoop指定目录下所有内容保存为一个文件,同时down至本地

hdfs dfs -getmerge /winnie/hadoop-file /home/spark/hadoop-file/test.txt
安全模式

退出

/usr/local/hadoop-2.7.7/bin/hadoop dfsadmin -safemode leave

进入

./hadoop dfsadmin -safemode enter

hive

数据仓库软件,提供了类SQL语言处理和分析 在HDFS或其他兼容Hadoop的存储系统中的数据。

Hive提供了一种极致吧对应结构映射到存储在HDFS中的数据,并用HiveQL来查询。在底层会把Hiveql查询转换为MapReduce作业,支持UDF (用户定义函数)和 UDAS(用户定义聚合函数)。

概念

数据序列化

序列化:把内存中的数据转换为可在硬盘上存储或通过网络发送的过程叫做序列化,而把硬盘或网络中的数据读取到内存的过程叫反序列化。

对于大数据集文本和二进制格式的序列化/反序列化时间和存储空间差异极大,因此首选二进制格式存储大数据集(二进制格式更加紧凑,在解析上比文本格式更快)。

  • Avro 自描述的二进制格式,模式与数据同时存储,模式使用JSON描述
  • Thrift
  • Protocol Buffer
  • SequenceFile

列存储

数据可以面向行或面向列的格式来存储。
面向行存储对于分析类应用(对列进行操作)不够高效,造成内存、CPU周期、磁盘I/O的浪费。另一个缺点是数据无法高效压缩。

  • RCFile
  • OCR 保存行索引,基于数据采用块模式压缩
  • Parquet 支持多种数据编码和压缩计算

消息系统

数据通常由一个应用流向另一个,一个应用产生数据,而后被一个或多个应用使用。生成或发生数据的应用叫做生产者,接收数据的叫做消费者。有时候,产生数据的应用/速率数量和使用数据的应用数量/速率会出现不对称。

发送数据简单方式是互联,但是不对称是情况就不行了,使用消息代理或消息系统,应用无需直接互连,使得数据管道上添加生产者和消费者变得容易,也允许应用以不同速率来生成和使用数据。

KAFKA

分布式消息系统,分布式的、分块的、重复的提交日志服务,可以用来作为发布-订阅式消息系统

特点:高吞吐量、可扩展、持久性。

ZeroMQ

NoSQL

不只SQL

Cassandra

HBase

分布式、可扩展、容错的NoSQL数据集,用来存储大数据集。运行在HDFS上。
本质上是一个稀疏的、分布式、持久化、多维且有序的Map.

一个有序且多维的多层次的Map,行键(快读读取其中一行),列族,列名,时间戳。四层键组合唯一标识了一个单元,其中包含值,值是一个未解析的字节数组。

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐