MySQL - MySQL Router

提供: MochiuWiki : SUSE, EC, PCB

概要

MySQL Routerは、MySQL InnoDB ClusterやInnoDB ReplicaSetで使用可能であり、ロードバランスや障害発生時のフェイルオーバーに対応したルーティングを透過的に実現するミドルウェア製品である。



MySQL InnoDB Cluster

MySQL InnoDB Clusterは、アプリケーションからのルーティングも含めたフルスタックなHAソリューションである。

MySQL InnoDB Clusterは、以下に示す複数のコンポーネントをまとめた名称であり、それ自体が1つの製品ではない。
コンポーネント同士が強く結びついて動作させることが前提のため、サードパーティ製品を導入する際に組み合わせにより発生するトラブルに悩まされることもなく、汎用的なツールにありがちな複雑な設定から解放される。

  • MySQL Group Replication (MySQLデータベースサーバ)
  • MySQL Router (接続ルーティング)
  • MySQL Shell (mysqlコマンド拡張)



必須環境

  • Python
    Python 2.7が必要となる。
    MySQL Shellでは、以下に示すコマンドでPythonが実行されるため、複数のPythonがインストールされている環境では、Python 2.7が実行されるように変更する必要がある。
    /usr/bin/env python

  • 名前解決
    MySQL Group Replicationで各MySQLサーバ間はホスト名を使用して接続するため、名前解決できるようにhostsやDNSの設定が必要である。



構成

bootstrapによる初期設定の完了後、MySQL Routerの設定ファイル(/etc/mysqlrouter/mysqlrouter.confファイル)には、以下に示すような内容が自動で書き込まれる。

 # File automatically generated during MySQL Router bootstrap
 [DEFAULT]
 name=system
 user=mysqlrouter
 keyring_path=/var/lib/mysqlrouter/keyring
 master_key_path=/etc/mysqlrouter/mysqlrouter.key
 connect_timeout=15
 read_timeout=30
 dynamic_state=/var/lib/mysqlrouter/state.json
 
 [logger]
 level = INFO
 
 [metadata_cache:myCluster]
 cluster_type=gr
 router_id=1
 user=mysql_router1_w0dw2zzuwu4c
 metadata_cluster=myCluster
 ttl=0.5
 auth_cache_ttl=-1
 auth_cache_refresh_interval=2
 use_gr_notifications=0
 
 [routing:myCluster_rw]
 bind_address=0.0.0.0
 bind_port=6446
 destinations=metadata-cache://myCluster/?role=PRIMARY
 routing_strategy=first-available
 protocol=classic
 
 [routing:myCluster_ro]
 bind_address=0.0.0.0
 bind_port=6447
 destinations=metadata-cache://myCluster/?role=SECONDARY
 routing_strategy=round-robin-with-fallback
 protocol=classic
 
 [routing:myCluster_x_rw]
 bind_address=0.0.0.0
 bind_port=64460
 destinations=metadata-cache://myCluster/?role=PRIMARY
 routing_strategy=first-available
 protocol=x
 
 [routing:myCluster_x_ro]
 bind_address=0.0.0.0
 bind_port=64470
 destinations=metadata-cache://myCluster/?role=SECONDARY
 routing_strategy=round-robin-with-fallback
 protocol=x