Upload
taejun
View
2.809
Download
4
Tags:
Embed Size (px)
DESCRIPTION
Mysql replication & cluster
Citation preview
MySQL Replication & Cluster
Ariz C. JacintoPLUG, Inc.
MySQL Overview
Most popular open source database.
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 dynamicenvironment.
A system is said to scale if it is suitably efficient and practical when applied to large situations. Meaning, if the design fails when the quantity increases then it does not scale.
Types of Scaling
Vertical - Increase of processors, memory, etc. within one operating environment.
Horizontal – Increase of machines working in parallel for the same task (Clustering). Each system has its own operating system and one or more processors controlled by each system image.
Horizontal Scaling (Clustering)
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?
(Database) SQL Replication
When is Database Replication Needed?
Case 1: Eliminating Cross-Host Query.
db_1 db_2db_1
Server 1 Server 2
on Server 2SELECT db1.tbl1.data, db2.tbl2.data WHERE ...
When is Database Replication Needed?
Case 2: Manage the Database Load.
db_1 db_1
Write Server( Insert / Update / Delete)
Read Server( Select )
When is Database Replication Needed?
Case 3: Hot-backup.
db_1 db_1
Production Server Backup Server
How MySQL Replication Works
binlog
Slave I/O Thread
MySQL Daemon
Slave Thread Relay
Log
binlog
Master Thread
MySQL Daemon
C l i e n t s
Configuration of MySQL for Replication
Download the latest stable MySQL 4.0.x version.
Determine the Master and Slave(s).
Edit /etc/my.cnf
Creation of replication user-account on Replication Master.
Configuration of MySQL for Replication
Sample Setup
Database Server 1192.168.0.1
Database Server 2192.168.0.2
Configuration of Replication Master
/etc/my.cnf
[mysqld]log-binserver-id = 1
mysql> GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'192.168.0.2';
Replication Client User-Account Creation on Master
Configuration of Replication Slave
/etc/my.cnf
[mysqld]server-id = 2master-host = 192.168.0.1master-user = replicator
Start / Stop Replication
Start Replication Master & Slave(s)
shell> service mysqld start
Start / Stop Replication Client
mysql> start slavemysql> stop slave
Replication With Existing Data
1. Record the bin log name & position on the master.
mysql > SHOW MASTER STATUS; File Position mysql-bin.013 213
2. Dump the data from the master into an SQL file.
3. Copy & dump the SQL file to the slave.
mysql> source /path/to/file.sql
4. Alter the slave's replication starting point
using the recorded bin log info....
master_log_file = “mysql-bin.013”master-user = 213slave-skip-errors = 1062
Replication With Existing Data
SQL updates might occur on the Master in-between the recording of the binlog info and the dumping of data into the slave.
Thus, data already exists on the slave, by the time replication is being started.
Replication Error 1062: Duplicates
Filtering of Database & Tables to be Replicated
[mysqld]...replicate-db = db1replicate-table = db1.tbl1
replicate-ignore-db = db2replicate-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
[mysqld]...log-slave-update
db_1 db_1db_2 db_2
Slave Require Multiple Replication Masters
Currently not supported, but replication from two masters is possible in a round-robin fashion using a script.
Slaves
Master
Slave
Masters
Slave Require Multiple Replication Masters
*Real-time replication from two masters.
SlaveMaster Master(Slave)
db_1db_2
db_1db_2
db_1
Monitoring MySQL Replication
Check if replication threads are running.
mysql> show slave status\G;
Data Integrity - Row per Row Matching. - MD5 Checksum. - Routine Re-Dumping of Data.
Load-Balancing
Master(Write)
Director
Slaves(Read-Only)
Director(backup)
clients
Virtual IP
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.3real = 192.168.0.1real = 192.168.0.2request = [customized mysql page]receive = [expected result]
Using Heartbeat for MySQL HA
1. Configure Heartbeat.
/etc/ha.d/haresources 192.168.0.3 mysqld
2. Bind the MySQL service on the backup node to the virtual ip address.
3. Create a script to handle the re-sync of master from slave before it assumes again the role of the main server.
Using MySQL Cluster for HA (active/active)
db_1 db_1
Master( active )
Master( active )
Using MySQL Cluster for HA
Clustering of databases in a fault-tolerant system.
Standard MySQL server with an in-memory clustered storage engine called NDB.
Data stored in NDB, are immediately available on all data nodes.
Using MySQL Cluster for HA (active/active)
ClusterManager
MySQL Farm( Read / Write )
clients
StorageEngine
Virtual IP
Configuring MySQL Cluster(Management Server)
config.ini ...[NDB_MGMD]
HostName = 192.168.0.250[NDBD]
HostName = 192.168.0.1[NDBD]
HostName = 192.168.0.2..
Start the controller / management server:
shell> ndb_mgmd
Configuring MySQL Cluster(Database Nodes)
/etc/my.cnf
[mysqld]ndbclusterndb-connectstring = 192.168.0.250
[mysql_cluster]ndb-connectstring = 192.168.0.250
Start storage engine / mysql daemon
shell> ndbd --initial shell> service mysql start
Checking MySQL Clusteron Management Server
shell> ndb_mgm
ndb_mgm> showConnected to Management ServerCluster Configuration[ndbd(NDB)] 2 node(s)id=2 @192.168.0.1id=3 @192.168.0.2
[ndb_mgmd(MGM)] 1 node(s)id=1 @192.168.0.250
MySQL Replication & Cluster
Ariz C. JacintoPLUG, Inc.