共用方式為


在閘道模式中啟動 SQL 用戶端 CLI

重要

此功能目前為預覽功能。 適用於 Microsoft Azure 預覽版的補充使用規定包含適用於 Beta 版、預覽版或尚未發行至正式運作之 Azure 功能的更合法條款。 如需此特定預覽的相關信息,請參閱 AKS 預覽資訊的 Azure HDInsight。 如需問題或功能建議,請在 AskHDInsight提交要求,並提供詳細數據,並遵循我們在 Azure HDInsight 社群取得更多更新。

本教學課程會引導您如何在 AKS 上的 HDInsight 上的 Apache Flink 叢集 1.17.0 中,以網關模式啟動 SQL 用戶端 CLI。 在閘道模式中,CLI 會將 SQL 提交至指定的遠端閘道來執行語句。

./bin/sql-client.sh gateway --endpoint <gateway address>

注意

在 AKS 上的 HDInsight 上的 Apache Flink 叢集中,任何外部連線都會透過 443 埠進行。 但在內部,它會將要求重新路由傳送至接聽埠 8083 的 sql-gateway 服務。

檢查 AKS 端的 sql 閘道服務:

顯示如何檢查 SQL 閘道的螢幕快照。

Flink 的數據表和 SQL API 可讓您使用以 SQL 語言撰寫的查詢,但這些查詢需要內嵌在以 Java 或 Scala 撰寫的數據表程式內。 此外,這些程式必須先使用建置工具封裝,才能提交至叢集。 此功能會將 Flink 的使用限制為 Java/Scala 程式設計人員。

SQL Client 旨在提供簡單的撰寫、偵錯和將數據表程式提交至 Flink 叢集的方式,而不需要單行 Java 或 Scala 程式代碼。 SQL 用戶端 CLI 可讓您從命令行上執行中的分散式應用程式擷取和可視化實時結果。

如需詳細資訊,請參閱 如何在 Webssh 上輸入 Flink SQL CLI 用戶端。

SQL 閘道是一項服務,可讓來自遠端的多個用戶端在並行中執行 SQL。 它可讓您輕鬆提交 Flink 作業、查閱元數據,以及在線分析數據。

如需詳細資訊,請參閱 SQL 閘道

在 AKS 上的 HDInsight 上的 Apache Flink 叢集中,執行 命令以閘道模式啟動 SQL 用戶端 CLI:

./bin/sql-client.sh gateway --endpoint host:port
 
or
 
./bin/sql-client.sh gateway --endpoint https://fqdn/sql-gateway

取得 Azure 入口網站 上的叢集端點(主機或 fqdn)。

顯示叢集端點的螢幕快照。

測試

準備

  1. https://aka.ms/hdionaksflink117clilinux 本機 Windows 電腦下載 Flink CLI。

安裝 Windows 子系統 Linux 版,讓此功能在本機 Windows 電腦上運作。

  1. 開啟 Windows 命令並執行 (以您自己的方式取代 JAVA_HOME 和 flink-cli 路徑),以下載 flink-cli:

    Windows Subsystem for Linux --distribution Ubuntu 
    export JAVA_HOME=/mnt/c/Work/99_tools/zulu11.56.19-ca-jdk11.0.15-linux_x64
    cd <folder>
    wget https://hdiconfigactions.blob.core.windows.net/hiloflink17blob/flink-cli.tgz
    tar -xvf flink-cli.tgz
    
  2. 在 flink-conf.yaml 中設定端點、租用戶標識碼和埠 443

    user@MININT-481C9TJ:/mnt/c/Users/user/flink-cli$ cd conf
    user@MININT-481C9TJ:/mnt/c/Users/user/flink-cli/conf$ ls -l
    total 8
    -rwxrwxrwx 1 user user 2451 Feb 26 20:33 flink-conf.yaml
    -rwxrwxrwx 1 user user 2946 Feb 23 14:13 log4j-cli.properties
    
    user@MININT-481C9TJ:/mnt/c/Users/user/flink-cli/conf$ cat flink-conf.yaml
    
    rest.address: <flink cluster endpoint on Azure portal>
    azure.tenant.id: <tenant ID>
    rest.port: 443
    
  3. Allowlist Local Windows public IP with port 443 with VPN enabled into HDInsight on AKS cluster Subnet's Network security inbound.

    顯示如何允許公用IP位址的螢幕快照。

  4. 在 Flink-cli 至 Flink SQL 的閘道模式中執行 sql-client.sh。

    bin/sql-client.sh gateway --endpoint https://fqdn/sql-gateway
    

    範例

    user@MININT-481C9TJ:/mnt/c/Users/user/flink-cli$ bin/sql-client.sh gateway --endpoint https://fqdn/sql-gateway
    
                                       ▒▓██▓██▒
                                   ▓████▒▒█▓▒▓███▓▒
                                ▓███▓░░        ▒▒▒▓██▒  ▒
                              ░██▒   ▒▒▓▓█▓▓▒░      ▒████
                              ██▒         ░▒▓███▒    ▒█▒█▒
                                ░▓█            ███   ▓░▒██
                                  ▓█       ▒▒▒▒▒▓██▓░▒░▓▓█
                                █░ █   ▒▒░       ███▓▓█ ▒█▒▒▒
                                ████░   ▒▓█▓      ██▒▒▒ ▓███▒
                             ░▒█▓▓██       ▓█▒    ▓█▒▓██▓ ░█░
                       ▓░▒▓████▒ ██         ▒█    █▓░▒█▒░▒█▒
                      ███▓░██▓  ▓█           █   █▓ ▒▓█▓▓█▒
                    ░██▓  ░█░            █  █▒ ▒█████▓▒ ██▓░▒
                   ███░ ░ █░          ▓ ░█ █████▒░░    ░█░▓  ▓░
                  ██▓█ ▒▒▓▒          ▓███████▓░       ▒█▒ ▒▓ ▓██▓
               ▒██▓ ▓█ █▓█       ░▒█████▓▓▒░         ██▒▒  █ ▒  ▓█▒
               ▓█▓  ▓█ ██▓ ░▓▓▓▓▓▓▓▒              ▒██▓           ░█▒
               ▓█    █ ▓███▓▒░              ░▓▓▓███▓          ░▒░ ▓█
               ██▓    ██▒    ░▒▓▓███▓▓▓▓▓██████▓▒            ▓███  █
              ▓███▒ ███   ░▓▓▒░░   ░▓████▓░                  ░▒▓▒  █▓
              █▓▒▒▓▓██  ░▒▒░░░▒▒▒▒▓██▓░                            █▓
              ██ ▓░▒█   ▓▓▓▓▒░░  ▒█▓       ▒▓▓██▓    ▓▒          ▒▒▓
              ▓█▓ ▓▒█  █▓░  ░▒▓▓██▒            ░▓█▒   ▒▒▒░▒▒▓█████▒
               ██░ ▓█▒█▒  ▒▓▓▒  ▓█                █░      ░░░░   ░█▒
               ▓█   ▒█▓   ░     █░                ▒█              █▓
                █▓   ██         █░                 ▓▓        ▒█▓▓▓▒█░
                 █▓ ░▓██░       ▓▒                  ▓█▓▒░░░▒▓█░    ▒█
                  ██   ▓█▓░      ▒                    ░▒█▒██▒      ▓▓
                   ▓█▒   ▒█▓▒░                         ▒▒ █▒█▓▒▒░░▒██
                    ░██▒    ▒▓▓▒                     ▓██▓▒█▒ ░▓▓▓▓▒█▓
                      ░▓██▒                          ▓░  ▒█▓█  ░░▒▒▒
                          ▒▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▓▓  ▓░▒█░
    
        ______ _ _       _       _____  ____  _         _____ _ _            _  BETA
       |  ____| (_)     | |     / ____|/ __ \| |       / ____| (_)          | |
       | |__  | |_ _ __ | | __ | (___ | |  | | |      | |    | |_  ___ _ __ | |_
       |  __| | | | '_ \| |/ /  \___ \| |  | | |      | |    | | |/ _ \ '_ \| __|
       | |    | | | | | |   <   ____) | |__| | |____  | |____| | |  __/ | | | |_
       |_|    |_|_|_| |_|_|\_\ |_____/ \___\_\______|  \_____|_|_|\___|_| |_|\__|
    
            Welcome! Enter 'HELP;' to list all available commands. 'QUIT;' to exit.
    
    Command history file path: /home/user/.flink-sql-history
    
  5. 使用外部來源查詢任何數據表之前,請先準備相關的 jar。 下列範例會查詢 Flink SQL 中的 kafka 數據表、mysql 數據表。 下載 jar,並將其放在連結的 Azure Data Lake 儲存體 gen2 記憶體的 Flink 叢集中。

    azure Data Lake 儲存體 gen2 中的 jars Azure 入口網站:

    顯示 Azure 入口網站 中 jar 檔案的螢幕快照。

  6. 使用已建立的數據表,並將其放入Hive中繼存放區以進行管理,然後執行查詢。

    注意

    在此範例中,AKS 上 HDInsight 中的所有 jar 預設為 Azure Data Lake 儲存體 Gen2。 容器和記憶體帳戶在叢集建立期間不需要與指定相同。 如有需要,您可以指定另一個記憶體帳戶,並將 Azure Data Lake 儲存體 Gen2 端的記憶體 Blob 數據擁有者角色授與叢集使用者受控識別。

    CREATE CATALOG myhive WITH (
        'type' = 'hive'
    );
    
    USE CATALOG myhive;
    
    // ADD jar into environment
    ADD JAR 'abfs://<container>@<storage name>.dfs.core.windows.net/jar/flink-connector-jdbc-3.1.0-1.17.jar';
    ADD JAR 'abfs://<container>@<storage name>.dfs.core.windows.net/jar/mysql-connector-j-8.0.33.jar';
    ADD JAR 'abfs://<container>@<storage name>.dfs.core.windows.net/jar/kafka-clients-3.2.0.jar';
    ADD JAR 'abfs://<container>@<storage name>.dfs.core.windows.net/jar/flink-connector-kafka-1.17.0.jar';
    
    Flink SQL> show jars;
    ----------------------------------------------------------------------------------------------+
    |                                                                                         jars |
    +----------------------------------------------------------------------------------------------+
    |    abfs://<container>@<storage name>.dfs.core.windows.net/jar/flink-connector-kafka-1.17.0.jar |
    | abfs://<container>@<storage name>.dfs.core.windows.net/jar/flink-connector-jdbc-3.1.0-1.17.jar |
    |             abfs://<container>@<storage name>.dfs.core.windows.net/jar/kafka-clients-3.2.0.jar |
    |        abfs://<container>@<storage name>.dfs.core.windows.net/jar/mysql-connector-j-8.0.33.jar |
    +----------------------------------------------------------------------------------------------+
    4 rows in set
    
    Flink SQL> SET 'sql-client.execution.result-mode' = 'tableau';
    [INFO] Execute statement succeed.
    
    Flink SQL> show tables;
    +----------------------+
    |           table name |
    +----------------------+
    | flightsintervaldata1 |
    |    kafka_user_orders |
    |           kafkatable |
    |    mysql_user_orders |
    |               orders |
    +----------------------+
    5 rows in set
    
    // mysql cdc table
    Flink SQL> select * from mysql_user_orders;
    +----+-------------+----------------------------+-------------+--------------------------------+--------------+-------------+--------------+
    | op |    order_id |                 order_date | customer_id |                  customer_name |        price |  product_id | order_status |
    +----+-------------+----------------------------+-------------+--------------------------------+--------------+-------------+--------------+
    | +I |       10001 | 2023-07-16 10:08:22.000000 |           1 |                           Jark |     50.00000 |
    102 |        FALSE |
    | +I |       10002 | 2023-07-16 10:11:09.000000 |           2 |                          Sally |     15.00000 |
    105 |        FALSE |
    | +I |       10003 | 2023-07-16 10:11:09.000000 |           3 |                          Sally |     25.00000 |
    
    

參考

AKS 叢集上 HDInsight 上的 Apache Flink® 命令行介面 (CLI)