在VM中部署的独立群集中,Spark流不起作用

时间:2018-04-04 01:04:42

标签: scala apache-spark streaming spark-streaming scala-streams

我使用Scala编写了Kafka流程序并在Spark独立集群中执行。代码在我的本地工作正常。我在Azure VM中完成了Kafka,Cassandra和Spark设置。我已打开所有入站和出站端口以避免端口阻塞。

启动了主人

  

sbin目录> ./ start-master.sh

已启动奴隶

  

sbin#。/ start-slave.sh spark:// vm-hostname:7077

我已在Master WEB UI中验证了此状态。

提交作业

  

bin#。/ spark-submit --class x.y.StreamJob --master   spark:// vm-hostname:7077 /home/user/appl.jar

我注意到在WEB WEB UI中添加并显示了应用程序。

我已向主题发布了一些消息,并且未收到消息并将其保留到Cassandra DB。

我在主Web控制台上单击了应用程序名称,发现该应用程序控制台页面中没有 Streaming选项卡

为什么应用程序无法在VM中运行并且在本地运行良好?

如何在VM中调试问题?

def main(args: Array[String]): Unit = {
    val spark = SparkHelper.getOrCreateSparkSession()
    val ssc = new StreamingContext(spark.sparkContext, Seconds(1))
    spark.sparkContext.setLogLevel("WARN")
    val kafkaStream = {
      val kafkaParams = Map[String, Object](
        "bootstrap.servers" -> 
                "vmip:9092",
        "key.deserializer" -> classOf[StringDeserializer],
        "value.deserializer" -> classOf[StringDeserializer],
        "group.id" -> "loc",
        "auto.offset.reset" -> "latest",
        "enable.auto.commit" -> (false: java.lang.Boolean)
      )

      val topics = Array("hello")
      val numPartitionsOfInputTopic = 3
      val streams = (1 to numPartitionsOfInputTopic) map {
        _ => KafkaUtils.createDirectStream[String, String]( ssc, PreferConsistent, Subscribe[String, String](topics, kafkaParams) )
      }
     streams
    }


    kafkaStream.foreach(rdd=> {
      rdd.foreachRDD(conRec=> {
        val offsetRanges = conRec.asInstanceOf[HasOffsetRanges].offsetRanges
        conRec.foreach(str=> {
          try {
            println(str.value().trim)
            CassandraHelper.saveItemEvent(str.value().trim)

          }catch {
            case ex: Exception => {
              println(ex.getMessage)
            }
          }
        })
        rdd.asInstanceOf[CanCommitOffsets].commitAsync(offsetRanges)
      })
      println("Read Msg")
    })
    println(" Spark parallel reader is ready !!!")
    ssc.start()
    ssc.awaitTermination()
  }

  def getSparkConf(): SparkConf = {
    val conf = new SparkConf(true)
      .setAppName("TestAppl")
      .set("spark.cassandra.connection.host", "vmip")
      .set("spark.streaming.stopGracefullyOnShutdown","true")
    .setMaster("spark://vm-hostname:7077")

    conf
  }

版本

scalaVersion := "2.11.8"
val sparkVersion = "2.2.0"
val connectorVersion = "2.0.7"


libraryDependencies ++= Seq(
  "org.apache.spark" %% "spark-core" % sparkVersion %"provided",
  "org.apache.spark" %% "spark-sql" % sparkVersion  %"provided",
  "org.apache.spark" %% "spark-hive" % sparkVersion %"provided",
  "com.datastax.spark" %% "spark-cassandra-connector" % connectorVersion  ,
  "org.apache.kafka" %% "kafka" % "0.10.1.0",
  "org.apache.spark" %% "spark-streaming-kafka-0-10" % sparkVersion,
  "org.apache.spark" %% "spark-streaming" %  sparkVersion  %"provided",
)
mergeStrategy in assembly := {
  case PathList("org", "apache", "spark", "unused", "UnusedStubClass.class") => MergeStrategy.first
  case x => (mergeStrategy in assembly).value(x)
}

1 个答案:

答案 0 :(得分:0)

要调试您的问题,首先要考虑的是确保消息通过Kafka。为此,您需要在VM上打开端口9092并尝试consuming directly from Kafka

bin/kafka-console-consumer.sh --bootstrap-server vmip:9092 --topic hello --from-beginning

从头开始选项将消耗您在Kafka主题上配置的最长保留时间。

检查您的VM中没有2个版本的Spark,并且需要使用“spark2-submit”提交Spark2作业。