Win10环境下测试Spark Streaming处理端口数据

今日测试了Win10环境下Spark Streaming处理端口数据,过程如下:
首先需监听程序对应的端口,Win10不存在Linux下的nc命令,需下载netcat,解压后将nc.exe拷贝到C:\Windows下,此时nc -l -p 端口号 即可开始监听,本人的测试端口号为6789,在shell中输入如下命令后:

nc -l -p 6789

启动程序时报错:

19/07/08 20:43:37 INFO spark.SparkContext: Running Spark version 2.2.0
19/07/08 20:43:37 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
19/07/08 20:43:37 ERROR util.Shell: Failed to locate the winutils binary in the hadoop binary path
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
	at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:378)
	at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:393)
	at org.apache.hadoop.util.Shell.(Shell.java:386)
	at org.apache.hadoop.util.StringUtils.(StringUtils.java:79)
	at org.apache.hadoop.security.Groups.parseStaticMapping(Groups.java:130)
	at org.apache.hadoop.security.Groups.(Groups.java:94)
	at org.apache.hadoop.security.Groups.(Groups.java:74)
	at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:303)
	at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:283)
	at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:260)
	at org.apache.hadoop.security.UserGroupInformation.loginUserFromSubject(UserGroupInformation.java:790)
	at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:760)
	at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:633)
	at org.apache.spark.util.Utils$$anonfun$getCurrentUserName$1.apply(Utils.scala:2430)
	at org.apache.spark.util.Utils$$anonfun$getCurrentUserName$1.apply(Utils.scala:2430)
	at scala.Option.getOrElse(Option.scala:121)
	at org.apache.spark.util.Utils$.getCurrentUserName(Utils.scala:2430)
	at org.apache.spark.SparkContext.(SparkContext.scala:295)
	at org.apache.spark.streaming.StreamingContext$.createNewSparkContext(StreamingContext.scala:839)
	at org.apache.spark.streaming.StreamingContext.(StreamingContext.scala:85)
	at com.dblab.spark.SqlNetworkWordCount$.main(SqlNetworkWordCount.scala:15)
	at com.dblab.spark.SqlNetworkWordCount.main(SqlNetworkWordCount.scala)

百度了下解决方案,本人按如下方式操作,亲测可用:

  1. 首先下载winutils.exe,在D盘下创建一个名为Hadoop的文件夹,在此文件夹下再创建一个bin文件夹,把winutils.exe放到bin文件夹下
  2. 代码添加:System.setProperty("hadoop.home.dir", "D:\\Hadoop")即可,不需在本地下载Hadoop,也不需配置环境变量

配置成功后,此处问题解决,但是后面又报错:

19/07/08 20:56:53 WARN receiver.ReceiverSupervisorImpl: Restarting receiver with delay 2000 ms: Error connecting to localhost:6789
java.net.ConnectException: Connection refused: connect
	at java.net.DualStackPlainSocketImpl.connect0(Native Method)
	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at java.net.Socket.connect(Socket.java:538)
	at java.net.Socket.(Socket.java:434)
	at java.net.Socket.(Socket.java:211)
	at org.apache.spark.streaming.dstream.SocketReceiver.onStart(SocketInputDStream.scala:61)
	at org.apache.spark.streaming.receiver.ReceiverSupervisor.startReceiver(ReceiverSupervisor.scala:149)
	at org.apache.spark.streaming.receiver.ReceiverSupervisor.start(ReceiverSupervisor.scala:131)
	at org.apache.spark.streaming.scheduler.ReceiverTracker$ReceiverTrackerEndpoint$$anonfun$9.apply(ReceiverTracker.scala:607)
	at org.apache.spark.streaming.scheduler.ReceiverTracker$ReceiverTrackerEndpoint$$anonfun$9.apply(ReceiverTracker.scala:597)
	at org.apache.spark.SparkContext$$anonfun$34.apply(SparkContext.scala:2173)
	at org.apache.spark.SparkContext$$anonfun$34.apply(SparkContext.scala:2173)
	at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)
	at org.apache.spark.scheduler.Task.run(Task.scala:108)
	at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:335)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

程序相关配置如下:

    val sparkConf = new SparkConf().setAppName("SqlNetworkWordCount").setMaster("local[2]")

此处已经考虑到Receiver接收端口数据时需要一个线程,故setMaster(“local[2]”),但是仍然报错,于是考虑是否为端口问题,故将端口变为9999,重新监听9999接口并启动程序,成功!
附截图:
在这里插入图片描述
Win10环境下测试Spark Streaming处理端口数据_第1张图片

你可能感兴趣的:(Win10环境下测试Spark Streaming处理端口数据)