MySQL Cluster und MySQL Proxy Alles Online Diese Slides gibt es - - PowerPoint PPT Presentation

mysql cluster und mysql proxy alles online
SMART_READER_LITE
LIVE PREVIEW

MySQL Cluster und MySQL Proxy Alles Online Diese Slides gibt es - - PowerPoint PPT Presentation

MySQL Cluster und MySQL Proxy Alles Online Diese Slides gibt es auch unter: http://rt.fm/s4p Agenda (Don't) Panic Web- und MySQL-Server MySQL Master-Master Cluster MySQL Proxy und Cluster MySQL


slide-1
SLIDE 1

MySQL Cluster und MySQL Proxy

slide-2
SLIDE 2

Alles Online

  • Diese Slides gibt es auch unter:
  • http://rt.fm/s4p
slide-3
SLIDE 3
slide-4
SLIDE 4

Agenda

  • (Don't) Panic
  • Web- und MySQL-Server
  • MySQL Master-Master Cluster
  • MySQL Proxy und Cluster
  • MySQL Master-Slave/Master
  • Konfiguration
  • Replication Manager
  • MySQL Proxy
  • Aufgaben
  • LUA
  • Konfiguration
  • Live Demo
slide-5
SLIDE 5

(Don't) Panic

slide-6
SLIDE 6

Web- und MySQL-Server

slide-7
SLIDE 7

MySQL Master-Master Cluster

slide-8
SLIDE 8

MySQL Proxy und Cluster

slide-9
SLIDE 9

MySQL Master-Slave/Master

slide-10
SLIDE 10

Pre-Konfiguration

  • Empfehlung:
  • leere MySQL Server ohne Datenbank
  • ggf. Datenbank Sicherung und auf allen Cluster-Nodes einspielen

$ mysqldump --opt --allow-keywords --add-drop-database

  • -hex-blob --quote-names --lock-tables

<dbname>

slide-11
SLIDE 11

Konfiguration - my.cnf

[mysql] # Server IDs should be consecutive (1, 2, 3, ...) # among all master servers server_id = 1 server_id = 1 # The increment should be set to the number of # master servers involved (default: 1) auto_increment_increment = 2 auto_increment_increment = 2 # The offset should be set to the local server-id (default: 1) auto_increment_offset = 1 auto_increment_offset = 1 # Using those, the NEXT_INSERT_ID is calculated as follows: # (NOTE: all values are integral, thus a division is whole-numbered as well) # AI_SEQUENCE = (AI_CURRENT + AI_INCREMENT - AI_OFFSET) / AI_INCREMENT # NEXT_INSERT_ID = AI_SEQUENCE * AI_INCREMENT + AI_OFFSET # The binary log (master role) log_bin = /var/log/mysql/mysql-bin.log log_bin = /var/log/mysql/mysql-bin.log log_bin_index = /var/log/mysql/mysql-bin.log.index log_bin_index = /var/log/mysql/mysql-bin.log.index # The relay log where binary log data from the master is written to # by the IO thread before being read by the SQL thread (slave role) relay_log = /var/log/mysql/mysql-relay-bin relay_log = /var/log/mysql/mysql-relay-bin relay_log_index = /var/log/mysql/mysql-relay-bin.index relay_log_index = /var/log/mysql/mysql-relay-bin.index # Purge binary logs older than this many days expire_logs_days = 10 expire_logs_days = 10 # Maximum size of single binary log files max_binlog_size = 100M max_binlog_size = 100M # Log updates received as a slave from a master to the own # binary log (used for circular master-master replication) log_slave_updates = 1 log_slave_updates = 1

slide-12
SLIDE 12

Konfiguration - Benutzer

  • Anlegen eines Benutzers mit Replikationsrechten
  • Host-Rechte sollten ggf. eingeschränkt werden

mysql-01> GRANT SUPER, REPLICATION CLIENT, REPLICATION SLAVE ON *.* \ TO 'replication'@'192.168.0.%' IDENTIFIED BY 'secret'; mysql-02> GRANT SUPER, REPLICATION CLIENT, REPLICATION SLAVE ON *.* \ TO 'replication'@'192.168.0.%' IDENTIFIED BY 'secret';

slide-13
SLIDE 13

Konfiguration - Slave

  • Festlegen des Master Servers
  • SSL von Vorteil

mysql-01> CHANGE MASTER TO master_host='masterserver', master_port=3306, master_user='replication', master_password='secret', master_ssl = 1, maser_ssl_ca = '/etc/ssl/certs/class3.pem';

slide-14
SLIDE 14

MySQL Status Master

mysql> show master status; +------------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------------+----------+--------------+------------------+ |MysqlMYSQL01-bin.000008 | 410 | adam | | +------------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)

Slave

mysql> show slave status\G; * ** ** **** 1. row *** 1. row * ** ** **** Slave_IO_State: Waiting for master to send event Master_Host: mysqlserver Master_User: replication Master_Port: 3306 Connect_Retry: 60 Master_Log_File: Mysql1MYSQL02-bin.000008 Read_Master_Log_Pos: 410 [...]

slide-15
SLIDE 15

Multi-Master Replication Manager

Was ist MMM?

  • HA Lösung mit Failover Möglichkeit
  • Automatisches Failover für Slave-Server

Was it MMM nicht?

  • Load Balancer
  • 100% Zuverlässig (Replikation ist nicht Perfekt)

Anleitung für die Installation: http://mysql-mmm.org/

slide-16
SLIDE 16

MMM Problem und Lösung

slide-17
SLIDE 17

MMM Problem und Lösung

slide-18
SLIDE 18

MMM Problem und Lösung

slide-19
SLIDE 19

MySQL Proxy

slide-20
SLIDE 20

Aufgaben

  • Erstellung neuer MySQL Befehle
  • Filterung von MySQL Queries
  • Query Analyze
  • Query Quota Support
  • Ausführen von Shell Scripten
  • Monitoring
  • Load Balancing
  • MySQL-Server Remote Steuerung (start/stop)
  • Kaffee kochen
slide-21
SLIDE 21

Übersicht

slide-22
SLIDE 22
slide-23
SLIDE 23

Lua

  • Scriptsprache
  • Entworfen für Embedded Systeme
  • MySQL Proxy ist mit Lua-Script erweiterbar

Funktion in Lua

function f (x) print(x) end g = f g(10)

slide-24
SLIDE 24

MySQL Proxy - Keywords

  • connect_server()
  • Wird beim Verbinden zum MySQL Server aufgerufen (Benötigt z.B. für Load Balancer)
  • read_query(packet)
  • Funktion wird vor dem Senden an den MySQL Server aufgerufen
  • read_query_result(injection_packet)
  • Diese Funktion wird vor dem Senden des MySQL Servers an den Client aufgerufen
slide-25
SLIDE 25

MySQL Proxy - Query Abfangen inform_user.lua

  • - inform_user.lua

function read_query(packet) if string.byte(packet) == proxy.COM_QUERY then print("The client committed the following query: " .. string.sub(packet, 2)) end end

Ausgabe

The client committed the following query: show tables The client committed the following query: select * from t The client committed the following query: select * from t The client committed the following query: insert into t ( c ) values ( 'blub' )

slide-26
SLIDE 26

MySQL Proxy - Query Aufsplitten

slide-27
SLIDE 27

MySQL Proxy - Query Aufsplitten

slide-28
SLIDE 28

Usage

/usr/local/sbin/mysql-proxy

  • -proxy-lua-script

=</path/name.lua>

  • -proxy-address

=<host:port>

  • -proxy-read-only-backend-addresses

=<host:port>

  • -proxy-backend-addresses

=<host:port>

Das Script wird erst ab dem ersten verbunden Client ausgeführt

slide-29
SLIDE 29

Live Demo

  • mysql-01: MySQL Master
  • mysql-02: MySQL Master
  • mysql-03: MySQL Slave
  • web-01: MySQL Proxy und Webserver
slide-30
SLIDE 30

Quellen

  • http://mysql-mmm.org/mmm2:guide
  • http://forge.mysql.com/w/images/0/05/DualMasterSetupsWithMMM.pdf
  • http://www.admin-magazin.de/[..]/Verteilte-Datenbank-mit-MySQL-Proxy
  • http://datacharmer.org/[..]/mysql_proxy_oscon_2008a.pdf
  • http://www.fromdual.ch/sites/default/files/doag_regio_2011-03.pdf
slide-31
SLIDE 31

Fragen? 42!