您好,登錄后才能下訂單哦!
1、說(shuō)明
這篇文章是在xxx基礎(chǔ)上進(jìn)行部署的,需要hadoop的相關(guān)配置和依賴等等,Spark on Yarn的模式,Spark安裝配置好即可,在Yarn集群的所有節(jié)點(diǎn)安裝并同步配置,在無(wú)需啟動(dòng)服務(wù),沒(méi)有master、slave之分,Spark提交任務(wù)給Yarn,由ResourceManager做任務(wù)調(diào)度。
2、安裝
yum -y install spark-core spark-netlib spark-python
3、配置
vim /etc/spark/conf/spark-defaults.conf spark.eventLog.enabled false spark.executor.extraJavaOptions -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=70 -XX:MaxHeapFreeRatio=70 -XX:+CMSClassUnloadingEnabled spark.driver.extraJavaOptions -Dspark.driver.log.level=INFO -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=70 -XX:MaxHeapFreeRatio=70 -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=512M spark.master yarn ##指定spark的運(yùn)行模式
PS:關(guān)于spark-env.sh的配置,因?yàn)槲业膆adoop集群是通過(guò)yum安裝的,估使用默認(rèn)配置就可以找到hadoop的相關(guān)配置和依賴,如果hadoop集群是二進(jìn)制包安裝需要修改相應(yīng)的路徑
4、測(cè)試
a、通過(guò)spark-shell 測(cè)試
[root@ip-10-10-103-144 conf]# cat test.txt 11 22 33 44 55 [root@ip-10-10-103-144 conf]# hadoop fs -put test.txt /tmp/ Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0 [roo[root@ip-10-10-103-246 conf]# spark-shell Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0 Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/usr/lib/zookeeper/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/usr/lib/flume-ng/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/usr/lib/parquet/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/usr/lib/avro/avro-tools-1.7.6-cdh6.11.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /___/ .__/\_,_/_/ /_/\_\ version 1.6.0 /_/ Using Scala version 2.10.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_121) Type in expressions to have them evaluated. Type :help for more information. Spark context available as sc (master = yarn-client, app id = application_1494472050574_0009). SQL context available as sqlContext. scala> val file=sc.textFile("hdfs://mycluster:8020/tmp/test.txt") file: org.apache.spark.rdd.RDD[String] = hdfs://mycluster:8020/tmp/test.txt MapPartitionsRDD[1] at textFile at <console>:27 scala> val count=file.flatMap(line=>line.split(" ")).map(test=>(test,1)).reduceByKey(_+_) count: org.apache.spark.rdd.RDD[(String, Int)] = ShuffledRDD[4] at reduceByKey at <console>:29 scala> count.collect() res0: Array[(String, Int)] = Array((33,1), (55,1), (22,1), (44,1), (11,1)) scala>
b、通過(guò)run-example測(cè)試
[root@ip-10-10-103-246 conf]# /usr/lib/spark/bin/run-example SparkPi 2>&1 | grep "Pi is roughly" Pi is roughly 3.1432557162785812
5、遇到的問(wèn)題
執(zhí)行spark-shell計(jì)算報(bào)錯(cuò)如下:
scala> val count=file.flatMap(line=>line.split(" ")).map(word=>(word,1)).reduceByKey(_+_) 17/05/11 21:06:28 ERROR lzo.GPLNativeCodeLoader: Could not load native gpl library java.lang.UnsatisfiedLinkError: no gplcompression in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at com.hadoop.compression.lzo.GPLNativeCodeLoader.<clinit>(GPLNativeCodeLoader.java:32) at com.hadoop.compression.lzo.LzoCodec.<clinit>(LzoCodec.java:71) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at $line20.$read.<init>(<console>:48) at $line20.$read$.<init>(<console>:52) at $line20.$read$.<clinit>(<console>) at $line20.$eval$.<init>(<console>:7) at $line20.$eval$.<clinit>(<console>) at $line20.$eval.$print(<console>) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.spark.repl.SparkIMain$ReadEvalPrint.call(SparkIMain.scala:1045) at org.apache.spark.repl.SparkIMain$Request.loadAndRun(SparkIMain.scala:1326) at org.apache.spark.repl.SparkIMain.loadAndRunReq$1(SparkIMain.scala:821) at org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:852) at org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:800) at org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:857) at org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:902)
解決方案:
在spark-env.sh添加
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/hadoop/lib/native/
讓Spark能找到lzo的lib包即可。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。