Spark RDD问题

Spark RDD problems

我刚开始使用 spark,从未使用过 Hadoop。我有 10 台 iMac,我在上面安装了 Spark 1.6.1 和 Hadoop 2.6。我下载了预编译版本,只是将提取的内容复制到 /usr/local/spark/ 中。我使用 SCALA_HOME 设置了所有环境变量,对 PATH 和其他 spark conf 进行了更改。我能够 运行 spark-shellpyspark(使用 anaconda 的 python)。

我已经设置了独立集群;所有节点都出现在我的网站上 UI。现在,通过使用 python shell (集群上的 运行 而不是本地),我遵循了 this link's python interpreter word count example.

这是我用过的代码

from operator import add

def tokenize(text):
    return text.split()

text = sc.textFile("Testing/shakespeare.txt")
words = text.flatMap(tokenize)
wc = words.map(lambda x: (x,1))
counts = wc.reduceByKey(add)

counts.saveAsTextFile("wc")

在从属节点上找不到文件 shakespeare.txt 给我一个错误。四处搜索我了解到,如果我不使用 HDFS,那么该文件应该存在于同一路径上的每个从属节点上。这是堆栈跟踪 - github gist

现在,我有几个问题-

如果您阅读 Spark Programming Guide,您会找到第一个问题的答案:

To illustrate RDD basics, consider the simple program below:

val lines = sc.textFile("data.txt")
val lineLengths = lines.map(s => s.length)
val totalLength = lineLengths.reduce((a, b) => a + b)

The first line defines a base RDD from an external file. This dataset is not loaded in memory or otherwise acted on: lines is merely a pointer to the file. The second line defines lineLengths as the result of a map transformation. Again, lineLengths is not immediately computed, due to laziness. Finally, we run reduce, which is an action. At this point Spark breaks the computation into tasks to run on separate machines, and each machine runs both its part of the map and a local reduction, returning only its answer to the driver program.

请记住,转换是在 Spark worker 上执行的(参见 link,幻灯片 n.21)。

关于您的第二个问题,如您所见,Spark 仅包含使用 Hadoop 基础架构的库。您需要先设置 Hadoop 集群(Hdfs 等),以便使用它(使用 Spark 中的库):查看 Hadoop Cluster Setup.

为了回答你的最后一个问题,我希望official documentation helps, in particular Spark Standalone