Flink运行自带SocketWindowWordCount.jar报错Job failed 和 Connection refused (Connection refused)

Flink运行自带SocketWindowWordCount.jar报错Job failed 和 Connection refused (Connection refused)_第1张图片

第一个原因:没有

nc -l 9000

的情况下直接执行了这句话 

./bin/flink run examples/streaming/SocketWindowWordCount.jar --port 9000

第二个原因:端口号最好换一个,如果配置了连接hdfs的话

第三个原因:其实因为你配置了hdfs环境的原因,仔细想想,你是不是修改了

vim conf/flink-conf.yaml

改成了这个样子:

Flink运行自带SocketWindowWordCount.jar报错Job failed 和 Connection refused (Connection refused)_第2张图片

说到这里想必大家都明白怎么回事了吧,接下来是官方的文档给出的demo:

object SocketWindowWordCount {

    def main(args: Array[String]) : Unit = {

        // the port to connect to
        val port: Int = try {
            ParameterTool.fromArgs(args).getInt("port")
        } catch {
            case e: Exception => {
                System.err.println("No port specified. Please run 'SocketWindowWordCount --port '")
                return
            }
        }

        // get the execution environment
        val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

        // get input data by connecting to the socket
        val text = env.socketTextStream("localhost", port, '\n')

        // parse the data, group it, window it, and aggregate the counts
        val windowCounts = text
            .flatMap { w => w.split("\\s") }
            .map { w => WordWithCount(w, 1) }
            .keyBy("word")
            .timeWindow(Time.seconds(5), Time.seconds(1))
            .sum("count")

        // print the results with a single thread, rather than in parallel
        windowCounts.print().setParallelism(1)

        env.execute("Socket Window WordCount")
    }

    // Data type for words with count
    case class WordWithCount(word: String, count: Long)
}

地址需要改吗,当然

localhost等于你配置的节点吗?不等于, 所以我修改了如下代码

修改运行地址

Flink运行自带SocketWindowWordCount.jar报错Job failed 和 Connection refused (Connection refused)_第3张图片

增加保存数据到节点本地的语句,为什么修改,那个print是看不到效果的

接下来就是打包,集群运行,

./bin/start-cluster.sh

nc -l 9009

./bin/flink run -class com.demo.SocketWindowWordCount examples/streaming/demo-1.0-SNAPSHOT.jar --port 9009

然后nc端发消息,你会惊奇的发现,接收端口并没有数据,不要紧,咱保存到本地了

去查看,发现了,/opt/software/下面没有wordcount.txt

node02是什么,namenode,不负责存储数据的,到集群其他节点查看数据,至此,报错解决,

结语,其实如果非得运行官方demo的话只需要在另一个地方解压flink安装包,然后运行就可以了,可以避免这个错误!!!

 

你可能感兴趣的:(linux,scala,大数据,大数据,Flink)