Linux 之 Spark 環境部署筆記——Spark安裝

1.下載

下載地址:https://archive.apache.org/dist/spark/

2.解壓

將安裝包放入linux中,然後解壓

tar -zxvf spark-1.6.0-bin-hadoop2.6.tgz

修改文件夾名稱

mv spark-1.6.0-bin-hadoop2.6 spark-1.6.0

3.環境配置

1)進入編輯

sudo vi /etc/profile

2)配置如下環境變量

export SPARK_HOME=/vol6/home/nudt_cb/psl/spark-1.6.0
export PATH=$JAVA_HOME/bin:$SPARK_HOME/bin:$PATH

 3)刷新配置

source /etc/profile

4)修改spark-env.sh

a)重命名文件名

cp spark-env.sh.template spark-env.sh

b)修改文件內容

vi spark-env.sh
#!/usr/bin/env bash

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

# This file is sourced when running various Spark programs.
# Copy it as spark-env.sh and edit that to configure Spark for your site.

# Options read when launching programs locally with
# ./bin/run-example or ./bin/spark-submit
# - HADOOP_CONF_DIR, to point Spark towards Hadoop configuration files
# - SPARK_LOCAL_IP, to set the IP address Spark binds to on this node
# - SPARK_PUBLIC_DNS, to set the public dns name of the driver program
# - SPARK_CLASSPATH, default classpath entries to append

# Options read by executors and drivers running inside the cluster
# - SPARK_LOCAL_IP, to set the IP address Spark binds to on this node
# - SPARK_PUBLIC_DNS, to set the public DNS name of the driver program
# - SPARK_CLASSPATH, default classpath entries to append
# - SPARK_LOCAL_DIRS, storage directories to use on this node for shuffle and RDD data
# - MESOS_NATIVE_JAVA_LIBRARY, to point to your libmesos.so if you use Mesos

# Options read in YARN client mode
# - HADOOP_CONF_DIR, to point Spark towards Hadoop configuration files
# - SPARK_EXECUTOR_INSTANCES, Number of executors to start (Default: 2)
# - SPARK_EXECUTOR_CORES, Number of cores for the executors (Default: 1).
# - SPARK_EXECUTOR_MEMORY, Memory per Executor (e.g. 1000M, 2G) (Default: 1G)
# - SPARK_DRIVER_MEMORY, Memory for Driver (e.g. 1000M, 2G) (Default: 1G)
# - SPARK_YARN_APP_NAME, The name of your application (Default: Spark)
# - SPARK_YARN_QUEUE, The hadoop queue to use for allocation requests (Default: ‘default’)
# - SPARK_YARN_DIST_FILES, Comma separated list of files to be distributed with the job.
# - SPARK_YARN_DIST_ARCHIVES, Comma separated list of archives to be distributed with the job.

# Options for the daemons used in the standalone deploy mode
# - SPARK_MASTER_IP, to bind the master to a different IP address or hostname
# - SPARK_MASTER_PORT / SPARK_MASTER_WEBUI_PORT, to use non-default ports for the master
# - SPARK_MASTER_OPTS, to set config properties only for the master (e.g. "-Dx=y")
# - SPARK_WORKER_CORES, to set the number of cores to use on this machine
# - SPARK_WORKER_MEMORY, to set how much total memory workers have to give executors (e.g. 1000m, 2g)
# - SPARK_WORKER_PORT / SPARK_WORKER_WEBUI_PORT, to use non-default ports for the worker
# - SPARK_WORKER_INSTANCES, to set the number of worker processes per node
# - SPARK_WORKER_DIR, to set the working directory of worker processes
# - SPARK_WORKER_OPTS, to set config properties only for the worker (e.g. "-Dx=y")
# - SPARK_DAEMON_MEMORY, to allocate to the master, worker and history server themselves (default: 1g).
# - SPARK_HISTORY_OPTS, to set config properties only for the history server (e.g. "-Dx=y")
# - SPARK_SHUFFLE_OPTS, to set config properties only for the external shuffle service (e.g. "-Dx=y")
# - SPARK_DAEMON_JAVA_OPTS, to set config properties for all daemons (e.g. "-Dx=y")
# - SPARK_PUBLIC_DNS, to set the public dns name of the master or workers

# Generic options for the daemons used in the standalone deploy mode
# - SPARK_CONF_DIR      Alternate conf dir. (Default: ${SPARK_HOME}/conf)
# - SPARK_LOG_DIR       Where log files are stored.  (Default: ${SPARK_HOME}/logs)
# - SPARK_PID_DIR       Where the pid file is stored. (Default: /tmp)
# - SPARK_IDENT_STRING  A string representing this instance of spark. (Default: $USER)
# - SPARK_NICENESS      The scheduling priority for daemons. (Default: 0)

export JAVA_HOME=/vol6/appsoftware/jdk1.8.0_101
export SPARK_HOME=/vol6/home/nudt_cb/psl/spark-1.6.0
export SPARK_MASTER_ID=***.***.***.***
export SPARK_MASTER_PORT=7077
export SPARK_WORKER_MEMORY=2g

5)配置slaves

a)重命名文件名

cp slaves.template slaves

b)修改內容

vi slaves
#
# 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.
#

# A Spark Worker will be started on each of the machines listed below.
localhost

4 查看spark

[nudt_cb@ln1%tianhe ~]$ spark-shell
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Using Spark's repl log4j profile: org/apache/spark/log4j-defaults-repl.properties
To adjust logging level use sc.setLogLevel("INFO")
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /___/ .__/\_,_/_/ /_/\_\   version 1.6.0
      /_/

Using Scala version 2.10.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101)
Type in expressions to have them evaluated.
Type :help for more information.
Spark context available as sc.
20/05/28 22:38:46 WARN Connection: BoneCP specified but not present in CLASSPATH (or one of dependencies)
20/05/28 22:38:47 WARN Connection: BoneCP specified but not present in CLASSPATH (or one of dependencies)
20/05/28 22:38:51 WARN ObjectStore: Version information not found in metastore. hive.metastore.schema.verification is not enabled so recording the schema version 1.2.0
20/05/28 22:38:51 WARN ObjectStore: Failed to get database default, returning NoSuchObjectException
20/05/28 22:38:53 WARN Connection: BoneCP specified but not present in CLASSPATH (or one of dependencies)
20/05/28 22:38:53 WARN Connection: BoneCP specified but not present in CLASSPATH (or one of dependencies)
SQL context available as sqlContext.

scala> 

5.配置參數說明 

以下內容來自官網》》》》》》》》》

http://spark.apache.org/docs/latest/spark-standalone.html

要使用啓動腳本啓動Spark獨立集羣,您應該在Spark目錄中創建一個名爲conf / slaves的文件,該文件必須包含要啓動Spark Worker的所有計算機的主機名,每行一個。如果conf / slaves不存在,則啓動腳本默認爲單臺計算機(localhost),這對於測試非常有用。注意,主計算機通過ssh訪問每個工作計算機。默認情況下,ssh是並行運行的,並且需要設置無密碼(使用私鑰)訪問權限。如果您沒有無密碼設置,則可以設置環境變量SPARK_SSH_FOREGROUND併爲每個工作線程依次提供一個密碼。

設置完此文件後,您可以基於Hadoop的部署腳本,使用以下shell腳本啓動或停止集羣,該腳本可在SPARK_HOME/sbin

  • sbin/start-master.sh -在執行腳本的計算機上啓動主實例。
  • sbin/start-slaves.sh-在conf/slaves文件中指定的每臺計算機上啓動一個從屬實例。
  • sbin/start-slave.sh -在執行腳本的計算機上啓動從屬實例。
  • sbin/start-all.sh -如上所述,同時啓動一個主機和多個從機。
  • sbin/stop-master.sh-停止通過sbin/start-master.sh腳本啓動的主機。
  • sbin/stop-slaves.sh-停止conf/slaves文件中指定的機器上的所有從屬實例。
  • sbin/stop-all.sh -如上所述,停止主機和從機。

請注意,這些腳本必須在要在其上運行Spark master的計算機上執行,而不是在本地計算機上執行。

您可以選擇通過在中設置環境變量來進一步配置集羣conf/spark-env.sh。從開始以創建此文件conf/spark-env.sh.template,然後將其複製到所有輔助計算機上以使設置生效。可以使用以下設置:

環境變量 含義
SPARK_MASTER_HOST 將主服務器綁定到特定的主機名或IP地址,例如公共主機名或IP地址。
SPARK_MASTER_PORT 在另一個端口上啓動主服務器(默認:7077)。
SPARK_MASTER_WEBUI_PORT 主Web UI的端口(默認值:8080)。
SPARK_MASTER_OPTS 僅以“ -Dx = y”的形式應用於主服務器的配置屬性(默認值:無)。請參閱下面的可能選項列表。
SPARK_LOCAL_DIRS 用於Spark中“臨時”空間的目錄,包括映射輸出文件和存儲在磁盤上的RDD。它應該在系統中的快速本地磁盤上。它也可以是不同磁盤上多個目錄的逗號分隔列表。
SPARK_WORKER_CORES 允許Spark應用程序在計算機上使用的內核總數(默認值:所有可用內核)。
SPARK_WORKER_MEMORY 允許Spark應用程序在計算機上使用的內存總量,例如1000m2g(默認值:總內存減去1 GB);請注意,每個應用程序的單獨內存都是使用其spark.executor.memory屬性配置的。
SPARK_WORKER_PORT 在特定端口上啓動Spark worker(默認:隨機)。
SPARK_WORKER_WEBUI_PORT 輔助Web UI的端口(默認值:8081)。
SPARK_WORKER_DIR 要在其中運行應用程序的目錄,其中將包括日誌和暫存空間(默認值:SPARK_HOME / work)。
SPARK_WORKER_OPTS 僅以“ -Dx = y”的形式應用於工作程序的配置屬性(默認值:無)。請參閱下面的可能選項列表。
SPARK_DAEMON_MEMORY 分配給Spark主守護程序和輔助守護程序本身的內存(默認值:1g)。
SPARK_DAEMON_JAVA_OPTS Spark主服務器和輔助服務器守護程序的JVM選項本身以“ -Dx = y”的形式出現(默認值:無)。
SPARK_DAEMON_CLASSPATH Spark主守護程序和輔助守護程序本身的類路徑(默認值:無)。
SPARK_PUBLIC_DNS Spark主服務器和輔助服務器的公共DNS名稱(默認值:無)。

注意:啓動腳本當前不支持Windows。要在Windows上運行Spark集羣,請手動啓動master和worker。

SPARK_MASTER_OPTS支持以下系統屬性:

物業名稱 默認 含義
spark.deploy.retainedApplications 200 顯示的已完成申請的最大數量。較舊的應用程序將從UI中刪除,以保持此限制。
spark.deploy.retainedDrivers 200 要顯示的已完成驅動程序的最大數量。較舊的驅動程序將從UI刪除,以保持此限制。
spark.deploy.spreadOut 真正 獨立集羣管理器是應將應用程序分佈在各個節點上,還是應將它們合併到儘可能少的節點上。對於HDFS中的數據局部性而言,擴展通常更好,但對於計算密集型工作負載而言,整合更有效。
spark.deploy.defaultCores (無限的) 如果未設置,則以Spark獨立模式提供給應用程序的默認內核數spark.cores.max。如果未設置,則應用程序始終會獲得所有可用的內核,除非它們spark.cores.max自行配置。在共享羣集上將此值設置得較低,以防止用戶默認情況下抓取整個羣集。
spark.deploy.maxExecutorRetries 10 對獨立集羣管理器刪除有故障的應用程序之前可能發生的最大背對背執行器故障數的限制。如果應用程序具有正在運行的執行程序,則永遠不會將其刪除。如果應用程序spark.deploy.maxExecutorRetries連續遇到多個 故障,沒有執行程序成功地在這些故障之間開始運行,並且該應用程序沒有運行的執行程序,則獨立集羣管理器將刪除該應用程序並將其標記爲失敗。要禁用此自動刪除功能,請設置spark.deploy.maxExecutorRetries爲 -1
spark.worker.timeout 60 如果獨立部署主服務器未接收到心跳信號,則該秒數之後該秒數將其視爲丟失。

SPARK_WORKER_OPTS支持以下系統屬性:

物業名稱 默認 含義
spark.worker.cleanup.enabled 啓用定期清除worker /應用程序目錄。請注意,這僅影響獨立模式,因爲YARN的工作原理不同。僅清除已停止的應用程序的目錄。
spark.worker.cleanup.interval 1800(30分鐘) 控制工人清理本地計算機上舊的應用程序工作目錄的時間間隔(以秒爲單位)。
spark.worker.cleanup.appDataTtl 604800(7天,7 * 24 * 3600) 在每個工作程序上保留應用程序工作目錄的秒數。這是生存時間,應取決於您擁有的可用磁盤空間量。應用程序日誌和jars被下載到每個應用程序工作目錄。隨着時間的推移,工作目錄會迅速填滿磁盤空間,尤其是如果您非常頻繁地運行作業時。
spark.storage.cleanupFilesAfterExecutorExit 真正 在執行程序退出後,啓用工作目錄的清理非混洗文件(例如臨時混洗塊,緩存的RDD /廣播塊,溢出文件等)。請注意,這與`spark.worker.cleanup.enabled`不重疊,因爲這可以清除死掉執行者的本地目錄中的非隨機文件,而`spark.worker.cleanup.enabled`則可以清除所有文件。 /停止和超時應用程序的子目錄。這僅影響獨立模式,將來可以添加對其他集羣管理員的支持。
spark.worker.ui.compressedLogFileLengthCacheSize 100 對於壓縮日誌文件,只能通過解壓縮文件來計算未壓縮文件。Spark緩存壓縮日誌文件的未壓縮文件大小。此屬性控制緩存大小。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章