본문 바로가기

보물창고/Big Data

Spark Cluster Manager Types (스파크 클러스터 매니저 타입 3종류 번역)

반응형

Spark Cluster Manager Types

3종류를 발번역 하였습니다


전체적인 흐름을 파악하는데 참고해주세요









클러스터 관리자 유형 
시스템은 현재 3종류의 클러스터 관리자를 지원합니다.


Standalone – a simple cluster manager included with Spark that makes it easy to set up a 
독립형 - 간단한 클러스터 매니저가 Spark에 포함되어있어 관리자는 클러스터를 쉽게 구성할 수 있습니다

Apache Mesos – a general cluster manager that can also run Hadoop MapReduce and service applications.
Apache Mesos - Hadoop의 MapReduce와 서비스 응용프로그램을 실행할 수 있는 일반적인 클러스터 관리자

Hadoop YARN – the resource manager in Hadoop 2.
Hadoop YARN – Hadoop 2. 의 리소스 매니저를 이용합니다



http://spark.apache.org/docs/latest/spark-standalone.html
*스파크 독립모드 (Spark Standalone Mode)

Spark는 mesos와 YARN에 실행되는것 외에 간단한 독립형 배포 모드가 준비되어 있습니다
수동으로 Master와 Slave를 Start하여 독립 실행형 클러스터를 시작하거나 제공되는 start 스크립트를 사용할 수 있습니다.
단일 머신에서 테스트를 위해 사용할 수 있습니다

*클러스터에 Spark 독립모드 설치 (Installing Spark Standalone to a Cluster)
Spark를 독립모드로 설치하려면, 간단하게 클러스터의 각 노드에 컴파일된 버전의 Spark를 놓습니다.
릴리즈마다 미리 빌드된 Spark버전을 이용하거나 직접 빌드할 수 있습니다
직접 빌드 방법 : http://spark.apache.org/docs/latest/index.html#building

*클러스터를 수동으로 Start (Starting a Cluster Manually)
독립 Master서버를 실행할 수 있습니다
./sbin/start-master.sh

일단 시작되면, Master는 자신의 URL spark://HOST:PORT를 출력합니다
이 주소는 workers를 연결하는데 사용할 수 있게 SparkContext의 인자로 master를 전달 합니다
또한 Master의 웹 UI를 볼 수 있습니다 기본적으로 http://localhost:8080입니다

하나 이상의 workers를 Start하고 다음을 통해 Master에 연결할 수 있습니다
./bin/spark-class org.apache.spark.deploy.worker.Worker spark://IP:PORT

workers를 Start한 후 (기본적으로 http://localhost:8080) 마스터 Web UI를 보세요
새로운 노드의 CPU와 메모리(OS에 남아있는 용량-1GB 만큼)와 해당번호가 나타날 것입니다

마지막으로 다음옵션은 Master와 worker에게 전당할 수 있습니다.

ArgumentMeaning
-i IP--ip IPIP address or DNS name to listen on
-p PORT--port PORTPort for service to listen on (default: 7077 for master, random for worker)
--webui-port PORTPort for web UI (default: 8080 for master, 8081 for worker)
-c CORES--cores CORESTotal CPU cores to allow Spark applications to use on the machine (default: all available); only on worker
-m MEM--memory MEMTotal amount of memory to allow Spark applications to use on the machine, in a format like 1000M or 2G (default: your machine's total RAM minus 1 GB); only on worker
-d DIR--work-dir DIRDirectory to use for scratch space and job output logs (default: SPARK_HOME/work); only on worker

*클러스터 실행 스크립트 (Cluster Launch Scripts)
실행 스크립트를 이용하여 독립 Spark를 실행하려면, Spark 디렉토리에 conf/slaves 파일을 작성해야 합니다
Spark worker로 사용하려는 모든 시스템의 호스트이름을 한줄에 하나씩 적어야 합니다
Master는 (개인키를 사용하여)  password-less ssh를 통해 각 Slave브 시스템에 액세스 할 수 있어야 합니다
테스트를 위해 localhost를 사용할 수 있습니다.

이 파일을 설정한 후에 다음과 같은 쉘 스크립트를 사용하여 클러스터를 실행하거나 중지 시킬 수 있습니다. 
하둡의 배포 스크립트 를기반으로 SPARK_HOME/bin에 위치해 있습니다

sbin/start-master.sh - Starts a master instance on the machine the script is executed on.
sbin/start-slaves.sh - Starts a slave instance on each machine specified in the conf/slaves file.
sbin/start-all.sh - Starts both a master and a number of slaves as described above.
sbin/stop-master.sh - Stops the master that was started via the bin/start-master.sh script.
sbin/stop-slaves.sh - Stops all slave instances on the machines specified in the conf/slaves file.
sbin/stop-all.sh - Stops both the master and the slaves as described above.

이 스크립트는 당신의 로컬 컴퓨터가 아닌 Spark Master를 실행하는 컴퓨터에서 실행해야합니다

선택적으로 conf/spark-env.sh 환경변수를 설정하여 추가로 클러스터를 구성할 수 있습니다 
conf/spark-env.sh는 conf/spark-env.sh.template를 이용하여 만듭니다
설정을 적용하려면 모든 worker컴퓨터에 복사해야 합니다
다음 설정을 이용할 수 있습니다

Environment VariableMeaning
SPARK_MASTER_IPBind the master to a specific IP address, for example a public one.
SPARK_MASTER_PORTStart the master on a different port (default: 7077).
SPARK_MASTER_WEBUI_PORTPort for the master web UI (default: 8080).
SPARK_MASTER_OPTSConfiguration properties that apply only to the master in the form "-Dx=y" (default: none). See below for a list of possible options.
SPARK_LOCAL_DIRSDirectory to use for "scratch" space in Spark, including map output files and RDDs that get stored on disk. This should be on a fast, local disk in your system. It can also be a comma-separated list of multiple directories on different disks.
SPARK_WORKER_CORESTotal number of cores to allow Spark applications to use on the machine (default: all available cores).
SPARK_WORKER_MEMORYTotal amount of memory to allow Spark applications to use on the machine, e.g. 1000m,2g (default: total memory minus 1 GB); note that each application's individual memory is configured using its spark.executor.memory property.
SPARK_WORKER_PORTStart the Spark worker on a specific port (default: random).
SPARK_WORKER_WEBUI_PORTPort for the worker web UI (default: 8081).
SPARK_WORKER_INSTANCESNumber of worker instances to run on each machine (default: 1). You can make this more than 1 if you have have very large machines and would like multiple Spark worker processes. If you do set this, make sure to also set SPARK_WORKER_CORES explicitly to limit the cores per worker, or else each worker will try to use all the cores.
SPARK_WORKER_DIRDirectory to run applications in, which will include both logs and scratch space (default: SPARK_HOME/work).
SPARK_WORKER_OPTSConfiguration properties that apply only to the worker in the form "-Dx=y" (default: none). See below for a list of possible options.
SPARK_DAEMON_MEMORYMemory to allocate to the Spark master and worker daemons themselves (default: 512m).
SPARK_DAEMON_JAVA_OPTSJVM options for the Spark master and worker daemons themselves in the form "-Dx=y" (default: none).
SPARK_PUBLIC_DNSThe public DNS name of the Spark master and workers (default: none).

참고 : 현재 시작 스크립트는 윈도우를 지원하지 않습니다
Window에서 Spark 클러스터를 실행하려면 수동으로 Master와 worker를 Start해야 합니다

SPARK_MASTER_OPTS는 다음과 같은 시스템 속성을 지원합니다.
Property NameDefaultMeaning
spark.deploy.spreadOuttrueWhether the standalone cluster manager should spread applications out across nodes or try to consolidate them onto as few nodes as possible. Spreading out is usually better for data locality in HDFS, but consolidating is more efficient for compute-intensive workloads. 
spark.deploy.defaultCores(infinite)Default number of cores to give to applications in Spark's standalone mode if they don't set spark.cores.max. If not set, applications always get all available cores unless they configure spark.cores.max themselves. Set this lower on a shared cluster to prevent users from grabbing the whole cluster by default. 
spark.worker.timeout60Number of seconds after which the standalone deploy master considers a worker lost if it receives no heartbeats.

SPARK_WORKER_OPTS는 다음과 같은 시스템 속성을 지원합니다.
Property NameDefaultMeaning
spark.worker.cleanup.enabledfalseEnable periodic cleanup of worker / application directories. Note that this only affects standalone mode, as YARN works differently. Applications directories are cleaned up regardless of whether the application is still running.
spark.worker.cleanup.interval1800 (30 minutes)Controls the interval, in seconds, at which the worker cleans up old application work dirs on the local machine.
spark.worker.cleanup.appDataTtl7 * 24 * 3600 (7 days)The number of seconds to retain application work directories on each worker. This is a Time To Live and should depend on the amount of available disk space you have. Application logs and jars are downloaded to each application work dir. Over time, the work dirs can quickly fill up disk space, especially if you run jobs very frequently.


*클러스터에 응용프로그램 연결 (Connecting an Application to the Cluster)
Spark 클러스터에 응용프로그램을 실행하려면 단순하게 SparkContext 생성자로 Master의 spark://IP:PORT URL을 넣어줍니다
SparkContext : http://spark.apache.org/docs/latest/programming-guide.html#initializing-spark

클러스터에 대한 대화형 Spark shell을 실행하려면 다음과 같이 합니다
./bin/spark-shell --master spark://IP:PORT

참고로 Spark Cluster 시스템중 하나에서 Spark-shell을 실행하려는 경우 bin/spark-shell 스크립트는 자동으로 conf/spark-env.sh에서 SPARK_MASTER_IP 및 SPARK_MASTER_PORT변수와 MASTER를 설정합니다

또한 옵션을 전달할 수 있습니다 --cores <numCores>를 이용하여 클러스터에서 사용할 코어수를 제어할 수 있습니다

*Spark응용프로그램의 실행가능한 컴파일 (Launching Compiled Spark Applications)
spark-submit 스크립트는 컴파일된 Spark 어플리케이션을 클러스터 에제출하는 가장 간단한 방법을 제공합니다
독립실행형 클러스터의 경우, 현재 Spark는 응용프로그램을 제출할때 클라이언트 프로세스의 내부 드라이버를 사용할 수 있게 배포를 지원합니다 (클라이언트 배포 드모).

만약 당신의 응용프로그램이 Spark submit을 통해 실행되는 경우, 응용프로그램의 jar는 자동으로 모든 worker노드에 배포 됩니다.
응용프로그램에 따라 추가되는 jar는 구분기호 쉼표를 사용하여 --jar를 통해 지정해야 합니다
(예를 들어 --jar jar1.jar2)
응용프로그램의 구성 또는 실행 환경을 제어하려면 Spark 구성을 참조하십시오
Spark 구성 : http://spark.apache.org/docs/latest/configuration.html

*리소스 스케줄링 (Resource Scheduling)
독림클러스터 모드는 현재 응용프로그램에서 간단한 FIFO스케줄러를 지원합니다
그러나, 다수의 동시 사용자에게 허용하려면 각 응용프로그램이 사용할 자원의 최대 수를 제어할 수 있습니다
기본적으로, 이는 클러스터의 모든 코어를 얻는것은 한번에 하나의 응용프로그램을 실행하는 경 우에만 의미가 있습니다
SparkConf에서 spark.cores.max를 설정하는것으로 코어수를 설정할 수 있습니다
val conf = new SparkConf()
             .setMaster(...)
             .setAppName(...)
             .set("spark.cores.max", "10")
val sc = new SparkContext(conf)

또한 spark.cores.max를 설정하지 않은 응용프로그램에 대한 기본값을 변경하려면 클러스터 마스터과정에서 spark.deploy.defaultCores를 설정하면 됩니다
설정 내용은 conf/spark-env.sh에 추가합니다

export SPARK_MASTER_OPTS="-Dspark.deploy.defaultCores=<value>"
이렇게하면 사용자가 개별적으로 코어의 최대수를 안정해도 됩니다
공유 클러스터에 유용합니다

*모니터링 및 로깅 (Monitoring and Logging)
Spark의 독립모드는 모든클러스터를 모니터링하는 웹 기반의 사용자 인터페이스를 제공합니다.
Master와 각 worker클러스터 작업통계를 보여주는 웹 UI를 가지고 있습니다
기본적으로 8080포트에서 Master UI에서 엑세스 할 수 있습니다
포트는 구성 파일이나 명령줄 옵션을 통해 하나를 변경할 수 있습니다

또한 각 작업에 대한 자세한 로그 출력은 각각의 슬레이브 노드의 작업 디렉토리에 기록됩니다.
(SPARK_HOME/work 기본 작업 위치)
각 작업의 표준출력 및 표준 오류에대한 두개의 파일을 모두 콘솔에서 볼 수 있습니다

* 하둡과 함께 실행 (Running Alongside Hadoop)

같은 시스템에서 별도의 서비스로 실행하여 기존의 하둡 클러스터와 함께 Spark를 실행할 수 있습니다
Spark에서 하둡 데이터에 액세스하려면 HDFS://URL (일반적으로 HDFS://<namenode:9000/path 입니다. 하둡 네임노드의 웹 UI의 오른쪽 URL에서 찾을 수 있습니다)
또한 Spark를 대해 별도의 클러스터를 설정할 수 있습다 그러면 네트워크를 통행 HDFS에 액세스합니다 이럴경우 로컬 액세스하는것보다 느립니다
같은 네트워크에서 실행되는 경우에는 문제될게 없습니다(예를 들어 하둡랙 중에 몇개만 Spark를 배치한 경우)

*네트워크 보안을 위한 포트 구성 (Configuring Ports for Network Security)
Spark는 네트워크를 많이 사용합니다. 일부 환경은 강한 방화벽 설정을 위해 엄격한 요구사항이 있습니다
아래의 스파크가 통신하는 기본 포트 구성에대해 안내합니다
FromToDefault PortPurposeConfiguration SettingNotes
BrowserStandalone Cluster Master8080Web UImaster.ui.portJetty-based
BrowserDriver4040Web UIspark.ui.portJetty-based
BrowserHistory Server18080Web UIspark.history.ui.portJetty-based
BrowserWorker8081Web UIworker.ui.portJetty-based
ApplicationStandalone Cluster Master7077Submit job to clusterspark.driver.portAkka-based. Set to "0" to choose a port randomly
WorkerStandalone Cluster Master7077Join clusterspark.driver.portAkka-based. Set to "0" to choose a port randomly
ApplicationWorker(random)Join clusterSPARK_WORKER_PORT(standalone cluster)Akka-based
Driver and other WorkersWorker(random)
  • File server for file and jars
  • Http Broadcast
  • Class file server (Spark Shell only)

*고 가용성 (High Availability)
기복적으로 독립스케줄 클러스터는 Worker 의오류에 탄력적입니다(Spark자체가 다른 Work로 이동하여 작업손실을 복가능한대로 복구합니다.
그러나 스케줄러는 스케줄링 결정할때 Master를 사용합니다 이는 단일 장애지점을 만듦니다.
만 약마스터가 충돌나는 경우, 새로운 응용프로그램을 만들  수없습니다
이것을 회피하기 위해 우리는 아래 설명된 두개의 고 가용성 계획을 가지고 있습니다

* Zookeeper를 이용 Master가 대기 (Standby Masters with ZooKeeper)
개요
리더 선출에 일부 state storage를 제공하기위해 Zookeeper를 활용합니다
동일한 Zookeeper 인스턴스에 연결된 클러스터에 여러개의 Master를 Start할 수 있습니다
하나는 리더로 선출되고 나머지는 대기 모드로 유지 됩니다
현재의 리터가 죽으면(첫번재 리더가 다운되었을떄) 다른 마스터가 선출되고 이전 마스터의 상태로 복구외어 다음 스케줄 을실행합니다
전체 복구 프로세스는 1,2 분정도 소요됩니다
마스터 장애 조치 중 이미 실행중이었던 응용프로그램은 영향을 받지 않습니다 이런 지연은 새로운 응용프로그램 스케줄에 영향을 줍니다

Zookeeper를 시작하기 전에 자세히 알아보세요 : http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html

설정
이 복구 모드를 사용하기 위해 spark-env 환경 설정에 SPARK_DAEMON_JAVA_OPTS를 설정할 수 있습니다
System propertyMeaning
spark.deploy.recoveryModeSet to ZOOKEEPER to enable standby Master recovery mode (default: NONE).
spark.deploy.zookeeper.urlThe ZooKeeper cluster url (e.g., 192.168.1.100:2181,192.168.1.101:2181).
spark.deploy.zookeeper.dirThe directory in ZooKeeper to store recovery state (default: /spark).

가능한 실수 : 당신의 클러스터에 여러개의 Master를 가지고 있지만 Zookeeper를 사용하는 Master를 구성하지 않는 경우
Master는 서로 발견하는데 실패하고 무두 Master라고 생각합니다
이는 정상적인 클러스터 상태로 이어지지 않습니다
(모든 마스터는 독립적으로 일정을 계획하는 등)

상세
Zookeeper클러스터를 설정한 후 고 가용성을 설정하는것은 간단합니다. 단순히 Zookeeper구성으로 서로 다른 노드에 여러개의 Master를 실행합니다 (Zookeeper URL및 디렉토리)
마스터는 언제든지 추가 삭제를 할 수 있습니다

새 응용프로그램을 스케줄 하거나 클러스터에 workers를 추가하기 위해 현재 Master의 IP주소를 알아야 합니다
단순하게 Master의 리스트 목록을 전달하여 실행 할 수 있습니다 
예를 들어 spark://host1:port1,host2:port2를 SparkContext가 가리키도록 start할 수 있습니다
이렇게 하는 이유는 SparkContext에 모든 Master를 등록하기 위해 서입니다(host1이 다운될때)
새로운 leader host2를 찾아 설정은 정확하게 계속 유지될 것입니다

Master등록과 정상 작동하는 것에는 중요한 차이점이 있습니다
Starting up할때 응용프로그램 또는 worker는 현재 lead Master를 찾아 등록할 수 있어야 합니다
성공적으로 등록되면 시스템이 구성됩니다(즉, Zookeeper에 저정된).
장애 조치가 발생했을 경우 새로운 leader가 leadership의 변화를 알리기 위해 이전에 등록된으용프로그램 및 worker에 알리게 됩니다
그래서 그들에게 새로운 Master의 존재를 알릴 필요가 없습니다

이때문에 설정을 통해 새로운 마스터를 언제든지 생성할 수 있습니다
단지 걱정해야 할 것은 새로운 어플리 케이션과 worker는 새로운 leader가 등록된 후에 register를 찾을 수 있습니다
등록이 되면 당신은 걱정할 필요가 없습니다

*로컬 파일 시스템과 단일 노드 복구 (Single-Node Recovery with Local File System)
개요
Zookeeper는 생산수준의 고 가용성으로 가는 가장 좋은 방법 입니다
하지만 down되었을때 Master가 다시 시작될 수 있도록 하는것은 파일 시스템 모드에서 처리 할 수 있습니다
응용프로그램과 workers를 register할때 Master 프로세스의 복구와 restart에 이용될수 있도록그들에게 제공되는 디렉토리에 충분히 기록할 수 있는 공간이 있어야 합니다


설정
이 복구 모드를 활성화 하기 위해 spark-env에 SPARK_DAEMON_JAVA_OPTS를 설정 할 수 있습니다
System propertyMeaning
spark.deploy.recoveryModeSet to FILESYSTEM to enable single-node recovery mode (default: NONE).
spark.deploy.recoveryDirectoryThe directory in which Spark will store recovery state, accessible from the Master's perspective.

상세
이 솔루션에 monit과 같은 monitor/manager를 이용하여 사용하거나 재 시작을 통해 수동 복구를 가능하게 합니다

파일시스템 복구가 정상적인 복구로 보일수 있지만  이모드는 특정 개발 또는 실험 목적을 위한 차선책 입니다
특히 stop-master.sh를 통해 Master를 종료할때 복구 기능을 제공하지 않습니다
그래서 새로운 Master를 시작할 때마다 그것은 복구 모드로 들어갑니다
previously-registered된 Workers/clients가 timeout될시간의 대기가 필요한 경우 최대 1분의 startup시간을 증가시킬수 있습니다

그것은 공식적으로 지원되지 않지만 보국 디렉토리를 NFS디렉토리에 마운트할 수 있습니다
원래의 Master노드는 완전히 죽은 경우 다른 노드에서 Master를 시작할  수있습니다
이전에 등록된 workers/applications을 복구하는 정상적인 절차 입니다(Zookeeper의 복구에 해당)
그러나 새로운 어플리케이션을 등록하기 위해 새로운 마스터를 찾을 수 있습니다




http://spark.apache.org/docs/latest/running-on-mesos.html
*Mesos에서 Spark 실행 (Running Spark on Mesos)

Spark는 Apacke Mesos하드웨어 관리 클러스터에서 실행 할 수 있습니다
Apache Mesos : http://mesos.apache.org

Spark에 Mesos를 포함시킨 장점은 다음과 같습니다
Spark와 다른 프레임 워크 사이의 동적 구분
Spark의 여러 인스턴스 사이의 확장 파티션

* 동작 구조 (How it Works)
독립클러스터 배포
아래 그림에서 클러스터 관리자는 Spark Master 인스턴스 입니다
Mesos를 사용할때 Mesos Master는 클러스터 관리자로 Spark의 Master를 대체 합니다



driver가 job 작성과 tasks 스케줄링을 위해 실행할때 Meso machines가 어떤 작업을 처리합니다
많은 short-lived(단기) 작업을 예약할때 이 계정으로 다른 프레임 워크를 사용하므로 여러 프레임워크 자 원의 정적 분할에 의지하지 않고 동일한 클러스터에 공존할 수 있습니다

Mesos를 설치하고 Mesos를 통해 Spark작업을 배포는 다음 절차를 따라 합니다

*Mesos설치 (Installing Mesos)
Spark 1.0.1은 Mesos 0.18.1과 함께 사용할 수 있도록 설계되어 Mesos의 특별한 패치가 필요하지 않습니다
이미 Mesos클러스터가 실행되고 있는겨우, 다음의 Mesos설치 단계를 건너 뛸 수 있습니다.

그렇지 않으면 Spark Mesos를 설치하면 다은 프레임 워크에서 사용하기 위해 Mesos를 설치하는것과 다르지 앖습니다(같다). Source나 미리 빌드된 패키지를 사용하여 Mesos를 설치할 수 있습니다

* Source를 이용(From Source)
Apache Mesos를 source로 설치하려면 다음 단계를 수행
Mesos mirror에서 자료를 다운로드 (Mesos mirror : http://www.apache.org/dyn/closer.cgi/mesos/0.18.1/)
Mesos를 컴파일하고 설치하기위한 시작 페이지 : http://mesos.apache.org/gettingstarted/

참고 : 시스템 기본 경로에 설치하지 않고 Meso를 실행합니다 (예를 들어, 설치할때 관리자 권한이 없는 경우)
--prefix를 이용해서 설치할 위치를 알려주는 옵션을 사용합니다
예를 들어 --prefix=/home/me/mesos
기본적인 prefix는 /usr/local 입니다

* 타사 패키지 (Third-Party Packages)
Apache Mesos 프로젝트는 source가 아닌 오직 binary 패키지로 배포합니다
그러나 다른 패키지에서 Mesos 설정에 도움이 될 수 있는 binary자료를 배포할 수 있습니다

그것은 Mesosphere입니다 여기서 제공하는 릴리즈를 사용하여 Mesos를 설치하려면 
다운로드 페이지에서 Mesos패키지를 다운로드 : http://mesosphere.io/downloads/
설치 및 설정에대한 지시를 따릅니다

Mesosphere 설치문서는 Master장애를 처리하기위해 Zookeeper 설정을 제시합니다
하지만 Zookeeper없이 단일 Master를 사용하여 Mesos를 실행할 수 있습니다

* 확인(Verification)
Mesos 클러스터가 Spark할 준비가 되었는지 확인하려면 Mesos Master  web UI 포트:5050에서 모든 machines에 slaves tab이 있는지 확인합니다

* Mesos에 Spark를 연결 (Connecting Spark to Mesos)
Spark에서 Mesos를 사용하려면 Mesos가 액세스 할 수 있는 장소에 사용할 수 있는 Spark 파이너리 패키지가 필요하 고 Spark 드라이버 프로그램은 Mesos에 연결하도록 구성합니다. 

* 업로드 Spark 패키지 (Uploading Spark Package)
Mesos slave에서 Mesos task를 처음 실행하는경우  slave에서 Mesos backend로 실행가기 위한 Spark binary 패키지가 꼭 있어야 합니다
Spark 패키지는 모든 하둡 액세스 URL에서 호스팅할 수 있습니다
HTTP를 포함 http:// 아마존 심플 스토리지 s3n:// 하둡 hdfs://

미리 컴파일된 패키지를 사용하려면 : 
Spark 다운로드 페이지에서 Spark binary 패키지를 다운로드
http / hdfs / s3 에 업로드

HDFS가 호스트라면 하둡명령어 fs put 명령어를 이용합니다
hadoop fs -put spark-1.0.1.tar.gz /path/to/spark-1.0.1.tar.gz

Spark 사용 자지정 컴파일된 버전을 사용하는 경우나 Spark source tarball/checkout을 사용하면  포함된 make-distribution.sh 스크립트를 사용하여 패키지를 만들어야 합니다.

여기있는 지침을 사용하여 다운로드와 빌드를 통해 Spark를 구축 : http://spark.apache.org/docs/latest/index.html
make-distribution.sh --tgz. 를 사용하여 binary 패키지 만들기
http / s3 / hdfs에 압축파일을 업로드

* Mesos Master URL을 사용 (Using a Mesos Master URL)
single-master에대한 Mesos Master URL 형태이다 mesos://host:5050
또는 Zookeeper를 사용한 multi-master의 Mesos 클러스터 mesos://zk://host:2181

Mesos와 올바르게 상호 작용하기 위해 드라이버는 spark-env.sh 설정파일을 필요로 합니다

  1. In spark.env.sh set some environment variables:
    • export MESOS_NATIVE_LIBRARY=<path to libmesos.so>. This path is typically <prefix>/lib/libmesos.so where the prefix is/usr/local by default. See Mesos installation instructions above. On Mac OS X, the library is called libmesos.dylibinstead of libmesos.so.
    • export SPARK_EXECUTOR_URI=<URL of spark-1.0.1.tar.gz uploaded above>.
  2. Also set spark.executor.uri to <URL of spark-1.0.1.tar.gz>.

이제 클러스터에 대에 Spark 어플리케이션을 시작할때 SparkContext을 만들때 mesos:// URL을 전달하면 됩니다
예를 들어 

val
conf = new SparkConf() .setMaster("mesos://HOST:5050") .setAppName("My app") .set("spark.executor.uri", "<path to spark-1.0.1.tar.gz uploaded above>") val sc = new SparkContext(conf)

또한 spark-submit과 conf/spark-defaults.conf 파일에 있는 spark.executor.uri 설정을 통해 구성할 수 있습니다
현재 Mesos 클라이언트 모드에서만 spark-submit Spark driver를 지원합니다

쉘을 실행하는 경우 spark.executor.uri매개 변수는 SPARK_EXECUTOR_URL에서 상속 받습니다 그래서 중복해서 시스템 속석으로 전달할 필요가 없습니다.

* Meso 실행 모드 (Mesos Run Modes)
Spark는 Mesos에서 두가지 모드로 실행됩니다
"fine-grainged"(기본값) 과 "coarse-grained" 
세분화(기본값)와 대단위

"fine-grained"모드에서(기본값)
각 Spark task는 별도의 Mesos task에서 실행됩니다
이 Spark의 여러인스턴스(다른 프레임워크)에 매우 미세한 단위에서 machines를 공유할 수 있습니다
각 응용프로그램은 더하거나 덜면서 machines을 가집니다
하지만 각 task실행에 추가 overhead를 가집니다
이 모드는 대화형 쿼리나 웹 요청같은 낮은 대기시간을 요구하 는사항에 적합하지 않을수 있습니다

"coarse-grained"(대단위) 모드는 각 Mesos시스템에서 하나의 long-running(오래 동작하는)한 Spark task가 시작됩니다
동적으로 그 안에 "mini-tasks"(작은 작업)을 스케줄 할 수 있습니다
장점으로는 훨씬 낮은 startup overhead시간 입니다 그러나 어플리에키션의 전체 지속 기간동안 Mesos의 예약 비용이 듭니다

coarse-grained모드에서 실행하려면 SparkConf에 spark-mesos.coarse 속성을 설정합니다
conf.set("spark.mesos.coarse", "true")
sparkconf : http://spark.apache.org/docs/latest/configuration.html#spark-properties

또한 coarse-grained모드에서 Spark 의최대 리소스를 제어할 수 있습니다 기본적으로 클러스터의 코어를 얻기위 해설정합니다
이는 한번에 하나의 응용프로그램을 실행하는 경우에만 의미가 있습니다
원하는 코어수를 설정할 수 있습니다 conf.set("spark.cores.max","10")

* 하둠과 함께 실행 (Running Alongside Hadoop)
Spark와 Mesos를 기존의 hadoop 시스템에서 별도의 서비스로 machines에서 실행할 수 있습니다
Spark에서 hadoop데이터에 액세스하려면 hdfs://URL의 전체가 필요합니다. (일반적으로 hdfs://<namenode>:9000/path, hadoop namenode 웹 UI의 오른쪽에서 URL을 찾을 수 있습니다

또한 둘 사이에 더 나은 자원 분리 및 공유를 위한 Mesos에서 hadoop MapReduce를 실행할 수 있습니다
각 노드의 리눅스 스케줄러를 통해 각각에 자원을 공유하는것과 다르게 이 경우 Mesos는 hadoop또는 Spark중 하나에 코어를 할당하는 통합 스케줄러 역할을 합니다
Mesos Hadoop 을참조하시기 바랍니다 : https://github.com/mesos/hadoop

두 경우에서 HDFS는 Mesos를 통해 스케줄받지 않고 Hadoop MapReduce와 별도로 실행합니다

* 문제 해결 및 디버길 (Troubleshooting and Debugging)

A few places to look during debugging:

  • Mesos master on port :5050
    • Slaves should appear in the slaves tab
    • Spark applications should appear in the frameworks tab
    • Tasks should appear in the details of a framework
    • Check the stdout and stderr of the sandbox of failed tasks
  • Mesos logs
    • Master and slave logs are both in /var/log/mesos by default

And common pitfalls:

  • Spark assembly not reachable/accessible
    • Slaves must be able to download the Spark binary package from the http://hdfs:// or s3n:// URL you gave
  • Firewall blocking communications
    • Check for messages about failed connections
    • Temporarily disable firewalls for debugging and then poke appropriate holes


YARN에서 Spark를 실행 (Running Spark on YARN)

YARN(하둡의 NextGen)에서 Spark 실행에 대한 지원은 0.6.0버전 이후에 향상 되었습니다.

* 준비 (Preparations)
Spark-on-YARN을 실행하기 위해선 YARN을 지원하도록 빌드된 Spark binary 배포판이 필요합니다
바이너리 배포판은 Spark프로젝트 웹 사이트에서 다운로드 할 수 있습니다 
Spark를 build하려면 Maven 빌드 가이드를 참조하세요 : http://spark.apache.org/docs/latest/building-with-maven.html

* 설정 ( Configuration)
configs의 대부분은 다른 배포 모드와 Spark on YARN과 동일합니다
이들에 대한 자세한 내용은 configuration 페이지를 참조하세요 : http://spark.apache.org/docs/latest/configuration.html
Spark on YARN에 필요한 configs가 있습니다

* 환경 변수 (Environment Variables)
YARN 용으로 출시된 Spark 프로세스의 환경변수에 SPARK_YARN_USER_ENV를 추가할 수 있습니다
이 환경변수의 목록(쉼표로 구분)을 예로들면 다음이 될 수 있습니다
SPARK_YARN_USER_ENV="JAVA_HOME=/jdk64,FOO=bar"

Spark Properties

Property NameDefaultMeaning
spark.yarn.applicationMaster.waitTries10Set the number of times the ApplicationMaster waits for the the Spark master and then also the number of tries it waits for the SparkContext to be initialized
spark.yarn.submit.file.replication3HDFS replication level for the files uploaded into HDFS for the application. These include things like the Spark jar, the app jar, and any distributed cache files/archives.
spark.yarn.preserve.staging.filesfalseSet to true to preserve the staged files (Spark jar, app jar, distributed cache files) at the end of the job rather then delete them.
spark.yarn.scheduler.heartbeat.interval-ms5000The interval in ms in which the Spark application master heartbeats into the YARN ResourceManager.
spark.yarn.max.executor.failures2*numExecutorsThe maximum number of executor failures before failing the application.
spark.yarn.historyServer.address(none)The address of the Spark history server (i.e. host.com:18080). The address should not contain a scheme (http://). Defaults to not being set since the history server is an optional service. This address is given to the YARN ResourceManager when the Spark application finishes to link the application from the ResourceManager UI to the Spark history server UI.
spark.yarn.executor.memoryOverhead384The amount of off heap memory (in megabytes) to be allocated per executor. This is memory that accounts for things like VM overheads, interned strings, other native overheads, etc.
spark.yarn.driver.memoryOverhead384The amount of off heap memory (in megabytes) to be allocated per driver. This is memory that accounts for things like VM overheads, interned strings, other native overheads, etc.

기본적으로, Spark on YARN은 로컬에 설치된 Spark jar을 사용합니다
하지만 Spark jar가 HDFS에 있으면 world-readable (모든위치) 에서 읽을 수 있습니다
응용프로그램 마다 실행을 분산시킬 필요가 없도록 YARN노드에서 캐시할 수 있습니다
HDFS에 있는 jar을 가리키려면 export SPARK_JAR=hdfs=hdfs:///some/path

* Spark on YARN 실행하기 (Launching Spark on YARN)
configuration 파일이 포함된 디렉토리가 (클라이언트에) HADOOP_CONF_DIR 또는 YARN_CONF_DIR에 반드시 있어야 합니다
이 configs는 YARN ResourceManager가 dfs에 write하고 connect하는데 사용됩니다

YARN에서 Spark 응용프로그램을 실행하는데 사용할수 있는 배포 모드는 두가지가 있습니다
yarn-cluster mode는 YARN의 클러스터 매니저에 관리되는 어플리케이션 master에서 Spark 드라이버가 동작합니다 그리고 클라이 언트 응용프로그램을 시작한 후 사라질 수 있습니다
yarn-client mode는 드라이버 클라이언트는 프로세스에서 실행되며 어플리케이션 master는 YARN에 리소스를 요청하는데 사용됩니다

Spark 독립모드와 Mesos모드와 달리 master의 주소는 "master"의 parameter에 지정됩니다
YARN mode에서 ResourceManager의 주소는 hadoop configuration에서 찾습니다
따라서 master parameter는 단순히 "yarn-client"나 "yarn-cluster"입니

yarn-cluster mode로 Spark 응용프로그램을 실행하려면
./bin/spark-submit --class path.to.your.Class --master yarn-cluster [options] <app jar> [app options]

예를 들어
$ ./bin/spark-submit --class org.apache.spark.examples.SparkPi \
    --master yarn-cluster \
    --num-executors 3 \
    --driver-memory 4g \
    --executor-memory 2g \
    --executor-cores 1 \
    lib/spark-examples*.jar \
    10

위에서 default Application Master를 시작해서 YARN 클라이언트 프로그램을 시작합니다
SparkPi는 Application Master의 자식 스레드로 실행됩니다
클라이언트는 주기적으로 상태 업데이트를 위해 어플리케이션 master를 폴링하여 콘솔에 표시합니다
어플리케이션 실행이 완료되면 클라이언트가 종료됩니다
드라이버와 실행 프로그램 로그를 확인하는 방법은 아래 로그보기절을 참조하세요

yarn-client mode에서 Spark 어플리케이션을 실행하려면 같은 작업을 실행합니다
하지만 Spark shell을 사용하면 "yarn-client"는 "yarn-cluster"를 대체합니다
$ ./bin/spark-shell --master yarn-client

* 다른 jar 추가하기 (Adding Other JARs)
yarn-cluster mode에서 드라이버는 클라이언트와 다른 시스템에서 실행됩니다
그래서 SparkContext.addJar은 해당 local client 밖에서 동작하지 않습니다
SparkContext.addJar를 클라이언트에서 사용할 수 있게 만들려면 --jar 옵션 commend를 사용합니다
$ ./bin/spark-submit --class my.main.Class \
    --master yarn-cluster \
    --jars my-other-jar.jar,my-other-other-jar.jar
    my-main-jar.jar
    app_arg1 app_arg2

* 어플리케이션 디버깅 (Debugging your Application)
YARN용어로 executors와 application master는 내부에서 "containers"를 실행합니다
YARN 응용프로그램이 완료된  후컨테이너의 로그를 처리하기위한 두가지 모드가 있습니다
로그 aggregation이 켜져있는 경우 (yarn.log-aggregation-enable 설정 포함), 컨테이너 로그를 HDFS에 복사하고 로컬 컴퓨터에서 삭제 됩니다
이러한 로그는 "yarn logs"명령을 사용하여 어디서나 클러스터에서 볼 수 있습니다
yarn logs -applicationId <app ID>

해당 어플리케이션의 모든 컨터에너의 로그파일 내용을 볼 수 있습니다

로그 aggregation 이 설정되어 있지 않은경우
로그는 각 시스템의 YARN_APP_LOGS_DIR에 유지됩니다
하둡 버전과 설치에 따라 다르지만 일반적으로 /tmp/logs/ 또는 정의된 $HADOOP_HOME/logs/userlogs에 있습니다
컨테이너의 로그를 보려면 컨테이너가 있는 호스트로가서 디렉토리를 봐야 합니다
하위 디렉토리에는 어플리케이션 ID와 컨테이너 ID로 로그파일이 구성되어 있습니다

컨테이너당 실행 환경을 보는것은 
큰값 yarn.nodemanager.delete.debug-delay-sec으로 증가합니다 (예를 들어 36000)
그리고 컨테이너가 시작되어있는 노드에서 yarn.nodemanager.local-dirs를 통해 어플리케이션 캐시에 접근할 수 있습니다

이 디렉토리에는 start스크립트가 포함되어 있고 jar와 컨테이너 실행에 사용되는 모든 환경 변수가 있습니다
이 과정은 class path문제를 디버깅 하는데 유용합니다
(이 작업을 가능하게 하는 클러스터 설정 및 노드 매니저를 다시 시작할 수 있는 관리자 권한이 필요합니다. 따라서 호스트 클러스터에서 적용할 수 없습니다)

* 중요 사항 (Important Notes)
hadoop 2.2 이전 YARN컨테이너 리소스 요청에 cores를 지원하지 않습니다
따라서 이전 버전에서 실행하는 겨우 commend line을 통해 cores의 숫자를 YARN에 전달할  수없습니다
core요청이 스케줄링 결정에 적용 여부는 그것이 어떻게 구성되어 있는지 스케줄러 사용에 의존하고 있다

Spark executors에 의해 사용되는 로컬 디렉토리는 YARN에 대해 구성된 로컬 디렉토리가 될 것입니다
(Hadoop YARN의 config yarn.nodemanager.local-dirs)
사용자가 spark.local.dir을 지정한 경우 그것은 무시됩니다

하둡 #과 유사한 --files와 --archives 옵션에 같이 지정하는 파일 이름을 지원합니다
예를 들어 --files localtest.txt#appSees.txt 이것은 로컬에는 localtest.txt 이름으로 있지만 HDFS에는 appSees.txt이름으로 연결되어 파일을 업로드 합니다
YARN에서 실행되는 경우 응용프로그램은 appSees.txt 이름으로 참조해야합니다

로컬 파일 --jar 옵션을 사용하여 yarn-cluster mode로 실행하는 경우 SparkContext.addJar기능이 작동할 수 있습니다
만약 HDFS, HTTP, HTTPS 또는 FTP파일과 함께 사용하는 경우에는 사용할 필요가 없습니다




반응형