ksqlDB のインストール

ksqlDB は Confluent Platform のコンポーネントであり、ksqlDB のバイナリは、Confluent Platform バンドルの一部として https://www.confluent.io/download/ にあります。

ksqlDB は、実行中の Apache Kafka® クラスターにアクセスできる必要があります。このクラスターは、データセンター、パブリッククラウド、Confluent Cloud などに配置することができます。

Docker のサポート
ksqlDB は、Docker コンテナー を使用してデプロイできます。Confluent Platform 4.1.2 以降、Confluent は Docker Hub にイメージを保持しています。"ksqlDB ヘッドレスサーバー" や "インターセプターを使用する対話型サーバー" のような構成において ksqlDB コンテナーを起動するには、「Docker 構成パラメーター」を参照してください。

YouTube の screencast of Installing and Running KSQL をご覧ください。

サポートされているバージョンおよび相互運用性

Confluent Platform ksqlDB は、互換性があるバージョンの Confluent Platform および Kafka で使用できます。

Confluent Platform ksqlDB Confluent Platform Kafka
7.1.x 3.3.0 以降 0.11.0 およびそれ以降
7.0.x 3.3.0 以降 0.11.0 およびそれ以降
6.2.x 3.3.0 以降 0.11.0 およびそれ以降
6.1.x 3.3.0 以降 0.11.0 およびそれ以降
6.0.x 3.3.0 以降 0.11.0 およびそれ以降
5.5.x 3.3.0 以降 0.11.0 およびそれ以降
5.4.x 3.3.0 以降 0.11.0 およびそれ以降

インストール手順

Confluent Platform のクイックスタート の手順に従います。

また confluent-ksql package を使用して ksqlDB を個別にインストールすることもできます。詳細については Confluent Platform パッケージ を参照してください。

ksqlDB サーバーのデプロイの拡張

ksqlDB は、サーバーあたりの容量を追加する(垂直方向)またはサーバーを追加する(水平方向)ことにより、拡張することができます。また、ライブ運用中にデータを失うことなく ksqlDB クラスターを拡張することもできます。詳細については、「ksqlDB の拡張」を参照してください。

ksqlDB サーバーの起動

ksqlDB サーバーは、ksqlDB CLI クライアントおよび Kafka ブローカーとは別に実行されます。サーバーはリモートのマシン、VM、またはコンテナー上にデプロイすることができ、CLI がこれらのリモートサーバーに接続します。

ライブ運用中に同じリソースプールからサーバーを追加または削除して、クエリ処理を弾力的に拡張することができます。ワークロードの分離に対応するために異なるリソースプールを使用することもできます。たとえば、本稼働環境用とテスト用に別個のプールをデプロイすることができます。

一度に複数の ksqlDB サーバーに接続することはできません。ksqlDB CLI は、別の ksqlDB サーバーへの自動フェールオーバーをサポートしていません。

../_images/client-server.ja.png

これらの手順に従い ksql-server-start スクリプトを使用して ksqlDB サーバーを起動します。

ちなみに

これらの手順では、ZIP または TAR アーカイブを使用して Confluent Platform をインストールしているという想定に基づいています。詳細については「オンプレミスのデプロイ」を参照してください。

  1. ksqlDB サーバーの構成パラメーターを指定します。また、Kafka Streams API、Kafka プロデューサー、または Kafka コンシューマーの任意のプロパティを設定することもできます。必須のパラメーターは bootstrap.servers および listeners です。パラメーターは ksqlDB プロパティファイルまたは KSQL_OPTS 環境変数に指定できます。KSQL_OPTS で設定したプロパティは、プロパティファイルに指定されているプロパティより優先されます。

    一例として ksqlDB 構成ファイルを使用して共通する一連のプロパティを構成し、必要な場合に KSQL_OPTS 環境変数を使用して特定のプロパティをオーバーライドする方法が推奨されます。

    デフォルトの設定は以下のとおりです。

    bootstrap.servers=localhost:9092
    listeners=http://0.0.0.0:8088
    

    詳細については、「ksqlDB サーバーを構成する」を参照してください。

  2. このコマンドによりサーバーノードを起動します。

    <path-to-confluent>/bin/ksql-server-start <path-to-confluent>/etc/ksqldb/ksql-server.properties
    

    ちなみに

    <path-to-confluent>/bin/ksql-server-start --help を実行することにより、ksqlDB サーバーのヘルプテキストを表示することができます。

    NAME
            server - KSQL Cluster
    
    SYNOPSIS
            server [ {-h | --help} ] [ --queries-file <queriesFile> ] [--]
                    <config-file>
    
    OPTIONS
            -h, --help
                Display help information
    
            --queries-file <queriesFile>
                Path to the query file on the local machine.
    
            --
                This option can be used to separate command-line options from the
                list of arguments (useful when arguments might be mistaken for
                command-line options)
    
            <config-file>
                A file specifying configs for the KSQL Server, KSQL, and its
                underlying Kafka Streams instance(s). Refer to KSQL documentation
                for a list of available configs.
    
                This option may occur a maximum of 1 times
    
  3. 非対話型(別名ヘッドレス)モードで ksqlDB を実行する手順については、こちらのページ を参照してください。

ksqlDB CLI の起動

ksqlDB CLI は ksqlDB サーバーに接続するクライアントです。

ksqlDB サーバーへの接続情報を指定することにより ksqlDB CLI を起動することができます。

LOG_DIR=./ksql_logs <path-to-confluent>/bin/ksql http://localhost:8088

重要

デフォルトで、ksqlDB は ksql 実行可能ファイルの場所に対応する logs と呼ばれるディレクトリにそのログを保管しようとします。たとえば、 ksql/usr/local/bin/ksql にインストールされると、/usr/local/logs にそのログを保管しようとします。ksql を Confluent Platform のデフォルトのロケーションである $CONFLUENT_HOME/bin から実行している場合は、LOG_DIR 変数を使用して、このデフォルトの動作をオーバーライドする必要があります。

ksqlDB 起動後のターミナルはこのようになります。

                  ===========================================
                  =       _              _ ____  ____       =
                  =      | | _____  __ _| |  _ \| __ )      =
                  =      | |/ / __|/ _` | | | | |  _ \      =
                  =      |   <\__ \ (_| | | |_| | |_) |     =
                  =      |_|\_\___/\__, |_|____/|____/      =
                  =                   |_|                   =
                  =  Event Streaming Database purpose-built =
                  =        for stream processing apps       =
                  ===========================================

Copyright 2017-2021 Confluent Inc.

CLI v7.1.1, Server v7.1.1 located at http://localhost:8088
Server Status: RUNNING

Having trouble? Type 'help' (case-insensitive) for a rundown of how things work!

ksql>

ちなみに

<path-to-confluent>/bin/ksql --help を実行することにより ksqlDB CLI のヘルプテキストを表示できます。

NAME
        ksql - KSQL CLI

SYNOPSIS
        ksql [ --config-file <configFile> ]
                [ {--define | -d} <definedVars>... ]
                [ {--execute | -e} <execute> ] [ {--file | -f} <scriptFile> ]
                [ {-h | --help} ] [ --output <outputFormat> ]
                [ {--password | -p} <password> ]
                [ --query-row-limit <streamedQueryRowLimit> ]
                [ --query-timeout <streamedQueryTimeoutMs> ]
                [ {--user | -u} <userName> ] [--] [ <server> ]

OPTIONS
        --config-file <configFile>
            A file specifying configs for Ksql and its underlying Kafka Streams
            instance(s). Refer to KSQL documentation for a list of available
            configs.

        --define <definedVars>, -d <definedVars>
            Define variables for the CLI session (equivalent to the DEFINE
            statement).

        --execute <execute>, -e <execute>
            Execute one or more SQL statements and quit.

        --file <scriptFile>, -f <scriptFile>
            Execute commands from a file and exit.

        -h, --help
            Display help information

        --output <outputFormat>
            The output format to use (either 'JSON' or 'TABULAR'; can be
            changed during REPL as well; defaults to TABULAR)

        --password <password>, -p <password>
            If your KSQL server is configured for authentication, then provide
            your password here. The username must be specified separately with
            the -u/--user flag

        --query-row-limit <streamedQueryRowLimit>
            An optional maximum number of rows to read from streamed queries

            This options value must fall in the following range: value >= 1

        --query-timeout <streamedQueryTimeoutMs>
            An optional time limit (in milliseconds) for streamed queries

            This options value must fall in the following range: value >= 1

        --user <userName>, -u <userName>
            If your KSQL server is configured for authentication, then provide
            your user name here. The password must be specified separately with
            the -p/--password flag

        --
            This option can be used to separate command-line options from the
            list of arguments (useful when arguments might be mistaken for
            command-line options)

        <server>
            The address of the Ksql server to connect to (ex:
            http://confluent.io:9098)

            This option may occur a maximum of 1 times

ksqlDB の Confluent Cloud 用構成

Confluent Cloud では、ksqlDB を Kafka クラスターと併用することができます。詳細については、「ksqlDB の Confluent Cloud への接続」を参照してください。