我想在群集上运行我的代码:我的代码:
import java.util.Properties
import edu.stanford.nlp.ling.CoreAnnotations._
import edu.stanford.nlp.pipeline._
import org.apache.spark.{SparkConf, SparkContext}
import scala.collection.JavaConversions._
import scala.collection.mutable.ArrayBuffer
object Pre2 {
def plainTextToLemmas(text: String, pipeline: StanfordCoreNLP): Seq[String] = {
val doc = new Annotation(text)
pipeline.annotate(doc)
val lemmas = new ArrayBuffer[String]()
val sentences = doc.get(classOf[SentencesAnnotation])
for (sentence <- sentences; token <- sentence.get(classOf[TokensAnnotation])) {
val lemma = token.get(classOf[LemmaAnnotation])
if (lemma.length > 0 ) {
lemmas += lemma.toLowerCase
}
}
lemmas
}
def main(args: Array[String]): Unit = {
val conf = new SparkConf()
.setMaster("local")
.setAppName("pre2")
val sc = new SparkContext(conf)
val plainText = sc.textFile("data/in.txt")
val lemmatized = plainText.mapPartitions(p => {
val props = new Properties()
props.put("annotators", "tokenize, ssplit, pos, lemma")
val pipeline = new StanfordCoreNLP(props)
p.map(q => plainTextToLemmas(q, pipeline))
})
val lemmatized1 = lemmatized.map(l => l.head + l.tail.mkString(" "))
val lemmatized2 = lemmatized1.filter(_.nonEmpty)
lemmatized2.coalesce(1).saveAsTextFile("data/out.txt)
}
}
和群集功能:
每个节点有2个节点:每个节点有60g RAM:48个内核共享磁盘
我在这个集群上安装了Spark,其中一个节点是master和worker,另一个节点是worker .
当我在终端中使用此命令运行我的代码时:
./bin/spark-submit --master spark://192.168.1.20:7077 --class Main --deploy-mode cluster code / Pre2.jar
表明 :
15/08/19 15:27:21 WARN RestSubmissionClient:无法连接到服务器spark://192.168.1.20:7077 . 警告:主 endpoints spark://192.168.1.20:7077不是REST服务器 . 而是回到遗留提交网关 . 15/08/19 15:27:22 WARN NativeCodeLoader:无法为您的平台加载native-hadoop库...使用内置的java类,其中适用的驱动程序成功提交为驱动程序-2010819152724-0002 ...在轮询主服务器之前等待驱动程序状态...驱动程序状态的轮询主机驱动程序状态20150819152724-0002是运行在1192.168.1.19:33485上的运行驱动程序(worker-20150819115013-192.168.1.19-33485)
如何在Spark独立集群上运行上面的代码?
3 回答
确保使用
8080
port检出WebUI . 在你的例子中它将是192.168.1.20:8080
.如果您在Spark Standalone Cluster模式下运行它,请尝试不使用
--deploy-mode cluster
并通过添加--executor-memory 60g
硬编码节点内存“警告:主 endpoints spark://192.168.1.20:7077不是REST服务器”从错误中,它看起来也像主要的其他URL不同 . 其余的URL可以在master_url:8080 UI上找到
如果两个节点都出现在Spark UI上,请检查群集,使用给定的配置,我将在节点上启动worker .
您已将主服务器硬编码为本地.setMaster(“local”)将其删除或将其替换为主网址 .
我假设您要在spark独立群集模式下运行,而不是在纱线群集模式下运行 . 因为配置的其余部分是为此