我试图演示在分布式Spark集群上运行Pyspark Mllib脚本。它可以在本地Spark会话(Windows 10)上运行,但是在将主服务器设置为具有两个从属服务器的远程计算机(全部为Ubuntu 18.04)时失败。我认为这是因为必须从所有节点都可以访问本地培训数据文件。为此,我在主服务器上设置了NFS以共享文件。
作为一个演示,我希望避免使用任何繁重的解决方案,例如设置Hadoop或使用S3存储桶。 Spark文档说我可以使用NFS,因此我已经在Spark主节点上设置了NFS服务器,在根目录中创建了一个“共享”目录,与从属节点共享,并从从属节点将其挂载为“共享” ,并检查它是否可以在主服务器和从服务器的命令行中正常工作。
我已修改示例代码以尝试如下在远程集群上运行它:
```
"""
Random Forest Regressor Example - modified for distributed cluster.
"""
from __future__ import print_function
from pyspark.ml import Pipeline
from pyspark.ml.regression import RandomForestRegressor
from pyspark.ml.feature import VectorIndexer
from pyspark.ml.evaluation import RegressionEvaluator
from pyspark.sql import SparkSession
if __name__ == "__main__":
spark = SparkSession\
.builder\
.appName("RandomForestRegressorExample")\
.master("spark://10.20.0.163:7077")\
.getOrCreate()
data = spark.read.format("libsvm").load\
("file:////share//sample_libsvm_data.txt")
```
运行脚本时,出现错误“ AnalysisException:'路径不存在:file:/share/sample_libsvm_data.txt;”
完整的错误响应:
---------------------------------------------------------------------------
Py4JJavaError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\pyspark\sql\utils.py in deco(*a, **kw)
62 try:
---> 63 return f(*a, **kw)
64 except py4j.protocol.Py4JJavaError as e:
C:\ProgramData\Anaconda3\lib\site-packages\py4j\protocol.py in get_return_value(answer, gateway_client, target_id, name)
327 "An error occurred while calling {0}{1}{2}.\n".
--> 328 format(target_id, ".", name), value)
329 else:
Py4JJavaError: An error occurred while calling o108.load.
: org.apache.spark.sql.AnalysisException: Path does not exist: file:/share/sample_libsvm_data.txt;
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$org$apache$spark$sql$execution$datasources$DataSource$$checkAndGlobPathIfNecessary$1.apply(DataSource.scala:558)
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$org$apache$spark$sql$execution$datasources$DataSource$$checkAndGlobPathIfNecessary$1.apply(DataSource.scala:545)
at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
at scala.collection.immutable.List.foreach(List.scala:392)
at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:241)
at scala.collection.immutable.List.flatMap(List.scala:355)
at org.apache.spark.sql.execution.datasources.DataSource.org$apache$spark$sql$execution$datasources$DataSource$$checkAndGlobPathIfNecessary(DataSource.scala:545)
at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:359)
at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:223)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:211)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:178)
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 py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:748)
During handling of the above exception, another exception occurred:
AnalysisException Traceback (most recent call last)
<ipython-input-22-fcd877efb9c4> in <module>
37 .getOrCreate()
38
---> 39 data = spark.read.format("libsvm").load("file:////share//sample_libsvm_data.txt")
40
C:\ProgramData\Anaconda3\lib\site-packages\pyspark\sql\readwriter.py in load(self, path, format, schema, **options)
164 self.options(**options)
165 if isinstance(path, basestring):
--> 166 return self._df(self._jreader.load(path))
167 elif path is not None:
168 if type(path) != list:
C:\ProgramData\Anaconda3\lib\site-packages\py4j\java_gateway.py in __call__(self, *args)
1255 answer = self.gateway_client.send_command(command)
1256 return_value = get_return_value(
-> 1257 answer, self.gateway_client, self.target_id, self.name)
1258
1259 for temp_arg in temp_args:
C:\ProgramData\Anaconda3\lib\site-packages\pyspark\sql\utils.py in deco(*a, **kw)
67 e.java_exception.getStackTrace()))
68 if s.startswith('org.apache.spark.sql.AnalysisException: '):
---> 69 raise AnalysisException(s.split(': ', 1)[1], stackTrace)
70 if s.startswith('org.apache.spark.sql.catalyst.analysis'):
71 raise AnalysisException(s.split(': ', 1)[1], stackTrace)
AnalysisException: 'Path does not exist: file:/share/sample_libsvm_data.txt;'
我有几个问题:
1)是否有更好的方法将数据从可以快速设置的单个文件获取到分布式群集?我曾尝试加载到本地会话数据帧中,然后将其复制到分布式数据帧中,但也未能实现。
2)失败了,我应该如何设置NSF共享路径以使其起作用?
3)或者,我是否正在犯其他阻止其正常工作的错误?