Mysql Replication & Cluster
Mysql Replication & Cluster
Ariz C. Jacinto
PLUG, Inc.
MySQL Overview
Part of the LAMP stack: GNU/Linux,
Apache, MySQL, PHP/Perl/Python.
+ + +
MySQL Replication & Cluster,
What for?
Scalability.
High-availabilty.
Scalability Defined
Scalability is a key success factor for
business applications in a dynamic
environment.
High-Perfomance Computing
OpenMosix, etc.
Horizontal Scaling (Clustering)
Load–Balancer
DNS Round-Robin, LVS Director, etc.
farm
director
Horizontal Scaling (Clustering)
High-Availability / Failover
LinuxHA (Heartbeat), etc.
hot standby
How to Replicate Data on
GNU/Linux?
Rsync
How to Replicate Data on
GNU/Linux?
DRBD
raid1-over-network
How to Replicate Data on
GNU/Linux?
Server 1 Server 2
on Server 2
SELECT db1.tbl1.data, db2.tbl2.data WHERE ...
When is Database Replication
Needed?
Case 2:
Manage the Database Load.
db_1 db_1
Case 3:
Hot-backup.
db_1 db_1
Clients
MySQL MySQL
Daemon binlog
Daemon
b
i
n
l Slave
Thread Relay
o
g
Master Slave I/O Log
Thread Thread
Configuration of MySQL for
Replication
Download the latest stable
MySQL 4.0.x version.
Edit /etc/my.cnf
Sample Setup
/etc/my.cnf
[mysqld]
log-bin
server-id = 1
Replication Client User-
Account Creation on Master
/etc/my.cnf
[mysqld]
server-id =2
master-host = 192.168.0.1
master-user = replicator
Start / Stop Replication
[mysqld]
...
replicate-db = db1
replicate-table = db1.tbl1
replicate-ignore-db = db2
replicate-ignore-table = db1.tbl2
Renaming of Database &
Tables to be Replicated
[mysqld]
...
replicate-rewrite-db = db1->db2
replicate-rewrite-table = db1.tbl1->db1.tbl2
Dual Replication Function,
Master & Slave
db_1 db_1
db_2 db_2
[mysqld]
...
log-slave-update
Slave Require Multiple
Replication Masters
Master Masters
Slaves Slave
Data Integrity
- Row per Row Matching.
- MD5 Checksum.
- Routine Re-Dumping of Data.
Load-Balancing
Virtual IP
c
l
i
e
Director
n
t
s Master
(Write)
Director Slaves
(backup) (Read-Only)
Load-Balancing Using Linux
Director & Heartbeat
/etc/ha.d/haresources
192.168.0.3 ldirectord::mysql
/etc/ha.d/mysql.cf
...
virtual = 192.168.0.3
real = 192.168.0.1
real = 192.168.0.2
request = [customized mysql page]
receive = [expected result]
Using Heartbeat for MySQL HA
1. Configure Heartbeat.
/etc/ha.d/haresources
192.168.0.3 mysqld
db_1 db_1
Master Master
( active ) ( active )
Using MySQL Cluster for HA
Data stored in NDB, are immediately
available on all data nodes.
Using MySQL Cluster for
HA (active/active)
Virtual IP
c
l
i
e
n
t
s Cluster
Manager
shell> ndb_mgmd
Configuring MySQL Cluster
(Database Nodes)
/etc/my.cnf
[mysqld]
ndbcluster
ndb-connectstring = 192.168.0.250
[mysql_cluster]
ndb-connectstring = 192.168.0.250
shell> ndb_mgm
ndb_mgm> show
Connected to Management Server
Cluster Configuration
[ndbd(NDB)] 2 node(s)
id=2 @192.168.0.1
id=3 @192.168.0.2
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.0.250
MySQL
Replication & Cluster
Ariz C. Jacinto
PLUG, Inc.