centos8 安装 flink 并测试 wordcount

开发环境和所需软件

  • centos 8
  • java
  • flink
安装 flink

我们选择安装的是 flink 目前的最新版本 1.9 版本 , 安装前请保证 java 已经正常安装

  • 检查 java 是否安装

    [vagrant@3b5a73745ce45650 ~]$ java -version
    openjdk version "1.8.0_232"
    OpenJDK Runtime Environment (build 1.8.0_232-b09)
    OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
    
  • 下载 flink 二进制包

    [vagrant@3b5a73745ce45650 ~]$ wget http://mirror.bit.edu.cn/apache/flink/flink-1.9.1/flink-1.9.1-bin-scala_2.11.tgz
    --2019-12-25 15:24:32--  http://mirror.bit.edu.cn/apache/flink/flink-1.9.1/flink-1.9.1-bin-scala_2.11.tgz
    Resolving mirror.bit.edu.cn (mirror.bit.edu.cn)... 114.247.56.117, 2001:da8:204:1205::22
    Connecting to mirror.bit.edu.cn (mirror.bit.edu.cn)|114.247.56.117|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 255543307 (244M) [application/octet-stream]
    Saving to: ‘flink-1.9.1-bin-scala_2.11.tgz’
    
    flink-1.9.1-bin-scala_2.11.tgz                  100%[=======================================================================================================>] 243.71M  3.06MB/s    in 65s     
    
    2019-12-25 15:25:37 (3.74 MB/s) - ‘flink-1.9.1-bin-scala_2.11.tgz’ saved [255543307/255543307]
    
  • 解压 flink 二进制包到 /usr/local

    sudo tar -zxvf flink-1.9.1-bin-scala_2.11.tgz  -C /usr/local
    cd /usr/local
    sudo mv flink-1.9.1/ flink
    
  • 启动和停止 flink 的命令

    • 启动 flink

      sudo ./flink/bin/start-cluster.sh
      
    • 停止 flink

      sudo ./flink/bin/stop-cluster.sh
      
  • 启动 flink 后,可以 curl 命令,查看 flink 自带的 web 管理页面来检查 flink 是否启动成功

    [vagrant@3b5a73745ce45650 ~]$ curl 127.0.0.1:8081
    <!--
      ~ Licensed to the Apache Software Foundation (ASF) under one
      ~ or more contributor license agreements.  See the NOTICE file
      ~ distributed with this work for additional information
      ~ regarding copyright ownership.  The ASF licenses this file
      ~ to you under the Apache License, Version 2.0 (the
      ~ "License"); you may not use this file except in compliance
      ~ with the License.  You may obtain a copy of the License at
      ~
      ~     http://www.apache.org/licenses/LICENSE-2.0
      ~
      ~ Unless required by applicable law or agreed to in writing, software
      ~ distributed under the License is distributed on an "AS IS" BASIS,
      ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      ~ See the License for the specific language governing permissions and
      ~ limitations under the License.
      -->
    
    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>Apache Flink Web Dashboard</title>
      <link rel="apple-touch-icon" sizes="180x180" href="assets/favicon/apple-touch-icon.png">
      <link rel="icon" type="image/png" href="assets/favicon/favicon-32x32.png" sizes="32x32">
      <link rel="icon" type="image/png" href="assets/favicon/favicon-16x16.png" sizes="16x16">
      <link rel="manifest" href="assets/favicon/manifest.json">
      <link rel="mask-icon" href="assets/favicon/safari-pinned-tab.svg" color="#aa1919">
      <link rel="shortcut icon" href="assets/favicon/favicon.ico">
      <meta name="msapplication-config" content="assets/favicon/browserconfig.xml">
      <meta name="theme-color" content="#ffffff">
      <base href="./"><link rel="stylesheet" href="styles.30d0912c1ece284d8d9a.css"></head>
    <body>
      <flink-root></flink-root>
    <script type="text/javascript" src="runtime.440aa244803781d5f83e.js"></script><script type="text/javascript" src="es2015-polyfills.5e343224e81eefb7658e.js" nomodule></script><script type="text/javascript" src="polyfills.b37850e8279bc3caafc9.js"></script><script type="text/javascript" src="main.69b429cff67b392733d5.js"></script></body>
    </html>
    
    
测试 wordcount 程序

flink 本身就为我们自带了很多的测试样例,样例都放在 flink 项目的 examples 文件夹里,因为 flink 本身非常擅长流式计算,我们特意选用 examples/streaming 下的流式计算的样例 SocketWindowWordCount.jar 来演示flink 的功能

  • 因为是流的样例,所以我们要先建立一个流,在我们的样例里我们用Socket来作为流

  • 监听本地的 9000 端口

    nc -l 9000
    
  • 运行 worlcount 程序

    cd /usr/local/flink
    sudo bin/flink run examples/streaming/SocketWindowWordCount.jar --port 9000
    
  • 在 nc 运行的 shell 如下如下的字符,记得按回车

    [vagrant@3b5a73745ce45650 ~]$ nc -l 9000
    hello world! hello
    
  • 在 flink/log 目录下运行 tail -f flink*.out 即可发现 flink 已经成功为我们统计出 hello 出现两次 world! 出现一次

    [vagrant@3b5a73745ce45650 log]$ tail -f flink*.out
    ==> flink-root-standalonesession-1-3b5a73745ce45650.out <==
    
    ==> flink-root-taskexecutor-1-3b5a73745ce45650.out <==
    hello : 2
    world! : 1
    

你可能感兴趣的:(flink,flink,java,linux)