sql >> データベース >  >> RDS >> MariaDB

MariaDBクラスターにMaxCtrlを使用したMaxScale基本管理

    前回のブログ投稿では、MaxCtrlコマンドラインクライアントを使用したMaxScaleのインストール、アップグレード、および展開の概要について説明しました。このブログ投稿では、MariaDBクラスターのMaxScale管理の側面について説明します。

    MaxCtrlで管理できるMaxScaleコンポーネントは多数あります。つまり、次のとおりです。

      サーバー管理 サービス管理 モニター管理 リスナー管理 フィルター管理
    1. MaxScale管理
    2. ログ管理

    このブログ投稿では、MariaDBクラスターで一般的に使用される最初の4つのコンポーネントについて説明します。このブログ投稿のすべてのコマンドは、MaxScale2.4.11に基づいています。

    サーバー管理 サーバーの一覧表示/表示

    MaxScale内のすべてのサーバーの概要を一覧表示します:

      maxctrl: list servers
    ┌────────────────┬────────────────┬──────┬─────────────┬─────────────────────────┬─────────────┐
    │ Server         │ Address        │ Port │ Connections │ State                   │ GTID        │
    ├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
    │ mariadbgalera1 │ 192.168.10.201 │ 3306 │ 0           │ Slave, Synced, Running  │ 100-100-203 │
    ├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
    │ mariadbgalera2 │ 192.168.10.202 │ 3306 │ 0           │ Slave, Synced, Running  │ 100-100-203 │
    ├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
    │ mariadbgalera3 │ 192.168.10.203 │ 3306 │ 0           │ Master, Synced, Running │ 100-100-203 │
    └────────────────┴────────────────┴──────┴─────────────┴─────────────────────────┴─────────────┘

    MariaDBクラスターの場合、サーバーリストは、クラスターが標準のMariaDBレプリケーションを介して別のクラスターからレプリケートするように設定されている場合にのみ、ノードとクラスターの状態をそのMariaDBGTIDとともに要約します。状態は、ルーティングアルゴリズムの動作を制御するためにMaxScaleによって使用されます。

    • マスター-クラスターの場合、これは書き込みマスターと見なされます。
    • スレーブ-すべてのスレーブがダウンしているが、マスターがまだ使用可能な場合、ルーターはマスターを使用します。
    • 同期済み-クラスターと同期状態にあるクラスターノード。 実行中-稼働中のサーバー。 MariaDB MaxScaleが接続できるすべてのサーバーには、実行中のラベルが付けられます。

    MariaDBクラスターはマルチマスターレプリケーションを処理できますが、MaxScaleは常に1つのノードを選択して、読み取り/書き込み分割ルーティングのすべての書き込みを受信するマスターの役割を保持します。デフォルトでは、GaleraMonitorはwsrep_local_index値が最も低いノードをマスターとして選択します。これは、異なるサーバーで実行されている2つのMaxScaleがマスターと同じサーバーを選択することを意味します。

    すべてのサーバーをより詳細に表示します:

    maxctrl: show servers
    サーバーの作成

    これは通常、MaxScaleをロードバランサーとして設定するときに最初に行う必要があることです。すべてのMariaDBクラスターノードをMaxScaleに追加し、オブジェクト名でラベル付けするのが一般的です。この例では、Galeraノードに「mariadbgalera#」形式のラベルを付けます。

    maxctrl: create server mariadbgalera1 192.168.0.221 3306
    maxctrl: create server mariadbgalera2 192.168.0.222 3306
    maxctrl: create server mariadbgalera3 192.168.0.222 3306

    サーバーの状態は、監視モジュールをアクティブ化した後でのみ正しく報告されます。これは、さらに下の[監視管理]セクションに示されています。

    サーバーを削除する

    サーバーを削除するには、事前にサーバーをサービスまたはモニターからリンク解除する必要があります。例として、次のサーバーリストでは、MaxScaleからmariadbgalera3を削除します。

      maxctrl: list servers
    ┌────────────────┬────────────────┬──────┬─────────────┬─────────────────────────┬─────────────┐
    │ Server         │ Address        │ Port │ Connections │ State                   │ GTID        │
    ├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
    │ mariadbgalera1 │ 192.168.10.201 │ 3306 │ 0           │ Slave, Synced, Running  │ 100-100-203 │
    ├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
    │ mariadbgalera2 │ 192.168.10.202 │ 3306 │ 0           │ Slave, Synced, Running  │ 100-100-203 │
    ├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
    │ mariadbgalera3 │ 192.168.10.203 │ 3306 │ 0           │ Master, Synced, Running │ 100-100-203 │
    └────────────────┴────────────────┴──────┴─────────────┴─────────────────────────┴─────────────┘

    すべてのモニターを一覧表示し、サーバーがモニターモジュールの一部であるかどうかを確認します。

     maxctrl: list monitors
     ┌─────────────────┬─────────┬────────────────────────────────────────────────┐
     │ Monitor         │ State   │ Servers                                        │
     ├─────────────────┼─────────┼────────────────────────────────────────────────┤
     │ MariaDB-Monitor │ Running │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
     └─────────────────┴─────────┴────────────────────────────────────────────────┘

    mariadbgalera3はMariaDB-Monitorの一部であるように見えるため、最初に「unlinkmonitor」コマンドを使用して削除する必要があります。

     maxctrl: unlink monitor MariaDB-Monitor mariadbgalera3
     OK

    次に、すべてのサービスを一覧表示して、対応するサーバーがMaxScaleサービスの一部であるかどうかを確認します。

      maxctrl: list services
    ┌─────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
    │ Service             │ Router         │ Connections │ Total Connections │ Servers                                        │
    ├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Read-Write-Service  │ readwritesplit │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
    ├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Round-Robin-Service │ readconnroute  │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
    ├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Replication-Service │ binlogrouter   │ 1           │ 1                 │                                                │
    └─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘

    ご覧のとおり、mariadbgalera3はRead-Write-ServiceおよびRound-Robin-Serviceの一部です。 「unlinkservice」コマンドを使用して、これらのサービスからサーバーを削除します。

     maxctrl: unlink service Read-Write-Service mariadbgalera3
    OK
     maxctrl: unlink service Round-Robin-Service mariadbgalera3
    OK

    最後に、「サーバーの破棄」コマンドを使用して、サーバーをMaxScaleから削除できます。

     maxctrl: destroy server mariadbgalera3
    OK

    MaxScaleからmariadbgalera3を削除した「リストサーバー」を使用して確認します。:

      maxctrl: list servers
    ┌────────────────┬────────────────┬──────┬─────────────┬─────────────────────────┬──────┐
    │ Server         │ Address        │ Port │ Connections │ State                   │ GTID │
    ├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼──────┤
    │ mariadbgalera1 │ 192.168.10.201 │ 3306 │ 0           │ Master, Synced, Running │      │
    ├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼──────┤
    │ mariadbgalera2 │ 192.168.10.202 │ 3306 │ 0           │ Slave, Synced, Running  │      │
    └────────────────┴────────────────┴──────┴─────────────┴─────────────────────────┴──────┘
    サーバーのパラメータを変更する

    サーバーのパラメーターを変更するには、一度に1つのキー/値パラメーターのみを受け取る「alterserver」コマンドを使用できます。例:

      maxctrl: alter server mariadbgalera3 priority 10
     OK

    「サーバーの表示」コマンドを使用し、「サーバー」オブジェクトで変更できるパラメーターのリストについて、「パラメーター」セクションを調べます。

    maxctrl: show server mariadbgalera3
    ...
    
    │ Parameters       │ {                                         │
    │                  │     "address": "192.168.10.203",          │
    │                  │     "protocol": "mariadbbackend",         │
    │                  │     "port": 3306,                         │
    │                  │     "extra_port": 0,                      │
    │                  │     "authenticator": null,                │
    │                  │     "monitoruser": null,                  │
    │                  │     "monitorpw": null,                    │
    │                  │     "persistpoolmax": 0,                  │
    │                  │     "persistmaxtime": 0,                  │
    │                  │     "proxy_protocol": false,              │
    │                  │     "ssl": "false",                       │
    │                  │     "ssl_cert": null,                     │
    │                  │     "ssl_key": null,                      │
    │                  │     "ssl_ca_cert": null,                  │
    │                  │     "ssl_version": "MAX",                 │
    │                  │     "ssl_cert_verify_depth": 9,           │
    │                  │     "ssl_verify_peer_certificate": false, │
    │                  │     "disk_space_threshold": null,         │
    │                  │     "priority": "10"                      │
    │                  │ }

    コマンドの変更の効果は即時であり、ランタイムでのパラメーターの値と、/ var / lib / maxscale / maxscale.cnf.d /内の個々のMaxScale構成ファイルの値が変更され、再起動後も永続化されることに注意してください。

    > サーバー状態の設定

    MaxScaleを使用すると、メンテナンスモードをアクティブ化することで、バックエンドのGaleraサーバーを負荷分散セットから一時的に除外できます。これは、「setserver」コマンドを使用して実現できます。

     maxctrl: set server mariadbgalera3 maintenance
    OK

    サーバーの状態を確認すると、次のように表示されます。

     maxctrl: show server mariadbgalera3
    ...
    │ State            │ Maintenance, Running
    ...

    サーバーがメンテナンスモードの場合、サーバーへの接続は作成されず、既存の接続は閉じられます。ホストからメンテナンス状態をクリアするには、「clearserver」コマンドを使用します。

     maxctrl: clear server mariadbgalera3 maintenance
    OK
    「showserver」で確認:

     maxctrl: show server mariadbgalera3
    ...
    │ State            │ Slave, Synced, Running                    │
    ...
    モニター管理 モニターを作成する

    MariaDBクラスターのMaxScaleモニターモジュールはガレラモンと呼ばれます。 MaxScaleがノードの状態に応じてクエリに最適なルーティングを決定できるように、正しい監視モジュールを定義する必要があります。たとえば、Galeraノードがジョイナーノードのドナーとして機能している場合、それは正常なノードの一部である必要がありますか?データベースサイズが非常に小さい場合など、ドナーノードを正常としてマークする(MaxScaleでパラメータavailable_when_donor =trueを設定する)ことは悪い計画ではなく、クエリルーティングのパフォーマンスを向上させる場合があります。

    サービス(ルーター)を作成するには、MariaDBサーバーのバックエンドに監視ユーザーを作成する必要があります。通常、モニターモジュールに定義したものと同じモニタリングユーザーを使用します。 Galera Clusterの場合、監視ユーザーが存在しない場合は、次の権限を持つノードの1つに作成するだけです。

    MariaDB> CREATE USER [email protected]'192.168.0.220' IDENTIFIED BY 'MaXSc4LeP4ss';
    MariaDB> GRANT SELECT ON mysql.* TO 'maxscale_monitor'@'192.168.0.220';
    MariaDB> GRANT SHOW DATABASES ON *.* TO 'maxscale_monitor'@'192.168.0.220';

    「createmonitor」コマンドを使用して、モニターモジュールとしてgaleramonを使用して名前を指定します。

      maxctrl: create monitor MariaDB-Monitor galeramon servers=mariadbgalera1,mariadbgalera2,mariadbgalera3 user=maxscale_monitor password=MaXSc4LeP4ss
    OK

    MaxScaleシークレットを構成していないことに注意してください。これは、ユーザーパスワードをプレーンテキスト形式で保存することを意味します。暗号化を有効にするには、このブログ投稿の例、「MaxScaleへの監視の追加」セクションの「MariaDBクラスターにmaxctrlを使用したMaxScale管理の概要」を参照してください。

    モニターの一覧表示/表示

    すべてのモニターを一覧表示するには:

     maxctrl: list monitors
    ┌─────────────────┬─────────┬────────────────────────────────────────────────┐
    │ Monitor         │ State   │ Servers                                        │
    ├─────────────────┼─────────┼────────────────────────────────────────────────┤
    │ MariaDB-Monitor │ Running │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
    └─────────────────┴─────────┴────────────────────────────────────────────────┘

    モニターの詳細を確認するには、「showmonitor」コマンドを使用します。

     maxctrl: show monitor MariaDB-Monitor
    
    ┌─────────────────────┬───────────────────────────────────────────┐
    │ Monitor             │ MariaDB-Monitor                           │
    ├─────────────────────┼───────────────────────────────────────────┤
    │ State               │ Running                                   │
    ├─────────────────────┼───────────────────────────────────────────┤
    │ Servers             │ mariadbgalera1                            │
    │                     │ mariadbgalera2                            │
    │                     │ mariadbgalera3                            │
    ├─────────────────────┼───────────────────────────────────────────┤
    │ Parameters          │ {                                         │
    │                     │     "user": "maxscale_monitor",           │
    │                     │     "password": "*****",                  │
    │                     │     "passwd": null,                       │
    │                     │     "monitor_interval": 2000,             │
    │                     │     "backend_connect_timeout": 3,         │
    │                     │     "backend_read_timeout": 1,            │
    │                     │     "backend_write_timeout": 2,           │
    │                     │     "backend_connect_attempts": 1,        │
    │                     │     "journal_max_age": 28800,             │
    │                     │     "disk_space_threshold": null,         │
    │                     │     "disk_space_check_interval": 0,       │
    │                     │     "script": null,                       │
    │                     │     "script_timeout": 90,                 │
    │                     │     "events": "all",                      │
    │                     │     "disable_master_failback": false,     │
    │                     │     "available_when_donor": true,         │
    │                     │     "disable_master_role_setting": false, │
    │                     │     "root_node_as_master": false,         │
    │                     │     "use_priority": false,                │
    │                     │     "set_donor_nodes": false              │
    │                     │ }                                         │
    ├─────────────────────┼───────────────────────────────────────────┤
    │ Monitor Diagnostics │ {                                         │
    │                     │     "disable_master_failback": false,     │
    │                     │     "disable_master_role_setting": false, │
    │                     │     "root_node_as_master": false,         │
    │                     │     "use_priority": false,                │
    │                     │     "set_donor_nodes": false              │
    │                     │ }                                         │
    └─────────────────────┴───────────────────────────────────────────┘
    モニターの停止/開始

    モニターを停止すると、サーバーの監視が一時停止します。これは通常、サーバーの状態を手動で制御するために「setserver」コマンドと組み合わせて使用​​されます。監視サービスを停止するには、「stopmonitor」コマンドを使用します。

     maxctrl: stop monitor MariaDB-Monitor
    OK
    「showmonitor」で状態を確認します:

     maxctrl: show monitors MariaDB-Monitor
    ┌─────────────────────┬───────────────────────────────────────────┐
    │ Monitor             │ MariaDB-Monitor                           │
    ├─────────────────────┼───────────────────────────────────────────┤
    │ State               │ Stopped                                   │
    ...

    再起動するには、「モニターの開始」を使用します。

     maxctrl: start monitor MariaDB-Monitor
    OK
    モニターのパラメーターを変更する

    このモニターのパラメーターを変更するには、「alter monitor」コマンドを使用して、以下のようにパラメーターのキー/値を指定します。

     maxctrl: alter monitor MariaDB-Monitor available_when_donor true
    OK

    「showmonitor」コマンドを使用し、「パラメーター」セクションを調べて、ガレラモンモジュール用に変更できるパラメーターのリストを確認します。

    maxctrl: show server mariadbgalera3
    ...
    │ Parameters          │ {                                         │
    │                     │     "user": "maxscale_monitor",           │
    │                     │     "password": "*****",                  │
    │                     │     "monitor_interval": 2000,             │
    │                     │     "backend_connect_timeout": 3,         │
    │                     │     "backend_read_timeout": 1,            │
    │                     │     "backend_write_timeout": 2,           │
    │                     │     "backend_connect_attempts": 1,        │
    │                     │     "journal_max_age": 28800,             │
    │                     │     "disk_space_threshold": null,         │
    │                     │     "disk_space_check_interval": 0,       │
    │                     │     "script": null,                       │
    │                     │     "script_timeout": 90,                 │
    │                     │     "events": "all",                      │
    │                     │     "disable_master_failback": false,     │
    │                     │     "available_when_donor": true,         │
    │                     │     "disable_master_role_setting": false, │
    │                     │     "root_node_as_master": false,         │
    │                     │     "use_priority": false,                │
    │                     │     "set_donor_nodes": false              │
    │                     │ }                                         │
    
    
    モニターを削除する

    モニターを削除するには、最初にモニターにリンクされているすべてのサーバーを削除する必要があります。たとえば、MaxScaleの次のモニターについて考えてみます。

     maxctrl: list monitors
    ┌─────────────────┬─────────┬────────────────────────────────────────────────┐
    │ Monitor         │ State   │ Servers                                        │
    ├─────────────────┼─────────┼────────────────────────────────────────────────┤
    │ MariaDB-Monitor │ Running │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
    └─────────────────┴─────────┴────────────────────────────────────────────────┘
    その特定のサービスからすべてのサーバーを削除します:

     maxctrl: unlink monitor MariaDB-Monitor mariadbgalera1 mariadbgalera2 mariadbgalera3
    
    OK

    モニターは次のようになります:

     maxctrl: list monitors
    ┌─────────────────┬─────────┬─────────┐
    │ Monitor         │ State   │ Servers │
    ├─────────────────┼─────────┼─────────┤
    │ MariaDB-Monitor │ Running │         │
    └─────────────────┴─────────┴─────────┘

    その場合にのみ、モニターを削除できます:

     maxctrl: destroy monitor MariaDB-Monitor
    OK
    サーバーをモニターに追加/削除

    モニターを作成したら、「linkmonitor」コマンドを使用してGaleraサーバーをモニターに追加できます。 [サーバーの作成]セクションで作成したサーバーの名前を使用します:

     maxctrl: link monitor MariaDB-Monitor mariadbgalera1 mariadbgalera2 mariadbgalera3
    OK

    同様に、サーバーをサービスから削除するには、「unlinkmonitor」コマンドを使用します。

     maxctrl: unlink monitor MariaDB-Monitor mariadbgalera3
    OK

    「listmonitors」または「showmonitors」コマンドで確認します。

    サービス管理 サービスを作成する

    サービス(ルーター)を作成するには、MariaDBサーバーのバックエンドに監視ユーザーを作成する必要があります。通常、モニターモジュールに定義したものと同じモニタリングユーザーを使用します。 Galera Clusterの場合、監視ユーザーが存在しない場合は、次の権限を持つノードの1つに作成するだけです。

    MariaDB> CREATE USER [email protected]'192.168.0.220' IDENTIFIED BY 'MaXSc4LeP4ss';
    MariaDB> GRANT SELECT ON mysql.* TO 'maxscale_monitor'@'192.168.0.220';
    MariaDB> GRANT SHOW DATABASES ON *.* TO 'maxscale_monitor'@'192.168.0.220';

    ここで、192.168.0.220はMaxScaleホストのIPアドレスです。

    次に、サービスの名前、ルーティングタイプ、およびバックエンドサーバーに接続するMaxScaleの監視ユーザーを指定します。

     maxctrl: create service Round-Robin-Service readconnroute user=maxscale_monitor password=******
    OK

    また、サービスの作成時に追加のパラメーターを指定できます。この例では、「マスター」ノードをMariaDBガレラクラスターのラウンドロビンバランシングセットに含める必要があります。

     maxctrl: create service Round-Robin-Service readconnroute user=maxscale_monitor password=****** router_options=master,slave
    OK

    「showservice」コマンドを使用して、サポートされているパラメーターを確認します。ラウンドロビンルーターの場合、リストは次のとおりです。

      maxctrl: show service Round-Robin-Service
    ...
    │ Parameters          │ {                                          │
    │                     │     "router_options": null,                │
    │                     │     "user": "maxscale_monitor",            │
    │                     │     "password": "*****",                   │
    │                     │     "passwd": null,                        │
    │                     │     "enable_root_user": false,             │
    │                     │     "max_retry_interval": 3600,            │
    │                     │     "max_connections": 0,                  │
    │                     │     "connection_timeout": 0,               │
    │                     │     "auth_all_servers": false,             │
    │                     │     "strip_db_esc": true,                  │
    │                     │     "localhost_match_wildcard_host": true, │
    │                     │     "version_string": null,                │
    │                     │     "weightby": null,                      │
    │                     │     "log_auth_warnings": true,             │
    │                     │     "retry_on_failure": true,              │
    │                     │     "session_track_trx_state": false,      │
    │                     │     "retain_last_statements": -1,          │
    │                     │     "session_trace": 0

    読み取り/書き込み分割ルーターの場合、サポートされるパラメーターは次のとおりです。

      maxctrl: show service Read-Write-Service
    ...
    │ Parameters          │ {                                                           │
    │                     │     "router_options": null,                                 │
    │                     │     "user": "maxscale_monitor",                             │
    │                     │     "password": "*****",                                    │
    │                     │     "passwd": null,                                         │
    │                     │     "enable_root_user": false,                              │
    │                     │     "max_retry_interval": 3600,                             │
    │                     │     "max_connections": 0,                                   │
    │                     │     "connection_timeout": 0,                                │
    │                     │     "auth_all_servers": false,                              │
    │                     │     "strip_db_esc": true,                                   │
    │                     │     "localhost_match_wildcard_host": true,                  │
    │                     │     "version_string": null,                                 │
    │                     │     "weightby": null,                                       │
    │                     │     "log_auth_warnings": true,                              │
    │                     │     "retry_on_failure": true,                               │
    │                     │     "session_track_trx_state": false,                       │
    │                     │     "retain_last_statements": -1,                           │
    │                     │     "session_trace": 0,                                     │
    │                     │     "use_sql_variables_in": "all",                          │
    │                     │     "slave_selection_criteria": "LEAST_CURRENT_OPERATIONS", │
    │                     │     "master_failure_mode": "fail_instantly",                │
    │                     │     "max_slave_replication_lag": -1,                        │
    │                     │     "max_slave_connections": "255",                         │
    │                     │     "retry_failed_reads": true,                             │
    │                     │     "prune_sescmd_history": false,                          │
    │                     │     "disable_sescmd_history": false,                        │
    │                     │     "max_sescmd_history": 50,                               │
    │                     │     "strict_multi_stmt": false,                             │
    │                     │     "strict_sp_calls": false,                               │
    │                     │     "master_accept_reads": false,                           │
    │                     │     "connection_keepalive": 300,                            │
    │                     │     "causal_reads": false,                                  │
    │                     │     "causal_reads_timeout": "10",                           │
    │                     │     "master_reconnection": false,                           │
    │                     │     "delayed_retry": false,                                 │
    │                     │     "delayed_retry_timeout": 10,                            │
    │                     │     "transaction_replay": false,                            │
    │                     │     "transaction_replay_max_size": "1Mi",                   │
    │                     │     "optimistic_trx": false                                 │
    │                     │ }

    List/Show Services
     

    To list out all created services (routers), use the "list services" command:

     maxctrl: list services
    ┌─────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
    │ Service             │ Router         │ Connections │ Total Connections │ Servers                                        │
    ├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Read-Write-Service  │ readwritesplit │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
    ├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Round-Robin-Service │ readconnroute  │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
    ├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Binlog-Repl-Service │ binlogrouter   │ 1           │ 1                 │                                                │
    └─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘

    In the above examples, we have created 3 services, with 3 different routers. However, the Binlog-Repl-Service for our binlog server is not linked with any servers yet.

    To show all services in details:

     maxctrl: show services

    Or if you want to show a particular service:

     maxctrl: show service Round-Robin-Service

    Stop/Start Services

    Stopping a service will prevent all the listeners for that service from accepting new connections. Existing connections will still be handled normally until they are closed. To stop and start all services, use the "stop services":

     maxctrl: stop services
     maxctrl: show services
     maxctrl: start services
     maxctrl: show services

    Or we can use the "stop service" to stop only one particular service:

     maxctrl: stop services Round-Robin-Service

    Delete a Service

    In order to delete a service, one has to remove all servers and destroy the listeners associated with the service first. For example, consider the following services in MaxScale:

     maxctrl: list services
    ┌─────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
    │ Service             │ Router         │ Connections │ Total Connections │ Servers                                        │
    ├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Read-Write-Service  │ readwritesplit │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
    ├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Round-Robin-Service │ readconnroute  │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
    ├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Replication-Service │ binlogrouter   │ 1           │ 1                 │                                                │
    └─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘

    Let's remove Round-Robin-Service from the setup. Remove all servers from this particular service:

     maxctrl: unlink service Round-Robin-Service mariadbgalera1 mariadbgalera2 mariadbgalera3
    OK

    Our services are now looking like this:

     maxctrl: list services
    ┌─────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
    │ Service             │ Router         │ Connections │ Total Connections │ Servers                                        │
    ├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Read-Write-Service  │ readwritesplit │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
    ├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Round-Robin-Service │ readconnroute  │ 1           │ 1                 │                                                │
    ├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Replication-Service │ binlogrouter   │ 1           │ 1                 │                                                │
    └─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘

    If the service is tied with a listener, we have to remove it as well. Use "list listeners" and specify the service name to look for it:

     maxctrl: list listeners Round-Robin-Service
    ┌──────────────────────┬──────┬─────────┬─────────┐
    │ Name                 │ Port │ Host    │ State   │
    ├──────────────────────┼──────┼─────────┼─────────┤
    │ Round-Robin-Listener │ 3307 │ 0.0.0.0 │ Running │
    └──────────────────────┴──────┴─────────┴─────────┘

    And then remove the listener:

     maxctrl: destroy listener Round-Robin-Service Round-Robin-Listener
    OK

    Finally, we can remove the service:

     maxctrl: destroy service Round-Robin-Service
    OK

    Modify Service's Parameter

    Similar to the other object, one can modify a service parameter by using the "alter service" command:

     maxctrl: alter service Read-Write-Service master_accept_reads true
    OK

    Some routers support runtime configuration changes to all parameters. Currently all readconnroute, readwritesplit and schemarouter parameters can be changed at runtime. In addition to module specific parameters, the following list of common service parameters can be altered at runtime:

    • user
    • passwd
    • enable_root_user
    • max_connections
    • connection_timeout
    • auth_all_servers
    • optimize_wildcard
    • strip_db_esc
    • localhost_match_wildcard_host
    • max_slave_connections
    • max_slave_replication_lag
    • retain_last_statements

    Note that alter command effect is immediate and the parameter's value in the runtime will be modified as well as the value in its individual MaxScale configuration file inside /var/lib/maxscale/maxscale.cnf.d/ for persistence across restart.

    Add/Remove Servers into Service

    After creating a service, we can use the link command to add our servers into the service. Use the server's name as created under Create Servers section:

     maxctrl: link service Round-Robin-Service mariadbgalera1 mariadbgalera2 mariadbgalera3
    OK

    Similarly, to remove a server from the service, just use "unlink service" command:

     maxctrl: unlink service Round-Robin-Service mariadbgalera3
    OK

    We can only remove one server from a service at a time, so repeat it for other nodes to delete them. Verify with "list services" or "show services" command.

    Listener Management

    List Listeners

    To list all listeners, we need to know the service name in advanced:

    maxctrl: list services
    ┌──────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
    │ Service              │ Router         │ Connections │ Total Connections │ Servers                                        │
    ├──────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Read-Write-Service   │ readwritesplit │ 0           │ 0                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
    ├──────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
    │ Round-Robin-Service  │ readconnroute  │ 0           │ 0                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
    ├──────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤

    In the above example, we have two services, Read-Write-Service and Round-Robin-Service. Then, we can list out the listener for that particular service. For Read-Write-Service:

     maxctrl: list listeners Read-Write-Service
    ┌─────────────────────┬──────┬─────────┬─────────┐
    │ Name                │ Port │ Host    │ State   │
    ├─────────────────────┼──────┼─────────┼─────────┤
    │ Read-Write-Listener │ 3306 │ 0.0.0.0 │ Running │
    └─────────────────────┴──────┴─────────┴─────────┘

    And for Round-Robin-Service:

     maxctrl: list listeners Round-Robin-Service
    ┌──────────────────────┬──────┬─────────┬─────────┐
    │ Name                 │ Port │ Host    │ State   │
    ├──────────────────────┼──────┼─────────┼─────────┤
    │ Round-Robin-Listener │ 3307 │ 0.0.0.0 │ Running │
    └──────────────────────┴──────┴─────────┴─────────┘

    Unlike other objects in MaxScale, the listener does not have a "show" and "alter" commands since it is a fairly simple object.

    Create a Listener

    Make sure a service has been created. In this example, taken from the Create Service section above, we will create a listener so MaxScale will listen on port 3307 to process the MariaDB connections in a round-robin fashion:

     maxctrl: create listener Round-Robin-Service Round-Robin-Listener 3307
    OK

    Delete a Listener

    To delete a listener, use the "destroy listener" command with the respective service name and listener name:

     maxctrl: destroy listener Round-Robin-Service Round-Robin-Listener
    OK

    This concludes this episode of basic MaxScale management tasks for MariaDB Cluster. In the next series, we are going to cover the MaxScale advanced management tasks like service filters, MaxScale user management and so on.


    1. 文字列フィールドからMySQLの日付を変換する

    2. SQLServerで文字列を日付/時刻値に変換する6つの方法

    3. 採用システム用のデータベースの設計

    4. SQLiteの日付と時刻の関数