mysql high availability option and cluster · 2011. 2. 3. · 'flush logs'...
TRANSCRIPT
<Insert Picture Here>
MySQL High Availability Option and Cluster
2
以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するものです。また、情報提供を唯一の目的とするものであり、いかなる契約にも組み込むことはできません。以下の事項は、マテリアルやコード、機能を提供することをコミットメント(確約)するものではないため、購買決定を行う際の判断材料になさらないで下さい。オラクル製品に関して記載されている機能の開発、リリースおよび時期については、弊社の裁量により決定されます。
OracleとJavaは、Oracle Corporation 及びその子会社、関連会社の米国及びその他の国における登録商標です。文中の社名、商品名等は各社の商標または登録商標である場合があります。
Copyright© 2010, Oracle. All rights reserved.
The world's most popular open source database
世界で最も有名なオープンソース データベース
MySQLの高可用性構成
MySQL
Cluster
MySQL
Cluster
アプリケーション/APサーバ
負荷分散
双方向同期複製
• MySQL Clusterシェアードナッシング型高性能クラスタ
MySQL
Server
• MySQL+DRBDLinux用のノード間データコピー
アプリケーション/APサーバ
フェールオーバー
同期複製
MySQL
Server
アプリケーション/APサーバ
共有ディスク
• 3rdベンダ製HAソフト利用共有ディスクにデータを格納
フェールオーバー
MySQL
Server
MySQL
Server
アプリケーション/APサーバ
負荷分散
非同期複製準同期複製
• レプリケーション(標準機能)非同期&準同期データレプリケーション
MySQL
Server
MySQL
Server
• MySQL Cluster+レプリケーション
MySQL
Cluster
MySQL
Cluster
アプリケーション/APサーバ
負荷分散
双方向同期複製
MySQL
Cluster
MySQL
Cluster 双方向同期複製
非同期複製
アプリケーション/APサーバ
共有ディスク
フェールオーバー
MySQL
Server
MySQL
Server
• 共有ディスク型構成+レプリケーション
MySQL
Server
・・・
非同期複製
アプリケーション/APサーバ
参照処理の負荷分散
MySQL
Server
MySQL
Server
複合型の高可用性構成例
MySQL レプリケーション
データの変更点を1つ以上の場所に複製すること
update
customer
update
customer
非同期レプリケーション - Asynchronous Replication
同期レプリケーション - Synchronous Replication
レプリケーションとは?
Webアプリケーションでは参照が95%、更新が5%というケースも (Digg.com)
> シンプルなスケールアウト構成によって簡単に20倍以上の性能向上が図れる
レプリケーション
• MySQLの標準機能– シンプルな設定– マスタ→スレーブ– 多数Webでの実績
• 非同期型&準同期型• 特徴
– 参照性能を向上させる構成– バックアップ用途での利用も– 基本は一方向でのデータコピーだが、双方向や循環型での利用も可能 (データの更新には注意が必要)
– 更新ログ(bin-log)を利用
非同期レプリケーション
Application
Master
Connection Thread
Data Binlog
Slave
DataRelaylog
Commit
ChangingData
ChangingBinlog
Replication
Response
ChangingData
マスタ > スレーブ
マルチマスタ > スレーブ (マルチソース)
マスタ < > マスタ (マルチマスタ)
マスタ > マルチスレーブ
循環型 (マルチマスタ)
マスタ > スレーブ > マルチスレーブ
MySQL レプリケーションの構成パターン
準同期レプリケーション
Application
Master
Connection Thread
Data Binlog
Slave
DataRelaylog
Commit
ChangingData
ChangingBinlog
Replication
ResponseChanging
Data
Response
MySQL 5.5のレプリケーション改善点
1.準同期(Semisynchronous)レプリケーションスレーブに変更点を転送してからアプリケーションに応答を返すため、信頼性が向上
2.スレーブでのfsync改良&リレーログの自動復旧fsyncsを改良しスレーブの障害時のログ破損を回避。破損した場合にも自動普及
3.レプリケーション ハードビート障害発生検知のメカニズムの精度を向上
4.サーバ毎のレプリケーション フィルタリング特定のサーバIDを持つマスターのイベントを無視
Copyright Oracle Corporation 2010 12
MySQL 5.5のレプリケーション改善点
5.スレーブでのデータ型変換の自動化(RBR)
マスターとスレーブ間でデータ型が異なる場合に自動的に型を変換
6.ログを個別にフラッシュ'FLUSH LOGS'実行時にログを選択してフラッシュ可能に
7. トランザクション非対応に関係なく安全にログに記録InnoDBとMyISAMのテーブルを同一のトランザクション内で更新した場合、コミット後に全変更点をバイナリログに記録
Copyright Oracle Corporation 2010 13
MySQL Cluster
NDB API
JDBC/ODBC/etc
SQL Based Applications
MySQL
Server
C++/Java
Applications
Management
Client
Management
Node
LDAP
MySQL ClusterData
Node
ND
B A
PI
MGM API
Data
Node
Data
Node
Data
Node
MySQL Cluster
• 非共有ディスク型高可用性クラスタソリューション– サーバの追加により性能&データ容量を拡大するスケールアウト構成
• 無停止でのサーバ追加&データ再構成が可能
– データを複数のサーバにデータの複製を分散配置
• マルチマスタ構成、単一障害点無し
• ミリ秒単位での障害検知、自動フェールオーバー、自動リカバリ
• ACID準拠のトランザクション
– 通信系の加入者データベースやWebのセッション永続化など、シンプルなトランザクションが同時多発的に発生するシステム向き
– SQL以外にもC++やJavaのAPI経由で直接データアクセス可能
SQL Node
(MySQL)
• 標準的なSQLインターフェース• スケールアウトによる性能向上• レプリケーション構成可能
• 高パフォーマンス• C++ API• 開発ガイドを公開
• データストレージ (ディスク/メモリ)• 自動的なパーティショニング• ローカル&グローバルチェックポイント• スケールアウトによる容量と可用性向上
• 管理および設定• "Arbitration" 調停役• 2ノードでの可用性
NDB API
(Application)
Data Node
(NDB Storage Engine)
Management
Node
MySQL Clusterを構成するコンポーネント
MySQL Clusterに関するキーワード
• パーティション– 水平(行単位)パーティショニング
– 主キー(または指定のインデックス)のKeyパーティショニング
– パーティション数 = データノード数
• レプリカ– データの完全なコピー
• ノードグループ– 自動的に作成される
– グループ数 = データノード数÷レプリカ数
SQL Node(MySQL)
NDB API
Data Node(NDB Storage Engine)
X
NDB APIによるアクセス
• NDB API = 高パフォーマンス C++ API
• キー、インデックススキャン、テーブルスキャン
• ACIDトランザクション対応
• オブジェクト指向エラーハンドリング
• SQLでは達成できない非常に高いパフォーマンス
>レイテンシーの低減による10倍以上のスループット
>Javaプログラマの「普通の」コーディングで利用可能
MySQL Cluster Connector for Java
• MySQL Cluster Connector for Java– ネイティブJavaインターフェース
– SQLは利用しない
• MySQL Cluster Java API :ドメインオブジェクトモデルのパーシステンスAPI– 別名Cluster/J
– Javaアプリケーションに組み込んで利用
• JPA準拠のO/Rマッパーでのアクセス– MySQL Cluster Plug-in for OpenJPA
– 主キーによる参照、更新、挿入や削除はCluster/Jで
– その他の処理はJDBCを利用
Measured as CPU time on a single host
JDBCドライバとCluster/Jとの比較
Cluster 1
同期型レプリケーション
Cluster 2
MyISAM MEMORY InnoDB
非同期型レプリケーション
• クラスタのノードグループ間で
は同期型レプリケーションで、
冗長性を確保
• 地理的に離れたクラスタ間で、
双方向の非同期型レプリケー
ションを行い、地理的冗長性を
確保
• (MySQL Clusterではない)通
常のMySQLサーバへ非同期
型のレプリケーションを行い、
レポート生成や課金処理など
のアプリケーションを実行
Geographical Replication -地理的冗長性の確保
Delivering up to 10x higher Java Throughput
MySQL Cluster Connector for Java:
Native Java API
JPA Plug-In
Reducing Cost of Operations
Simplified Management & Monitoring:
NDBINFO
MySQL Cluster Manager (part of CGE only)
Faster Restarts
MySQL Cluster CGE 7.1 – Key Enhancements
ndbinfo
• New database (ndbinfo) which
presents real-time metric data
in the form of tables
• Exposes new information
together with providing a
simpler, more consistent way
to access existing data
• Examples include:
– Resource usage (memory,
buffers)
– Event counters (such as number
of READ operations since last
restart)
– Data node status and connection
status
mysql> use ndbinfo
mysql> show tables;
+-------------------+
| Tables_in_ndbinfo |
+-------------------+
| blocks |
| config_params |
| counters |
| logbuffers |
| logspaces |
| memoryusage |
| nodes |
| resources |
| transporters |
+-------------------+
ndbinfo
• Example 1: Check memory usage/availability
mysql> select * from memoryusage;
+---------+--------------+------+------+
| node_id | DATA_MEMORY | used | max |
+---------+--------------+------+------+
| 3 | DATA_MEMORY | 594 | 2560 |
| 4 | DATA_MEMORY | 594 | 2560 |
| 3 | INDEX_MEMORY | 124 | 2336 |
| 4 | INDEX_MEMORY | 124 | 2336 |
+---------+--------------+------+------+
• Note that there is a DATA_MEMORY and INDEX_MEMORY row for
each data node in the cluster
• If the Cluster is nearing the configured limit then increase the
DataMemory and/or IndexMemory parameters in config.ini and then
perform a rolling restart
ndbinfo
• Example 2: Check how many table scans performed on each data node since the last restart
mysql> select node_id as 'data node', val as 'Table Scans'
from counters where counter_name='TABLE_SCANS';
+-----------+-------------+
| data node | Table Scans |
+-----------+-------------+
| 3 | 3 |
| 4 | 4 |
+-----------+-------------+
• You might check this if your database performance is lower than
anticipated
• If this figure is rising faster than you expected then examine your
application to understand why there are so many table scans
MySQL Cluster 7.1: ndbinfo
• Example 3: Check if approaching the point at which the undo log completely fills up
between local checkpoints (which could result in delayed transactions or even a
database halt if not addressed):
mysql> select node_id as 'data node', total as 'configured undo log
buffer size', used as 'used buffer space' from logbuffers where
log_type='DD-UNDO‘;
+-----------+---------------------------------+-------------------+
| data node | configured undo log buffer size | used buffer space |
+-----------+---------------------------------+-------------------+
| 3 | 2096128 | 0 |
| 4 | 2096128 | 0 |
+-----------+---------------------------------+-------------------+
• If log buffer is almost full then increase size of log buffer
MySQL Enterprise Monitor 2.3
Monitoring
Status Monitoring &
Recovery
Automated Management
Cluster-Wide
Management
Process Management
On-Line Operations
(Upgrades /
Reconfiguration)
HA Operations
Disk Persistence
Configuration
Consistency
HA Agent Operation
MySQL Cluster Manager 1.0 Features
Example configuration
• MySQL Cluster Manager agent
runs on each physical host
• No central process for Cluster
Manager – agents co-operate,
each one responsible for its local
nodes
• Agents are responsible for
managing all nodes in the cluster
• Management responsibilities
– Starting, stopping & restarting
nodes
– Configuration changes
– Upgrades
– Host & Node status reporting
– Recovering failed nodes
agent
1. ndb_mgmd
7. mysqld
192.168.0.10
agent
2. ndb_mgmd
8. mysqld
192.168.0.11
agent
5. ndbd
3. ndbd
192.168.0.12
agent
6. ndbd
4. ndbd
192.168.0.13
mysql
client
agent
n. ndb_mgmd
n. mysqld
n. ndbd
MySQL Server (ID=n)
Management Node (ID=n)
Data Node (ID=n)
MySQL Cluster Manager agent
Creating & Starting a Cluster
1. Define the site:
2. Expand the MySQL Cluster tar-ball(s)
from mysql.com to known directory
3. Define the package(s):
Note that the basedir should match the
directory used in Step 2.
4. Create the Cluster
This is where you define what
nodes/processes make up the Cluster and
where they should run
5. Start the Cluster:
agent
1. ndb_mgmd
7. mysqld
192.168.0.10
agent
2. ndb_mgmd
8. mysqld
192.168.0.11
agent
5. ndbd
3. ndbd
192.168.0.12
agent
6. ndbd
4. ndbd
192.168.0.13
mysql
client
Mysql> create site --hosts=192.168.0.10,192.168.0.11,
-> 192.168.0.12,192.168.0.13 mysite;
Mysql> add package --basedir=/usr/local/mysql_6_3_26 6.3;
Mysql> add package --basedir=/usr/local/mysql_7_0_7 7.0;
Mysql> create cluster --package=6.3
-> [email protected],[email protected],
-> [email protected],[email protected], [email protected],
-> [email protected],[email protected],[email protected]
-> mycluster;
Mysql> start cluster mycluster;
Upgrade Cluster
• Upgrade from MySQL Cluster 6.3.26 to 7.0.7:
• Automatically upgrades each node and restarts
the process – in the correct order to avoid any
loss of service
• Without MySQL Cluster Manager, the
administrator must stop each process in turn,
start the process with the new version and wait
for the node to restart before moving onto the
next one
agent
1. ndb_mgmd
7. mysqld
192.168.0.10
agent
2. ndb_mgmd
8. mysqld
192.168.0.11
agent
5. ndbd
3. ndbd
192.168.0.12
agent
6. ndbd
4. ndbd
192.168.0.13
mysql
client
mysql> upgrade cluster --package=7.0 mycluster;
MySQL Cluster Manager 1.1 GA 1st November 2010
• On-line add-node
mysql> add hosts --hosts=192.168.0.35,192.168.0.36 mysite;
mysql> add package --basedir=/usr/local/mysql_7_0_7 –
hosts=192.168.0.35,192.168.0.36 7.0;
mysql> add process --
[email protected],[email protected],ndbd@19
2.168.0.35,[email protected] mycluster;
mysql> start process --added mycluster;
• Restart optimizations
– Fewer nodes restarted on some parameter changes
Data
Node
Data
Node
mysqldMgmt
Nodemysqld
Mgmt
Node
31 32
33 34
Data
Node
Data
Node
mysqld mysqld
31 32
33 34
Data
Node
Data
Node•35 36
mysqldMgmt
Nodemysqld
Mgmt
Node
米国海軍航空母艦用航空機管理システムAviation Data Management and Control System (ADMACS)
• 艦載機・飛行甲板の運用管理
– 空母に搭載された航空機のメンテナンス、燃料補給計画の管理
– 空母上の飛行甲板の利用を含む、フライトプランの作成および管理
• MySQL Cluster
– 4ノードのLinux上で利用
– 単一障害点のない完全な冗長性
– 障害を想定したテストでの安定性とフットプリントの小ささが選択理由
• 世界最大の軍艦ニミッツ級航空母艦で運用中
NEC モバイルインターネットプラットフォーム
• 3G通信の顧客情報管理、ユーザ認証、アクセス制御、課金システム– アプリケーションによってSQLおよびAPIを利用
– 2,000万加入者のデータを管理
– 2,400TPSを処理
• 将来の加入者やデータ量、処理能力の増加に備えたフレキシブルなサーバ構成が可能
お客様の声
MySQL Clusterの安定性と処理性能はすでに理解していましたが、特に選定の決め手となったのは導入の容易性と、拡張性の高さです。
MySQLの高可用性構成
MySQL
Cluster
MySQL
Cluster
アプリケーション/APサーバ
負荷分散
双方向同期複製
• MySQL Clusterシェアードナッシング型高性能クラスタ
MySQL
Server
• MySQL+DRBDLinux用のノード間データコピー
アプリケーション/APサーバ
フェールオーバー
同期複製
MySQL
Server
アプリケーション/APサーバ
共有ディスク
• 3rdベンダ製HAソフト利用共有ディスクにデータを格納
フェールオーバー
MySQL
Server
MySQL
Server
アプリケーション/APサーバ
負荷分散
非同期複製準同期複製
• レプリケーション(標準機能)非同期&準同期データレプリケーション
MySQL
Server
MySQL
Server
Requirements Replication ClusterMySQL &
DRBD
Availability
Automatic Fail Over No Yes Yes
Fail Over Time Varies < 1 sec < 5 min
Resynch of Data No Yes Yes
Geographic Redundancy Yes Yes No
Scalability
Load Balancing Scale-Out Yes No
Read Intensive Yes Yes No
Write Intensive No Yes No
# of Nodes 100’s(reads) 255 1 Active
SQL Functionality
Primary Key Lookups Yes Yes Yes
Simple JOINs Yes Yes Yes
Complex JOINs Yes No Yes
Transactions Yes Yes Yes
37