programing

Windows에서 Spark를 설정하는 방법은 무엇입니까?

nasanasas 2020. 9. 11. 08:08
반응형

Windows에서 Spark를 설정하는 방법은 무엇입니까?


Windows에서 Apache Spark를 설정하려고합니다.

조금 검색 한 결과 독립 실행 형 모드가 내가 원하는 것임을 이해합니다. Windows에서 Apache Spark를 실행하려면 어떤 바이너리를 다운로드해야합니까? 스파크 다운로드 페이지에서 hadoop 및 cdh를 사용한 배포판을 봅니다.

나는 이것에 대한 웹 참조가 없습니다. 이에 대한 단계별 가이드는 높이 평가됩니다.


Windows에서 가장 쉬운 해결책은 소스에서 빌드하는 것입니다.

이 가이드를 거의 따를 수 있습니다 : http://spark.apache.org/docs/latest/building-spark.html

Maven을 다운로드하여 설치 MAVEN_OPTS하고 가이드에 지정된 값으로 설정 합니다.

그러나 Spark를 사용하고 있고 자신의 컴퓨터가 Windows를 실행하는 다른 이유 때문에 실제로 Windows에서 실행할 필요가 없다면 Linux 가상 컴퓨터에 Spark를 설치하는 것이 좋습니다. 시작하는 가장 간단한 방법은 Cloudera 또는 Hortonworks에서 만든 기성 이미지를 다운로드하고 번들 버전의 Spark를 사용하거나 소스에서 직접 설치하거나 spark 웹 사이트에서 얻을 수있는 컴파일 된 바이너리를 설치하는 것입니다.


로컬 모드에서 Spark를 설치하는 단계 :

  1. Java 7 이상을 설치합니다 . Java 설치가 완료되었는지 테스트하려면 명령 프롬프트 유형을 열고 javaEnter 키를 누르십시오. 메시지를 수신하는 경우 'Java' is not recognized as an internal or external command.환경 변수를 구성 JAVA_HOME하고 PATHjdk의 경로를 가리켜 야합니다.

  2. Scala를 다운로드하여 설치 합니다.

    설정 SCALA_HOME에서 Control Panel\System and Security\System고토 "교수실 시스템 설정"을 추가 %SCALA_HOME%\bin환경 변수에 PATH 변수에.

  3. Python 다운로드 링크 에서 Python 2.6 이상을 설치합니다 .

  4. SBT를 다운로드하십시오 . 그것을 설치하고 SBT_HOME값이 <<SBT PATH>>.
  5. HortonWorks repo 또는 git repowinutils.exe 에서 다운로드합니다 . Windows에 로컬 Hadoop 설치가 없기 때문에 생성 된 홈 디렉토리 아래의 디렉토리에 다운로드 하여 배치해야합니다 . 환경 변수에 설정 합니다.winutils.exebinHadoopHADOOP_HOME = <<Hadoop home directory>>
  6. 사전 빌드 된 Spark 패키지를 사용하므로 Hadoop Spark 다운로드 용 Spark 사전 빌드 패키지를 선택합니다 . 다운로드하고 추출하십시오.

    환경 변수에서 PATH 변수를 설정 SPARK_HOME하고 추가 %SPARK_HOME%\bin합니다.

  7. 실행 명령 : spark-shell

  8. http://localhost:4040/SparkContext 웹 UI를 보려면 브라우저에서 엽니 다 .


여기에서 스파크를 다운로드 할 수 있습니다.

http://spark.apache.org/downloads.html

이 버전을 추천합니다 : Hadoop 2 (HDP2, CDH5)

버전 1.0.0부터 Windows에서 스파크를 실행 하는 .cmd 스크립트가 있습니다.

7zip 등을 사용하여 압축을 풉니 다.

시작하려면 /bin/spark-shell.cmd --master local [2]을 실행할 수 있습니다 .

인스턴스를 구성하려면 다음 링크를 따르십시오. http://spark.apache.org/docs/latest/


다음 방법을 사용하여 Spark를 설정할 수 있습니다.

  • 소스에서 빌드
  • 미리 빌드 된 릴리스 사용

Source에서 Spark빌드 하는 방법에는 여러 가지가 있습니다.
먼저 SBT로 Spark 소스를 빌드하려고 시도했지만 hadoop이 필요합니다. 이러한 문제를 피하기 위해 사전 빌드 된 릴리스를 사용했습니다.

Source 대신 Hadoop 2.x 버전 용 Prebuilt 릴리스를 다운로드하여 실행했습니다. 이를 위해서는 Scala를 필수 구성 요소로 설치해야합니다.

여기에 모든 단계를 수집
했습니다. 독립 실행 형 모드에서 Windows7에서 Apache Spark를 실행하는 방법

도움이 되길 바랍니다 .. !!!


spark-2.xx로 작업하려고 할 때 Spark 소스 코드를 빌드하는 것이 작동하지 않았습니다.

  1. 그래서 Hadoop을 사용하지는 않겠지 만, Hadoop이 내장 된 미리 빌드 된 Spark를 다운로드했습니다. spark-2.0.0-bin-hadoop2.7.tar.gz

  2. 추출 된 디렉토리에서 SPARK_HOME을 가리키고 다음에 추가하십시오 PATH.;%SPARK_HOME%\bin;

  3. Download the executable winutils from the Hortonworks repository, or from Amazon AWS platform winutils.

  4. Create a directory where you place the executable winutils.exe. For example, C:\SparkDev\x64. Add the environment variable %HADOOP_HOME% which points to this directory, then add %HADOOP_HOME%\bin to PATH.

  5. Using command line, create the directory:

    mkdir C:\tmp\hive
    
  6. Using the executable that you downloaded, add full permissions to the file directory you created but using the unixian formalism:

    %HADOOP_HOME%\bin\winutils.exe chmod 777 /tmp/hive
    
  7. Type the following command line:

    %SPARK_HOME%\bin\spark-shell
    

Scala command line input should be shown automatically.

Remark : You don't need to configure Scala separately. It's built-in too.


Here's the fixes to get it to run in Windows without rebuilding everything - such as if you do not have a recent version of MS-VS. (You will need a Win32 C++ compiler, but you can install MS VS Community Edition free.)

I've tried this with Spark 1.2.2 and mahout 0.10.2 as well as with the latest versions in November 2015. There are a number of problems including the fact that the Scala code tries to run a bash script (mahout/bin/mahout) which does not work of course, the sbin scripts have not been ported to windows, and the winutils are missing if hadoop is not installed.

(1) Install scala, then unzip spark/hadoop/mahout into the root of C: under their respective product names.

(2) Rename \mahout\bin\mahout to mahout.sh.was (we will not need it)

(3) Compile the following Win32 C++ program and copy the executable to a file named C:\mahout\bin\mahout (that's right - no .exe suffix, like a Linux executable)

#include "stdafx.h"
#define BUFSIZE 4096
#define VARNAME TEXT("MAHOUT_CP")
int _tmain(int argc, _TCHAR* argv[]) {
    DWORD dwLength;     LPTSTR pszBuffer;
    pszBuffer = (LPTSTR)malloc(BUFSIZE*sizeof(TCHAR));
    dwLength = GetEnvironmentVariable(VARNAME, pszBuffer, BUFSIZE);
    if (dwLength > 0) { _tprintf(TEXT("%s\n"), pszBuffer); return 0; }
    return 1;
}

(4) Create the script \mahout\bin\mahout.bat and paste in the content below, although the exact names of the jars in the _CP class paths will depend on the versions of spark and mahout. Update any paths per your installation. Use 8.3 path names without spaces in them. Note that you cannot use wildcards/asterisks in the classpaths here.

set SCALA_HOME=C:\Progra~2\scala
set SPARK_HOME=C:\spark
set HADOOP_HOME=C:\hadoop
set MAHOUT_HOME=C:\mahout
set SPARK_SCALA_VERSION=2.10
set MASTER=local[2]
set MAHOUT_LOCAL=true
set path=%SCALA_HOME%\bin;%SPARK_HOME%\bin;%PATH%
cd /D %SPARK_HOME%
set SPARK_CP=%SPARK_HOME%\conf\;%SPARK_HOME%\lib\xxx.jar;...other jars...
set MAHOUT_CP=%MAHOUT_HOME%\lib\xxx.jar;...other jars...;%MAHOUT_HOME%\xxx.jar;...other jars...;%SPARK_CP%;%MAHOUT_HOME%\lib\spark\xxx.jar;%MAHOUT_HOME%\lib\hadoop\xxx.jar;%MAHOUT_HOME%\src\conf;%JAVA_HOME%\lib\tools.jar
start "master0" "%JAVA_HOME%\bin\java" -cp "%SPARK_CP%" -Xms1g -Xmx1g org.apache.spark.deploy.master.Master --ip localhost --port 7077 --webui-port 8082 >>out-master0.log 2>>out-master0.err
start "worker1" "%JAVA_HOME%\bin\java" -cp "%SPARK_CP%" -Xms1g -Xmx1g org.apache.spark.deploy.worker.Worker spark://localhost:7077 --webui-port 8083 >>out-worker1.log 2>>out-worker1.err
...you may add more workers here...
cd /D %MAHOUT_HOME%
"%JAVA_HOME%\bin\java" -Xmx4g -classpath "%MAHOUT_CP%" "org.apache.mahout.sparkbindings.shell.Main"

The name of the variable MAHOUT_CP should not be changed, as it is referenced in the C++ code.

Of course you can comment-out the code that launches the Spark master and worker because Mahout will run Spark as-needed; I just put it in the batch job to show you how to launch it if you wanted to use Spark without Mahout.

(5) The following tutorial is a good place to begin:

https://mahout.apache.org/users/sparkbindings/play-with-shell.html

You can bring up the Mahout Spark instance at:

"C:\Program Files (x86)\Google\Chrome\Application\chrome" --disable-web-security http://localhost:4040

The guide by Ani Menon (thx!) almost worked for me on windows 10, i just had to get a newer winutils.exe off that git (currently hadoop-2.8.1): https://github.com/steveloughran/winutils


Here are seven steps to install spark on windows 10 and run it from python:

Step 1: download the spark 2.2.0 tar (tape Archive) gz file to any folder F from this link - https://spark.apache.org/downloads.html. Unzip it and copy the unzipped folder to the desired folder A. Rename the spark-2.2.0-bin-hadoop2.7 folder to spark.

Let path to the spark folder be C:\Users\Desktop\A\spark

Step 2: download the hardoop 2.7.3 tar gz file to the same folder F from this link - https://www.apache.org/dyn/closer.cgi/hadoop/common/hadoop-2.7.3/hadoop-2.7.3.tar.gz. Unzip it and copy the unzipped folder to the same folder A. Rename the folder name from Hadoop-2.7.3.tar to hadoop. Let path to the hadoop folder be C:\Users\Desktop\A\hadoop

Step 3: Create a new notepad text file. Save this empty notepad file as winutils.exe (with Save as type: All files). Copy this O KB winutils.exe file to your bin folder in spark - C:\Users\Desktop\A\spark\bin

Step 4: Now, we have to add these folders to the System environment.

4a: Create a system variable (not user variable as user variable will inherit all the properties of the system variable) Variable name: SPARK_HOME Variable value: C:\Users\Desktop\A\spark

Find Path system variable and click edit. You will see multiple paths. Do not delete any of the paths. Add this variable value - ;C:\Users\Desktop\A\spark\bin

4b: Create a system variable

Variable name: HADOOP_HOME Variable value: C:\Users\Desktop\A\hadoop

Find Path system variable and click edit. Add this variable value - ;C:\Users\Desktop\A\hadoop\bin

4c: Create a system variable Variable name: JAVA_HOME Search Java in windows. Right click and click open file location. You will have to again right click on any one of the java files and click on open file location. You will be using the path of this folder. OR you can search for C:\Program Files\Java. My Java version installed on the system is jre1.8.0_131. Variable value: C:\Program Files\Java\jre1.8.0_131\bin

Find Path system variable and click edit. Add this variable value - ;C:\Program Files\Java\jre1.8.0_131\bin

Step 5: Open command prompt and go to your spark bin folder (type cd C:\Users\Desktop\A\spark\bin). Type spark-shell.

C:\Users\Desktop\A\spark\bin>spark-shell

It may take time and give some warnings. Finally, it will show welcome to spark version 2.2.0

Step 6: Type exit() or restart the command prompt and go the spark bin folder again. Type pyspark:

C:\Users\Desktop\A\spark\bin>pyspark

It will show some warnings and errors but ignore. It works.

Step 7: Your download is complete. If you want to directly run spark from python shell then: go to Scripts in your python folder and type

pip install findspark

in command prompt.

In python shell

import findspark
findspark.init()

import the necessary modules

from pyspark import SparkContext
from pyspark import SparkConf

If you would like to skip the steps for importing findspark and initializing it, then please follow the procedure given in importing pyspark in python shell


Here is a simple minimum script to run from any python console. It assumes that you have extracted the Spark libraries that you have downloaded into C:\Apache\spark-1.6.1.

This works in Windows without building anything and solves problems where Spark would complain about recursive pickling.

import sys
import os
spark_home = 'C:\Apache\spark-1.6.1'

sys.path.insert(0, os.path.join(spark_home, 'python'))
sys.path.insert(0, os.path.join(spark_home, 'python\lib\pyspark.zip')) 
sys.path.insert(0, os.path.join(spark_home, 'python\lib\py4j-0.9-src.zip')) 

# Start a spark context:
sc = pyspark.SparkContext()

# 
lines = sc.textFile(os.path.join(spark_home, "README.md")
pythonLines = lines.filter(lambda line: "Python" in line)
pythonLines.first()

Cloudera and Hortonworks are the best tools to start up with the HDFS in Microsoft Windows. You can also use VMWare or VBox to initiate Virtual Machine to establish build to your HDFS and Spark, Hive, HBase, Pig, Hadoop with Scala, R, Java, Python.

참고URL : https://stackoverflow.com/questions/25481325/how-to-set-up-spark-on-windows

반응형