Oracle veröffentlichte im Mai 2014 MySQL Fabric . MySQL Fabric ist ein Framework das ein MySQL Server um zwei Funktionen erweitert: High Availability (HA) und Sharding. High Availability (HA) wurde bereits teilweise durch MySQL Replication oder durch MySQL Cluster erreicht . Sharding in Form von vertical partitioning existiert bereits seit MySQL 5.1 . MySQL Cluster (MySQL NDB Cluster) versucht durch die in-memory storage engine NDB das horizontal partitioning, jedoch mit der Einschränkung dass alle Daten in den RAM passen müssen. Betreibt man zum Beispiel 4 x MySQL Server mit insgesamt 10 TB (Daten + Index), dann benötigt man laut der Formel in den MySQL FAQ’s ohne Replikation 172 Server mit 64GB RAM. Neben dieser Entschränkung, sind der höhere Konfigurationsaufwand und das neue Schema-Design Hürden, warum MySQL Cluster keiner großen Beliebtheit findet . In vielen Fällen ist es dann einfacher die Logik der horizontalen Partitionierung in die Applikation zu implementieren. MySQL Fabric verwendet einen anderen Sharding-Ansatz. Schauen wir uns das genauer an.
Setup
Versuchen wir ein MySQL Fabric Cluster auf einem Server mit Ubuntu 14.04 aufzusetzen. Ziel soll es sein ein Gefühl dafür zu bekommen, wie hoch der Konfigurationsaufwand ist.
MySQL Fabric
v1.4
MySQL Fabric ist seit 2014 ein Teil von MySQL Utilities v.1.4. MySQL Utilities ist zum einen eine Sammlung von nützlichen Commandline-Befehlen wie z.B. dem Befehl mysqldbcompare, das 2 Datenbanken vergleicht, und zum anderen enthält MySQL Utilities eine python Library.
v1.5
Download die Version Generic Linux mysql-utilities-1.5.6.tar.gz. Zusätzlich wird noch MySQL Connector/Python benötigt. Wie man die installiert steht weiter unten unter v1.6. Die Dokumentation zu MySQL Fabric 1.5 findet man hier. Überprüfen wir nun erstmal ob alles richtig installiert ist.
1 2 |
root@schroedingerdb:~# mysqlfabric --version mysqlfabric 1.5.6 |
mysqlfabric manage setup
1 2 3 4 5 6 7 8 |
root@schroedingerdb:~# mysqlfabric manage setup [INFO] 1452452809.218858 - MainThread - Initializing persister: user (fabric_store), server (localhost:3306), database (mysql_fabric). [INFO] 1452452809.882569 - MainThread - Initial password for admin/mysql set Password set for admin/mysql from configuration file. [INFO] 1452452809.887876 - MainThread - Password set for admin/mysql from configuration file. [INFO] 1452452809.888676 - MainThread - Initial password for admin/xmlrpc set Password set for admin/xmlrpc from configuration file. [INFO] 1452452809.894082 - MainThread - Password set for admin/xmlrpc from configuration file. |
mysqlfabric manage start
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
root@schroedingerdb:~# mysqlfabric manage start [INFO] 1452452881.390901 - MainThread - Initializing persister: user (fabric_store), server (localhost:3306), database (mysql_fabric). [WARNING] 1452452881.397387 - MainThread - Provider error: No module named novaclient. [INFO] 1452452881.397639 - MainThread - Loading Services. [INFO] 1452452881.404998 - MainThread - MySQL-RPC protocol server started, listening on localhost:32275 [INFO] 1452452881.430640 - MainThread - Fabric node version (1.5.6) started. [INFO] 1452452881.433099 - MainThread - Starting Executor. [INFO] 1452452881.433602 - MainThread - Setting 5 executor(s). [INFO] 1452452881.434206 - Executor-0 - Started. [INFO] 1452452881.435259 - Executor-1 - Started. [INFO] 1452452881.442346 - Executor-2 - Started. [INFO] 1452452881.442682 - Executor-3 - Started. [INFO] 1452452881.444366 - Executor-4 - Started. [INFO] 1452452881.445302 - MainThread - Executor started. [INFO] 1452452881.468636 - MainThread - Starting failure detector. [INFO] 1452452881.477982 - XML-RPC-Server - XML-RPC protocol server ('127.0.0.1', 32274) started. [INFO] 1452452881.478761 - XML-RPC-Server - Setting 5 XML-RPC session(s). [INFO] 1452452881.479288 - XML-RPC-Session-0 - Started XML-RPC-Session. [INFO] 1452452881.480592 - XML-RPC-Session-1 - Started XML-RPC-Session. [INFO] 1452452881.482330 - XML-RPC-Session-2 - Started XML-RPC-Session. [INFO] 1452452881.498343 - XML-RPC-Session-3 - Started XML-RPC-Session. [INFO] 1452452881.499557 - XML-RPC-Session-4 - Started XML-RPC-Session. |
Fabric kann man auch als Daemon starten mit dem Befehl:
mysqlfabric manage start –daemonize
Danach kann eine fabric group erstellt werden.
mysqlfabric group create my_group
1 2 3 4 5 6 7 8 9 10 11 12 13 |
root@schroedingerdb:/etc/mysql# mysqlfabric group create my_group Fabric UUID: 5ca1ab1e-a007-feed-f00d-cab3fe13249e Time-To-Live: 1 uuid finished success result ------------------------------------ -------- ------- ------ 27dfceac-d330-42ca-b0b9-cd375362d70c 1 1 1 state success when description ----- ------- ------------- ------------------------------------------------------------------ 3 2 1452454288.11 Triggered by <mysql.fabric.events.Event object at 0x7fb675b26210>. 4 2 1452454288.12 Executing action (_create_group). 5 2 1452454288.12 Executed action (_create_group). |
Server können so zu einer Gruppe hinzugefügt werden.
mysqlfabric group add my_group localhost:3307
1 2 3 4 5 6 7 8 9 10 11 12 13 |
root@schroedingerdb:/etc/mysql# mysqlfabric group add my_group localhost:3307 Fabric UUID: 5ca1ab1e-a007-feed-f00d-cab3fe13249e Time-To-Live: 1 uuid finished success result ------------------------------------ -------- ------- ------ 212e884a-dc27-48b7-8370-b3999de03f1b 1 1 1 state success when description ----- ------- ------------- ------------------------------------------------------------------ 3 2 1452454387.7 Triggered by <mysql.fabric.events.Event object at 0x7fb675b265d0>. 4 2 1452454387.7 Executing action (_add_server). 5 2 1452454387.72 Executed action (_add_server). |
Wenn bei dem Server keine Replikation aktiviert ist, dann erhält man diese Fehlermeldung.
1 2 3 4 5 |
root@schroedingerdb:/etc/mysql# mysqlfabric group add my_group localhost:3307 Fabric UUID: 5ca1ab1e-a007-feed-f00d-cab3fe13249e Time-To-Live: 1 ServerError: Server (2a99c526-b23e-11e5-97d1-080027f54660) does not have the binary log or gtid enabled. |
Die Replikation per GTID (Global Transaction Identifier) lässt sich beim Start des Servers so aktivieren.
1 |
/usr/bin/mysqld_safe --defaults-file=/etc/mysql-1/my.cnf --gtid_mode=ON --log-bin --log-slave-updates --enforce-gtid-consistency |
Fügt man zwei weitere Server hinzu:
– mysqlfabric group add my_group localhost:3308
– mysqlfabric group add my_group localhost:3309
dann lässt sich der Status des clusters mit diesem Befehl prüfen.
1 2 3 4 5 6 7 8 9 10 11 12 |
root@schroedingerdb:/etc/mysql# mysqlfabric group health my_group Fabric UUID: 5ca1ab1e-a007-feed-f00d-cab3fe13249e Time-To-Live: 1 uuid is_alive status is_not_running is_not_configured io_not_running sql_not_running io_error sql_error ------------------------------------ -------- --------- -------------- ----------------- -------------- --------------- -------- --------- 24417a8e-b23e-11e5-97d1-080027f54660 1 SECONDARY 0 1 0 0 False False 2a99c526-b23e-11e5-97d1-080027f54660 1 SECONDARY 0 1 0 0 False False 36e4a762-b23e-11e5-97d1-080027f54660 1 SECONDARY 0 1 0 0 False False issue ----- |
Alle Konfigurationen bis hierhin wurden noch nicht aktiviert. Das erfolgt mit:
mysqlfabric group promote my_group
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
root@schroedingerdb:/etc/mysql# mysqlfabric group promote my_group Fabric UUID: 5ca1ab1e-a007-feed-f00d-cab3fe13249e Time-To-Live: 1 uuid finished success result ------------------------------------ -------- ------- ------ efdac49b-949e-41fa-8138-c8f0cee5369f 1 1 1 state success when description ----- ------- ------------- ------------------------------------------------------------------ 3 2 1452455813.57 Triggered by <mysql.fabric.events.Event object at 0x7fb675ebc8d0>. 4 2 1452455813.57 Executing action (_define_ha_operation). 5 2 1452455813.58 Executed action (_define_ha_operation). 3 2 1452455813.58 Triggered by <mysql.fabric.events.Event object at 0x7fb675ebc890>. 4 2 1452455813.59 Executing action (_find_candidate_fail). 5 2 1452455813.61 Executed action (_find_candidate_fail). 3 2 1452455813.61 Triggered by <mysql.fabric.events.Event object at 0x7fb675d7fc90>. 4 2 1452455813.61 Executing action (_check_candidate_fail). 5 2 1452455813.62 Executed action (_check_candidate_fail). 3 2 1452455813.62 Triggered by <mysql.fabric.events.Event object at 0x7fb675d7fd10>. 4 2 1452455813.62 Executing action (_wait_slave_fail). 5 2 1452455813.64 Executed action (_wait_slave_fail). 3 2 1452455813.64 Triggered by <mysql.fabric.events.Event object at 0x7fb675d7fe50>. 4 2 1452455813.64 Executing action (_change_to_candidate). 5 2 1452455813.72 Executed action (_change_to_candidate). |
Danach sieht man dass nun ein Server der Master ist.
1 2 3 4 5 6 7 8 9 10 11 12 |
root@schroedingerdb:/etc/mysql# mysqlfabric group health my_group Fabric UUID: 5ca1ab1e-a007-feed-f00d-cab3fe13249e Time-To-Live: 1 uuid is_alive status is_not_running is_not_configured io_not_running sql_not_running io_error sql_error ------------------------------------ -------- --------- -------------- ----------------- -------------- --------------- -------- --------- 24417a8e-b23e-11e5-97d1-080027f54660 1 SECONDARY 0 0 1 1 False False 2a99c526-b23e-11e5-97d1-080027f54660 1 SECONDARY 0 0 1 1 False False 36e4a762-b23e-11e5-97d1-080027f54660 1 PRIMARY 0 0 0 0 False False issue ----- |
Alles Weitere findet man in der MySQL Fabric Quick Start Dokumentation.
v1.6
Seit der MySQL Utilities Version 1.6 ist MySQL Fabric kein Teil mehr dieser, sondern ein eigenes Paket. Es hat nun seine eigene Dokumentation und Downloadbereich. MySQL Fabric v1.6 benötigt MySQL Instanzen ab der Version 5.6.17. MySQL Fabric v1.6 ist gerade (3. Januar 2016) nur für den Testbetrieb geeignet – produktiv sollte es nicht eingesetzt werden.
Herunterladen kann man MySQL Fabric v1.6 hier. Die Installation ist einfach und in den MySQL Docs beschrieben. Zusätzlich muss der mysql-connector-python aktualisiert werden. Dazu muss man das mysql apt repo installieren.
1 2 3 4 |
sudo dpkg -i mysql-apt-config_0.6.0-1_all.deb sudo apt-get update sudo apt-get install mysql-connector-python ln -s /etc/mysql /usr/local/etc/mysql |
MySQL Fabric user auf allen Instanzen anlegen und config unter /etc/mysql/fabric.cnf bearbeiten, wie in der Fabric 1.6 Dokumentation beschrieben. Dann mit mysqlfabric manage setup das cluster anlegen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
mysqlfabric manage setup ################### MASTER PASSWORD SETUP ################ Enter the master password that is used for encrypting all fabric passwords. ######################################################### master Password: Retype master Password: ################# STORAGE PASSWORD SETUP ################ Enter the authentication information for accessing the state store ######################################################### storage Username [root]: fabric_store storage Password: Retype storage Password: ################################################### WARNING: Storage password file being overwritten ################################################### [INFO] 1452448303.303227 - MainThread - Initializing persister: user (fabric_store), server (localhost:3306), database (mysql_fabric). Password for admin/mysql is not yet set and cannot be empty. Trying to read it from the configuration file. Note that password is not replicated at this point. Password set for admin/mysql from configuration file. Password for admin/xmlrpc is not yet set and cannot be empty. Trying to read it from the configuration file. Note that password is not replicated at this point. Password set for admin/xmlrpc from configuration file. |
Danach gibt es eine neue Tabelle mysql_fabric auf localhost:3306. Mit mysqlfabric manage start lässt sich fabric starten, leider gibt es wohl noch auf ubuntu einen Bug.
1 2 3 4 5 6 7 8 |
mysqlfabric manage start --foreground master Password: [INFO] 1452448742.101373 - MainThread - Initializing persister: user (fabric_store), server (localhost:3306), database (mysql_fabric). [INFO] 1452448742.113543 - MainThread - Loading Services. [INFO] 1452448742.127655 - MainThread - MySQL-RPC protocol server started, listening on localhost:32275 [WARNING] 1452448742.146372 - MainThread - Provider error: No module named novaclient. [INFO] 1452448742.147522 - MainThread - Loading Services. Error: MySQL GCS is not properly installed but the clustering capabilities were requested. |
MySQL Instanzen
Installieren wir erstmal mit puppet 4 MySQL 5.6 Instanzen. Wie man die benötigten puppet module mysql und sdb_mysql installiert, steht hier.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
$root_password = "root" $override_options = { 'mysqld' => { 'bind-address' => '0.0.0.0', } } class { 'mysql::server': root_password => $root_password, override_options => $override_options, package_name => 'mysql-server-5.6' } class { 'sdb_mysql':; } sdb_mysql::instance { 'mysql-1': port => 3307, override_options => $override_options ; 'mysql-2': port => 3308, override_options => $override_options ; 'mysql-3': port => 3309, override_options => $override_options ; } |
PHP Client
Für PHP existiert eine Kurzanleitung die beschreibt, wie man in MySQL Fabric eine Tabelle anlegt, einen Datensatz einfügt und diesen ausliest.