Archive for the ‘HA’ Category

MySQL 5.6 Replication: FAQ

Май 23rd, 2012

On Wednesday May 16th, we ran a webinar to provide an overview of all of the new replication features and enhancements that are previewed in the MySQL 5.6 Development Release – including Global Transaction IDs, auto-failover and self-healing, multi-threaded, crash-safe slaves and more.

Collectively, these new capabilities enable MySQL users to scale for next generation web and cloud applications.

Attendees posted a number of great questions to the MySQL developers, serving to provide additional insights into how these new features are implemented. So I thought it would be useful to post those below, for the benefit of those unable to attend the live webinar (note, you can listen to the On-Demand replay which is available now).

Before getting to the Q&A, there are a couple of other resources that maybe useful to those wanting to learn more about Replication in MySQL 5.6

On-Demand webinar

Slides used during the webinar

For more detail on any of the features discussed below, be sure to check out the Developer Zone article: Replication developments in MySQL 5.6

So here is the Q&A from the event 

Multi-Threaded Slaves

The results from recent benchmarking of the Multi-Threaded Slave enhancement were discussed, prompting the following questions

Q. Going from 0 - 10 threads, did you notice any increase in IOwait on CPU?

A. In this case, yes. The actual amount depends on a number of factors: your hardware, query/transaction distribution across databases, server general and InnoDB specific configuration parameters.

Q. Will the multiple threads work on different transactions on the same database, or each thread works on a separate database?

A. Each worker thread works on separate databases (schemas).

Q. If I set the slave-parallel-workers to less than the number of databases, can I configure which databases use which worker threads?

A. There is no such configuration option to assign a certain Worker thread to a database. Configuring slave-parallel-workers to less than the number of databases is a good setup. A Worker can handle multiple databases.

Q. If I create 4 threads and I have 100 databases, can I configure which databases use which threads?

A. There won't be 1 worker to a mapping of exactly 25 databases, but it will be very close to that type of distribution.

Q. Thank You. I ask as we have about 8 databases that have a lot of transactions and about 30 that are used less frequently. It would be nice to have the ability to create 9 workers, 1 for each if the heavy databases and 1 for all the others

A. The current design enables relatively equal distribution of transactions across your databases, but it could be that 9 workers will fit anyway.

Q. Does multi-thread slave still work if there is foreign key across database?

A. MTS preserves slave consistency *within* a database, but not necessarily *between* databases. With MTS enabled and replication ongoing, updates to one database can be executed before updates to another causing them to be temporarily out of sync with each other.

Q. How is auto-increment managed with the multi-thread slave?

A. MTS makes sure Worker threads do not execute concurrently on the same table. Auto-increment is guaranteed to be handled in the same way as the single threaded "standard" slave handles auto-increment

Q. Can you use semi-synchronous replication on one of the slaves when using MTS?

A. Semi-sync is friendly to MTS. MTS is about parallel execution - so they cooperate well.

Optimized Row Based Replication

Q. If you only store the PK column in the Before Image for updates, does this mean you don't care about the slave's data potentially being out-of-sync? Will we be able to control how much data is stored in the binary logs?

A. The rule is that we ship a *PK equivalent* so that the slave is always able to find a row. This means:
  1. if master table has PK, then we ship the PK only
  2. if master table does not have PK, then we ship the entire row

Global Transaction IDs and HA Utilities

Q. Would the failover utility need to sit on a 3rd party host to allow arbitration?

A. The utility would typically run on a client, not on the hosts it is monitoring

Q. Can you explain the upgrade process to move to MySQL 5.6? I am assuming that the slave(s) are upgraded first and that replication would be backwards compatible. And after the slave(s) are upgraded, the master would be next. But then how do you turn on the GTID?

A. Right: the slave(s) are upgraded first. After upgrading Slaves they would be started with --gtid-mode=on (technically a couple of other options are needed as well). And then the same process would be followed for the upgraded Master.

Q. For failover functionality, if I had a setup like this: Server1 replicates to Server2, Server2 replicates to Server3, Server4, and Server5. If Server2 were to fail, can I have it configured so that Server1 can become the new master for Server3/4/5?

A. Yes - you can either configure the failover to the most recent slave based on GTID, or list specific candidates. What will happen is that Slave 1 will temporarily become a slave of 3, 4 and 5 to ensure it replicates any more recent transactions those slaves may have, and then it will become the master

Replication Event Checksums

Q. What is the overhead of replication checksums?

A. It is minimal - we plan to publish benchmarks over the summer to better characterize any overhead

Q. Are you exposing the checksum to the plugin api so we can add our own checksum types?

A. We prepared some of interfaces, i.e. checksum methods are identified by a specific code byte (1-127) values. But it's not really a plugin at this point.

Q. Do checksums verify both replicated data and the data on slave?

A. Yes - checksums are implemented across the entire path - so you can check for issues in replication itself, or in the hardware or network

Q. I think, it is better to turn on checksums at the relaylog to avoid overhead on the master, but if we do that and checksum fails (i.e. not matching the master's data) then what happens – will the slave throw an error

A. I agree, it's better to relax the Master, which verifies the checksum only optionally when the Dump Thread reads from the binlog prior to the replication event being sent out to the Slave. The slave mandatorily checks the checksummed events when they are sent across the network, and optionally when they are read from Relay-log. In either case, an error is thrown.

Q. Are checksums optional? In some cases we don't care for huge data loads

A. Yes, checksums are optional.

Time Delayed Replication

Q. Is Time delayed replication applied at the database level only and not for the entire slave?

A. Applied for the slave as execution is global.

Informational Log Events

Q. When we configure information log event, does it show meaningful query log for any binlog format? (Row based especially)

A. When using row based replication, you get the original query in human readable format... obviously you don’t want to see all the rows modified in a table of size, which can be huge

Q. Will the binlog include user id?

A. User id is replicated in some cases for Query-log-event - namely user id of the invoker when a stored routine is called.

Remote Binlog Backup

Q. What level of access does the remote binlog backup need?

A. Replication slave

Summary

As you can see, our Engineering team was kept busy with questions over the course of the webinar. Be sure to check out the MySQL 5.6 Replication webinar replay and if you have further questions, please don’t hesitate to use the comments below!


PlanetMySQL Voting: Vote UP / Vote DOWN

Meet the MySQL Experts Podcast: MySQL Replication Global Transaction Identifiers & HA Utilities

Май 17th, 2012

In the latest episode of our “Meet The MySQL Experts” podcast, Luis Soares, Engineering Manager of MySQL Replication discusses the new Global Transaction Identifiers (GTIDs) that are part of the latest MySQL 5.6 Development Release. We are also joined by Chuck Bell who discusses how the new MySQL HA utilities use GTIDs to create a self-healing replication topology.

In the podcast, we cover how GTIDs and the HA utilities are implemented, how they are configured and considerations for their use.

You can also learn more from Luis’ blog on GTIDs in MySQL 5.6 and Chuck’s blog on the HA utilities.

Of course, GTIDs are just one of the major new features of MySQL replication. For a complete overview, take a look at our DevZone article: MySQL 5.6 Replication - Enabling the Next Generation of Web & Cloud Services.

You can try out MySQL 5.6 and GTIDs by downloading the Development Release (select Development Release tab)

Enjoy the GTID podcast and let us know what topics you would like covered in future podcasts!  Also check out the library of Meet the MySQL Experts podcasts


PlanetMySQL Voting: Vote UP / Vote DOWN

Upcoming webinar: MySQL 5.6 Replication – For Next Generation of Web and Cloud Services

Май 10th, 2012
MySQL 5.6 Replication - Global Transaction IDs

MySQL 5.6 Replication - Global Transaction IDs

On Wednesday (16th May 2012), Mat Keep and I will be presenting the new replication features that are previewed as part of the latest MySQL 5.6 Development Release. If you’d like to attend then register here.

MySQL 5.6 delivers new replication capabilities which we will discuss in the webinar:

  • High performance with Multi-Threaded Slaves and Optimized Row Based Replication
  • High availability with Global Transaction Identifiers, Failover Utilities and Crash Safe Slaves & Binlog
  • Data integrity with Replication Event Checksums
  • Dev/Ops agility with new Replication Utilities, Time Delayed Replication and more

The session will wrap up with resources to get started with MySQL 5.6 and an opportunity to ask questions.

The webinar will last 45-60 minutes and will start on Wednesday, May 16, 2012 at 09:00 Pacific time (America); start times in other time zones:

  • Wed, May 16: 06:00 Hawaii time
  • Wed, May 16: 10:00 Mountain time (America)
  • Wed, May 16: 11:00 Central time (America)
  • Wed, May 16: 12:00 Eastern time (America)
  • Wed, May 16: 16:00 UTC
  • Wed, May 16: 17:00 Western European time
  • Wed, May 16: 18:00 Central European time
  • Wed, May 16: 19:00 Eastern European time

As always, it’s worth registering even if you can’t make the live webcast as you’ll  be emailed a link to the replay as soon as it’s available.


PlanetMySQL Voting: Vote UP / Vote DOWN

Upcoming webinar: MySQL 5.6 Replication – For Next Generation of Web and Cloud Services

Май 10th, 2012
MySQL 5.6 Replication - Global Transaction IDs

MySQL 5.6 Replication - Global Transaction IDs

On Wednesday (16th May 2012), Mat Keep and I will be presenting the new replication features that are previewed as part of the latest MySQL 5.6 Development Release. If you’d like to attend then register here.

MySQL 5.6 delivers new replication capabilities which we will discuss in the webinar:

  • High performance with Multi-Threaded Slaves and Optimized Row Based Replication
  • High availability with Global Transaction Identifiers, Failover Utilities and Crash Safe Slaves & Binlog
  • Data integrity with Replication Event Checksums
  • Dev/Ops agility with new Replication Utilities, Time Delayed Replication and more

The session will wrap up with resources to get started with MySQL 5.6 and an opportunity to ask questions.

The webinar will last 45-60 minutes and will start on Wednesday, May 16, 2012 at 09:00 Pacific time (America); start times in other time zones:

  • Wed, May 16: 06:00 Hawaii time
  • Wed, May 16: 10:00 Mountain time (America)
  • Wed, May 16: 11:00 Central time (America)
  • Wed, May 16: 12:00 Eastern time (America)
  • Wed, May 16: 16:00 UTC
  • Wed, May 16: 17:00 Western European time
  • Wed, May 16: 18:00 Central European time
  • Wed, May 16: 19:00 Eastern European time

As always, it’s worth registering even if you can’t make the live webcast as you’ll  be emailed a link to the replay as soon as it’s available.


PlanetMySQL Voting: Vote UP / Vote DOWN

The Full Monty – Version 2

Февраль 15th, 2012

Installing MySQL on CentOS 6.2 with PaceMaker, MHA and more

When I work with High Availability software, I’m reminded of the maze in the original computer adventure game “You are Lost in a maze of twisty-turny passages all alike…”.

If you search the web for HA programs you will find many well maintained projects all related that refer each other. The goal of this document is to give you with a step by step guide to a production worthy MySQL system. It should provide at least 99.999% access to your data and be able to scale read requests as you grow.

I have chosen these programs and utilities because they are free (as in beer) and each has enterprise support available. (When you make the money to pay for it.) If you start with this MySQL platform you will avoid many common problems. Just write your application to read and write data from different servers.

Here is what we’ll be using:

If you want to see all this work check out my Youtube Video at : http://tinyurl.com/7yqj5gz

I’ve worked hard to make these instructions cut and past. The GREEN stuff gets cut and pasted into the linux command line. The BLUE is copied into an application (vi, crm etc), but the RED needs to be edited to fit your environment (passwords, IP). I enjoyed the work. I hope you do to.

Getting started

Every good system starts with good hardware. Two things database servers hunger for are disk space and memory. You should supply yours with as much of each as you can afford. My rule of thumb is three times size of one copy of the data. A production system with a RAID-10 disk system is good and two network ports or more is recommended.

To test this installation I’m building on a VMware server. If you’d like to know more about my hardware read my “Building a Home VMware server” story.

The Hardware

The operating system I’m using is CentOS 6.2 64 bit. Don’t use the 32bit versions.

How you define disk space is important part. Choose the type, size and partitions carefully. You don’t want daily activity filling the root file system (/) and taking down the database. The common places this can happen are, the MySQL data directory, the /tmp directory and log space. Keep these in separate partitions. I’ve found the OS system logs in /var/log take care of them selves. MySQL logs should be keep in the MySQL /data directory.

I’m test hardware (VMware ESXi 4) has four SAS hard disks. For each MySQL server (db1 and db2) I create four (4) 15Gig virtual hard disks, one on each physical SAS disk. I split each virtual disk into four partitions. The /boot partition is RAID-1 and the / (root), /data and /tmp partitions are RAID-5. The sizes of these partitions depend you your needs but your /boot needs to be about 1G and the / needs to be at least 12G.

This table show my for virtual disk and how they are raid-ed and partitioned.

Md0 – /boot

Md1 – /

Md2 – /tmp

Md3 – /data

Disk 0 – 15G

256M

4G

512M

11G

Disk 1 – 15G

256M

4G

512M

11G

Disk 2 – 15G

256M

4G

512M

11G

Disk 3 – 15G

256M

Checksum

512M

Checksum

Total

1G

12G

2G

33G

I created a KickStart for this install to make is simpler. http://www.mysqlfanboy.com/mysql.ks

I left the /data parition out of the kickstart because of a bug.  I then build it my hand with this command.

mdadm -Cv /dev/md3 -l5 -n4 /dev/sda6 /dev/sdb6 /dev/sdc6 /dev/sdd6

Install the OS

Start with a minimum installation so you’ll have as few applications installed as possible. No desktop or server applications are needed.

After the install you should update the installed packages and include any packages you know you will be wanting or needed.

 yum -y update
 yum -y install openssh-clients rsync wget perl-DBI perl-TermReadKey

Remove any supplied MySQL.

Even with a minimum install there is a little clean up. I remove packages that are un-needed.  For better security you should remove  anything that connect to remote systems like bluetooth and printing.

 rpm -e mysql
 rpm -e mysql-libs --nodeps

Security

For the install process I turn off the firewall. In secure environments I recommend you leave it in place and deal with restrictions as they come up.

 service iptables stop
 chkconfig iptables off
 service ip6tables stop
 chkconfig ip6tables off

Because we are moving the MySQL data directory, you will need to disable SELinux or update it. To disable it, edit /etc/selinux/config and change the SELINUX line to SELINUX=disabled. Then, so you don’t have to reboot Linux for this to take effect, just write a 0 to the SELinux control file.

 vi /etc/selinux/config

SELINUX=disabled

 echo 0 >/selinux/enforce

If you don’t want to disable To update SELinux for the new data directory you will need to have the the SELinux tools installed.

 yum -y install policycoreutils-python
 semanage fcontext -a -t mysqld_db_t "/data/mysql(/.*)?"
 restorecon -Rv /data/mysql

Syncing Time

Time sync is very important to maintaining accurate data. You may want to edit the /etc/ntp.conf file to point to your primary NTP time server. CentOS and Redhat provide time servers for your use. I recommend using pool.ntp.org.

 yum -y install ntp
 chkconfig ntpd on
 ntpdate 0.pool.ntp.org
 service ntpd start

Setup SSH

Now is a good time to make sure DNS works on all servers and each knows their names.

MHA need ssh access to each server. You need to create ssh keys and copy to the mysql servers.

Skip this if you already have ssh keys installed.

 ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ""
 cp ~/.ssh/id_dsa.pub ~/.ssh/authorized_keys
 scp -r ~/.ssh db2:.

Network configuration

You can edit all the network setting with the network system configuration utility.

 system-config-network

Except you need to insure the hosts can ALWAY resolve each other.

 vi /etc/hosts

192.168.2.160 db.grennan.com db
192.168.2.161 db1.grennan.com db1
192.168.2.162 db2.grennan.com db2
192.168.2.163 db3.grennan.com db3

 scp /etc/hosts db2:/etc

Now is a good time to reboot each system and check the install.

 init 6

MySQL Setup

Install the MySQL of your choise. I’m installing Percona’s version 5.5.

 rpm -e mysql-libs-5.1.52 --nodeps
 rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
 yum -y install Percona-Server-shared-compat
 yum -y install percona-toolkit
 yum -y install Percona-Server-server-55.x86_64
 yum -y install Percona-Server-client-55

The default location for MySQL data is /var/lib/mysql. MySQL benefits from being in it’s own partition. I’ll be putting the MySQL data in /data/mysql.

 service mysql stop
 mkdir /data
 mkdir /data/mysql
 cp -prv /var/lib/mysql/* /data/mysql
 mv /var/lib/mysql /var/lib/mysql-empty
 ln -s /data/mysql /var/lib/mysql
 chown -R mysql.mysql /data/mysql

Configure MySQL

You need to change the server-id number on each server. The minimum setting you will need are:

 vi /etc/my.cnf

[mysqld]
log-bin=mysql-bin
server-id=1 # Each system needs a unique id number
innodb_flush_log_at_trx_commit=2
sync_binlog=1
# relay_log_purge=0 # uncomment on slaves
# read_only=1 # uncomment on slaves

Percona has a service to help you configure MySQL for your hardware.   MySQL Configuration Wizard

Now we need to add a couple of user before we install the replicator. We also need to set a password for the root user. The root password is blank so just it return.

If you have skip-name-resolve set you will need to substitute the host names for IP addresses.

 service mysql start
 mysql -h localhost -u root -p

The next set of command are entered into the mysql client. You should have a ‘mysql >’ prompt.

 DROP USER ``@`localhost`;
 DROP USER ``@`db1.grennan.com` ;
 GRANT ALL on *.* TO `root`@`192.168.2.%` IDENTIFIED by `P@ssw0rd` with GRANT option;
 GRANT ALL on *.* TO `root`@`localhost` IDENTIFIED by `P@ssw0rd` with GRANT option;
 CREATE USER `repl`@`192.168.2.%` IDENTIFIED BY `RepP@ssw0rd`;
 GRANT REPLICATION SLAVE ON *.* TO `repl`@`192.168.2.%`;
 grant all on *.* to `hauser`@`db1.grennan.com` identified by `P@ssw0rd`;
 grant all on *.* to `hauser`@`db2.grennan.com` identified by `P@ssw0rd`;
 flush privileges;
 quit ;

Now, stop MySQL on all servers and copy all the MySQL data files to the slaves.

From the master (db1) at a system prompt ‘#’ :

 service mysql stop
 ssh db2 `service mysql stop`
 rsync -rog --delete /data/mysql root@db2:/data

Rather than type the password for MySQL each type we connect. We can also setup a usr .my.cnf to prevent this. This should connect you to the master (RW) server from each host.

 vi ~/.my.cnf

[Client]
user=root
password=P@ssw0rd
host=localhost
socket=/data/mysql/mysql.sock

 scp .my.cnf db2:.

Start Replication

On each system start MySQL and connect the two slaves to the master.

On the master we need to now the bin-file and the position. Note the numbers in purple.

 service mysql start
 mysql -e `reset master; reset slave;`
 mysql -e `show master status\G`

*************************** 1. row ***************************
File: mysql-bin.000001
Position: 107
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)

On all slaves, use the master’s bin log position to setup replication. Start the slave and note that the IO and SQL are running. (Yes).
service mysql start

 mysql
 stop slave;
 CHANGE MASTER TO MASTER_HOST='192.168.2.201', MASTER_USER='repl',
 MASTER_PASSWORD='RepP@ssw0rd', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107 ;
 start slave ;
 show slave status\G

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

Installing MHA

Every MySQL server needs to have a copy of the MHA Node and Manager installed. Download the latest version of MHA from the Google Code server.

http://code.google.com/p/mysql-master-ha/downloads/list

There are a number of required Perl modules. I chose to use the Fedora evaluation packages to resolve these.

  • DBD::mysql
  • Config::Tiny
  • Log::Dispatch
  • Parallel::ForkManager
  • Time::HiRes

Here is my install with the fedora packages.

 wget http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm
 rpm -i epel-release-6-5.noarch.rpm
 yum -y install perl-DBD-MySQL
 yum -y install perl-Config-Tiny
 yum -y install perl-Log-Dispatch
 yum -y install perl-Parallel-ForkManager
 yum -y install perl-Time-HiRes
 wget http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.53-0.el6.noarch.rpm
 rpm -i mha4mysql-node-0.53-0.el6.noarch.rpm
 wget http://mysql-master-ha.googlecode.com/files/mha4mysql-manager-0.53-0.el6.noarch.rpm
 rpm -i mha4mysql-manager-0.53-0.noarch.rpm

MHA only need one configuration file on each server. You can name this file anything you want. Change the setting and make sure the directories exist and are writable.

 vi /etc/MHA.cnf

Insert this configuration data into the MHA.cnf file.

[server default]
user=root
password=P@ssw0rd
manager_workdir=/var/log/masterha
manager_log=/var/log/masterha/MHA.log
remote_workdir=/var/log/masterha

[server1]
hostname=db1

[server2]
hostname=db2

You should have already installed SSH keys (see above) and the ‘hauser’ installed in MySQL.

masterha_check_ssh is used to check if you have SSH working. Look for the OK after the connect test.

 masterha_check_ssh --conf=/etc/MHA.cnf

Thu Dec 1 10:10:52 2011 – [info] Starting SSH connection tests..
Thu Dec 1 10:10:53 2011 – [debug]
Thu Dec 1 10:10:52 2011 – [debug] Connecting via SSH from root@db1(192.168.0.11) to root@db2(192.168.2.12)..
Thu Dec 1 10:10:53 2011 – [debug] ok.

masterha_check_repl is used to check MySQL replicaton. This is chatty. Your are looking for the ‘MySQL Replication Health is OK’ at the end. You should pay attention to any warnings.

 masterha_check_repl --conf=/etc/MHA.cnf


Thu Dec 1 10:07:22 2011 – [info] Checking slave configurations..
Thu Dec 1 10:07:22 2011 – [warning] read_only=1 is not set on slave db2(192.168.0.11:3306).
Thu Dec 1 10:07:22 2011 – [warning] relay_log_purge=0 is not set on slave db2(192.168.0.12:3306).

MySQL Replication Health is OK.

 

You now have MHA installed. If the configure it wrong MHA will give some errors that are not helpful and die. check the system logs (/var/log/messages) and your MHA settings and try again.

We’ll be using Pacemaker and a command like this to fail over to a slave when the master dies.

masterha_master_switch –master_state=dead –dead_master_host=db1 –conf=/etc/MHA.cnf

Putting the H in High Availability (HA)

There are may ways a system can fail and even with MySQL running. How do you know when your dead? How do you make the new is system ready to accept data? Are your servers even on the same network? I’ve chosen PaceMaker because it is the most complete and flexible.

Install Pacemaker / CoroSync

Neither RedHat or CentOS supply PaceMaker packeges. RedHat support their own propitiatory clustering suite. CentOS does supply heartbeat. Thankfully PaceMaker project provide it in EPEL repository for Redhat 5.

Note we are installing PaceMaker for RedHat 5 not 6.2. At the time of this writing a version for 6.2 was not available. This create some dependence problems we have to work around.

 wget -O /etc/yum.repos.d/pacemaker.repo http://clusterlabs.org/rpm/epel-5/clusterlabs.repo
 yum -y install libtool-ltdl
 ln -s /usr/lib64/libltdl.so.7.2.1 /usr/lib64/libltdl.so.3
 yum -y install net-snmp
 wget http://www.clusterlabs.org/rpm/epel-5/x86_64/cluster-glue-1.0.6-1.6.el5.x86_64.rpm
 wget http://www.clusterlabs.org/rpm/epel-5/x86_64/cluster-glue-libs-1.0.6-1.6.el5.x86_64.rpm
 rpm -i cluster-glue-1.0.6-1.6.el5.x86_64.rpm --nodeps
 rpm -i cluster-glue-libs-1.0.6-1.6.el5.x86_64.rpm --nodeps
 yum -y install pacemaker corosync heartbeat

Again, make sure all the name resolves are in place on both DB1 and DB2. Heartbeat and Pacemaker provide the group communications and process management respectivly. The nodes must be able to communicate with each other.

Configure CoroSync

On both DB1 and DB2.

 corosync-keygen
 chown root:root /etc/corosync/authkey
 chmod 400 /etc/corosync/authkey
 vi /etc/corosync/corosync.conf

totem {
    version: 2
    token: 5000 # How long before declaring a token lost (ms)
    token_retransmits_before_loss_const: 20 # How many token retransmits
    # before forming a new configuration
    join: 1000 # How long to wait for join messages in the membership protocol (ms)
    consensus: 7500 # How long to wait for consensus to be achieved before
    # starting a new round of membership configuration (ms)
    vsftype: none # Turn off the virtual synchrony filter
    max_messages: 20 # Number of messages that may be sent by
    #one processor on receipt of the token
    secauth: off # Disable encryption
    threads: 0 # How many threads to use for encryption/decryption
    clear_node_high_bit: yes # Limit generated nodeids to 31-bits (positive signed integers)
    # Optionally assign a fixed node id (integer)
    # nodeid: 1234
    interface {
        ringnumber: 0
        # The following three values need to be set based on your environment
        bindnetaddr: 192.168.2.201
        mcastaddr: 239.255.42.0
        mcastport: 5405
        }
}
logging {
    fileline: off
    to_syslog: yes
    to_stderr: no
    syslog_facility: daemon
    debug: on
    timestamp: on
}
amf {
    mode: disabled
}

 vi /etc/corosync/service.d/pcmk

service {
    # Load the Pacemaker Cluster Resource Manager
    name: pacemaker
    ver: 0
}

If you didn’t edit this on both servers copy it from second server.

 rsync -rop /etc/corosync db2:/etc

Now start corosync on both servers.

 chkconfig corosync on
 /etc/init.d/corosync start

Check CoroSync healty. Look for ‘no faluts’ and both members show up as members.

 corosync-cfgtool -s

Printing ring status.
Local node ID -922572608
RING ID 0
id = 192.168.2.201
status = ring 0 active with no faults

 corosync-objctl | grep members

totem.join=1000 # How long to wait for join messages in the membership protocol (ms)
runtime.totem.pg.mrp.srp.members.-922572608.ip=r(0) ip(192.168.2.201)
runtime.totem.pg.mrp.srp.members.-922572608.join_count=1
runtime.totem.pg.mrp.srp.members.-922572608.status=joined
runtime.totem.pg.mrp.srp.members.-905795392.ip=r(0) ip(192.168.2.202)
runtime.totem.pg.mrp.srp.members.-905795392.join_count=1
runtime.totem.pg.mrp.srp.members.-905795392.status=joined

Patch for Pacemaker

Yves Trudeau had created a newer version of the mysql resource agent for Pacemaker. He keeps it at:
https://github.com/y-trudeau/. Just download it and copy it into the ocf resource heartbeat directory.

 wget https://raw.github.com/y-trudeau/resource-agents/master/heartbeat/mysql
 cp mysql /usr/lib/ocf/resource.d/heartbeat/mysql

Configure Pacemaker

Fencing is normally used and is enabled by default and should be! We’ll start my turning Shoot the other Node in the Head (stonith) off. TURN THIS BACK ON BEFORE YOU GO INTO PRODUCTION! You disable it with:

 crm configure property stonith-enabled="false"

If your cluster consists of just two nodes, switch the quorum feature off with:

 crm configure property no-quorum-policy=ignore

This is a bit of magic. I’ll explain after we’re done. Create file to configure crm and paste this document into it.

 crm configure node db2.grennan.com attributes IP="192.168.2.202"
 crm configure

Now your in the CRM configuration utility. Type in the blue part of this txt and edit the red parts to fit your configuration.

crm(live)configure# primitive failover-ip ocf:heartbeat:IPaddr \
 params ip="192.168.2.200" \
 operations $id="failover-ip-operations" \
 op monitor start-delay="0" interval="2"
crm(live)configure# primitive p_mysql ocf:heartbeat:mysql \
 params pid="/var/run/mysqld/mysqld.pid" socket="/data/mysql/mysql.sock" \
 test_passwd="P@ssw0rd" enable_creation="false" replication_user="root" \
 replication_passwd="P@ssw0rd" MHASupport="true" \
 operations $id="p_mysql-operations" \
 op monitor interval="20" timeout="30" depth="0" \
 op monitor interval="10" role="Master" timeout="30" depth="0" \
 op monitor interval="30" role="Slave" timeout="30" depth="0"
crm(live)configure# ms ms_mysql p_mysql meta clone-max="2" notify="true"
crm(live)configure# colocation col_ms_mysql_failover-ip inf: failover-ip ms_mysql:Master
crm(live)configure# order ord_ms_mysql_failover-ip inf: ms_mysql:promote failover-ip:start
crm(live)configure# commit
crm(live)configure# quit

 

Monitor Pacemaker

Back at the system prompt you can monitor the health of Pacemaker from the command line.

 crm_mon -Arf

============
Last updated: Fri Feb 10 14:28:53 2012
Last change: Fri Feb 10 14:26:15 2012 via crm_attribute on db1.grennan.com
Stack: openais
Current DC: db1.grennan.com – partition with quorum
Version: 1.1.6-3.el6-a02c0f19a00c1eb2527ad38f146ebc0834814558
2 Nodes configured, 2 expected votes
3 Resources configured.
============

Online: [ db1.grennan.com db2.grennan.com ]

Full list of resources:

failover-ip (ocf::heartbeat:IPaddr): Started db1.grennan.com
Master/Slave Set: ms_mysql [p_mysql]
Masters: [ db1.grennan.com ]
Slaves: [ db2.grennan.com ]

Node Attributes:
* Node db1.grennan.com:
+ IP : 192.168.2.201
+ master-p_mysql:0 : 3601
+ readerOK : 1
+ writerOK : 1
* Node db2.grennan.com:
+ IP : 192.168.2.202
+ master-p_mysql:1 : 1
+ readerOK : 0
+ writerOK : 0

Migration summary:

* Node db1.grennan.com:
* Node db2.grennan.com:

Install DRBD Management Console

The DRBD Management Console is a Java application that eases the burden of managing your DRBD and Pacemaker/Corosync or Heartbeat based cluster systems.

Download this Jar file to your workstation.

When you run it you will need to add the server logins and cluster set. You don’t need to edit anything. Skip any installations or configurations.

http://sourceforge.net/projects/lcmc/files/LCMC-1.2.3.jar/download

[I'll post a video of configuring the Management Console here.]

 

But wait there is MORE

Percona Tool kit

You install the Perconal Tool kit when you installed MySQL. :-) Percona Toolkit is a collection of advanced command-line tools used by Percona (http://www.percona.com/) support staff to perform a variety of MySQL and system tasks that are too difficult or complex to perform manually. As a DBA you will find them very useful. Here is a small sample:

  • pt-duplicate-key-checker – Find duplicate indexes and foreign keys on MySQL tables.
  • pt-heartbeat – Monitor MySQL replication delay.
  • pt-index-usage – Read queries from a log and analyze how they use indexes.
  • pt-query-advisor – Analyze queries and advise on possible problems.
  • pt-query-digest – Analyze query execution logs and generate a query report, filter, replay, or transform queries for MySQL, PostgreSQL, memcached, and more.
  • pt-query-profiler – Execute SQL statements and print statistics, or measure activity caused by other processes.
  • pt-show-grants – Print MySQL grants so you can effectively replicate, compare and version-control them.
  • pt-table-checksum – Perform an online replication consistency check, or checksum MySQL tables efficiently on one or many servers.
  • pt-table-sync – Synchronize MySQL table data efficiently.
  • pt-visual-explain – Format EXPLAIN output as a tree.

openark kit

Shlomi Noach maintains another great set of utility.

  • oak-apply-ri: apply referential integrity on two columns with parent-child relationship.
  • oak-block-account: block or release MySQL users accounts, disabling them or enabling them to login.
  • oak-chunk-update: perform long, non-blocking UPDATE/DELETE operation in auto managed small chunks.
  • oak-get-slave-lag: print slave replication lag and terminate with respective exit code.
  • oak-hook-general-log: hook up and filter general log entries based on entry type or execution plan criteria.
  • oak-kill-slow-queries: terminate long running queries.
  • oak-modify-charset: change the character set (and collation) of a textual column.
  • oak-online-alter-table: perform a non-blocking ALTER TABLE operation.
  • oak-prepare-shutdown: make for a fast and safe MySQL shutdown.
  • oak-purge-master-logs: purge master logs, depending on the state of replicating slaves.
  • oak-repeat-query: repeat query execution until some condition holds.
  • oak-security-audit: audit accounts, passwords, privileges and other security settings.
  • oak-show-limits: show AUTO_INCREMENT “free space”.
  • oak-show-replication-status: show how far behind are replicating slaves on a given master.

You can find them here. http://code.openark.org/forge/openark-kit

MyTOP

Mytop is a console-based (non-gui) tool for monitoring the threads and overall performance of MySQL. The original development was done by Jeremy D. Zawodny <Jeremy@Zawodny.com> and is well know after being published in the book, High Performance MySQL. I’ve updated it with as a tool for monitoring MyISAM and replication.

I would be amiss if I didn’t say something about innotop. Some consider this a predecessors to mytop. It is of you are using InnoDB. I still find mytop useful. More than half of my tables are MyISAM.

 wget http://www.mysqlfanboy.com/mytop/mytop-1.9.tar.gz
 tar zxf mytop-1.9.tar.gz
 cd mytop-1.9
 perl Makefile.PL
 make install
 wget https://innotop.googlecode.com/files/innotop-1.8.0.tar.gz
 cd innotop-1.8.0
 perl Makefile.PL
 make install

Backup

Percona XtraBackup is a hot backup utility that doesn’t lock your database during the backup!

It’s best to run this from one of your slaves. I often create a local copy and then rsync the files off the backup system to a remote (off site) server using a cron script.

 yum -y install xtrabackup
 innobackupex --user=root --password=`P@ssw0rd` /tmp/Backup

Here is an example script.

export HOST=`/bin/hostname -a`
mkdir /root/Backup
/usr/bin/innobackupex –user=root –password=`P@ssword` /root/Backup
/usr/bin/xtrabackup –prepare –target-dir=/tmp/backup
/bin/find /tmp/Backup/* -mtime +1 -exec rm {} -Rf \;

Last word

If you’ve made it this fare, now is a good time to restart everything and do some testing.

 init 6

 

Tweet


PlanetMySQL Voting: Vote UP / Vote DOWN

MySQL Cluster training Jan 24 — 26 in DC

Январь 13th, 2012

We still have a few seats left for our MySQL Cluster training in Washington DC January 24 - 26. If you're interested in learning about MySQL Cluster, the architecture, how to install it, administer it and troubleshoot it this is the course for you. The course will also cover replication and optimization and we will also discuss the exciting new features coming in version 7.2 of MySQL Cluster. For more information about the course contents visit http://www.skysql.com/services/training/courses/administering-mysql-cluster and to sign up to the course go to http://www.skysql.com/services/training/schedule/administering-mysql-cluster-1.

See you there!

 


PlanetMySQL Voting: Vote UP / Vote DOWN

What’s new in MySQL 5.6 Replication – free webinar

Декабрь 12th, 2011

Global Transaction IDs - simplifying replication management

There will be a webinar this Wednesday where you can get the latest information on all of the great new content that has been included in the MySQL 5.6 Development Releases as well as some features that are still being developed. As always, the webinar is free but you need to register here in advance. Even if you can’t attend the live event it’s worth registering so that you get sent the replay.

Some of the topics we’ll be discussing are:

  • Enhanced data integrity: Global Transactions Identifiers, Crash-Safe Slaves and Replication Event Checksums;
  • High performance: Multi-Threaded Slaves, Binlog Group Commit and Optimized Row-Based Replication;
  • Improved flexibility: Time Delayed Replication, Multi-Source Replication, Binlog API and Informational Log Events
The event starts on Wednesday, December 14, 2011: 09:00 Pacific time; 17:00 UK; 18:00 CET.

PlanetMySQL Voting: Vote UP / Vote DOWN

MySQL HA Solutions – webinar replay

Декабрь 7th, 2011

If you were unable to attend the live webinar (or you want to go back and listen to it again) then it’s now available to view on-line here.

Databases are the center of today’s web and enterprise applications, storing and protecting an organization’s most valuable assets and supporting business-critical applications. Just minutes of downtime can result in significant lost revenue and dissatisfied customers. Ensuring database highly availability is therefore a top priority for any organization. Tune into this webcast to learn more.

The session discusses:

  1. Causes, effect and impact of downtime
  2. Methodologies to map applications to HA solution
  3. Overview of MySQL HA solutions
  4. Operational best practices to ensure business continuity

PlanetMySQL Voting: Vote UP / Vote DOWN

Replication stars

Ноябрь 4th, 2011
Working with replication, you come across many topologies, some of them sound and established, some of them less so, and some of them still in the realm of the hopeless wishes. I have been working with replication for almost 10 years now, and my wish list grew quite big during this time. In the last 12 months, though, while working at Continuent, some of the topologies that I wanted to work with have moved from the cloud of wishful thinking to the firm land of things that happen. My quest for star replication starts with the most common topology. One master, many slaves.
Replication 1 master slave

Fig 1. Master/Slave topology

Replication legend

Legend

It looks like a star, with the rays extending from the master to the slaves. This is the basis of most of the replication going on mostly everywhere nowadays, and it has few surprises. Setting aside the problems related to failing over and switching between nodes, which I will examine in another post, let's move to another star.
Replication 2 fan in slave

Fig 2. Fan-in slave, or multiple sources

The multiple source replication, also known as fan-in topology, has several masters that replicate to the same slave. For years, this has been forbidden territory for me. But Tungsten Replicator allows you to create multiple source topologies easily. This is kind of uni-directional, though. I am also interested in topologies where I have more than one master, and I can retrieve data from multiple points.
Replication 3 all to all three nodes

Fig 3. all-to-all three nodes

Replication 4 all to all four nodes

Fig 4. All-to-all four nodes

Tungsten Multi-Master Installation solves this problem. It allows me to create topologies where every node replicates to every other node. Looking at the three-node scheme, it appears a straightforward solution. When we add one node, though, we see that the amount of network traffic grows quite a lot. The double sided arrows mean that there is a replication service at each end of the line, and two open data channels. When we move from three nodes to four, we double the replication services and the channels needed to sustain the scheme. For several months, I was content with this. I thought: it is heavy, but it works, and it's way more than what you can do with native replication, especially if you consider that you can have a practical way of preventing conflicts using Shard Filters. But that was not enough. Something kept gnawing at me, and from time to time I experimented with Tungsten Replicator huge flexibility to create new topologies. But the star kept eluding me. Until … Until, guess what? a customer asked for it. The problem suddenly ceased to be a personal whim, and it became a business opportunity. Instead of looking at the issue in the idle way I often think about technology, I went at it with practical determination. What failed when I was experimenting in my free time was that either the pieces did not glue together the way I wanted, or I got an endless loop. Tungsten Replicator has a set of components that are conceptually simple. You deploy a pipeline between two points, open the tap, and data starts flowing in one direction. Even with multiple masters replication, the principle is the same. You deploy many pipes, and each one has one purpose only.
Replication 5 star topology 3 rays

Fig 5. All-masters star topology

In the star topology, however, you need to open more taps, but not too many, as you need to avoid the data looping around. The recipe, as it turned out, is to create a set of bi-directional replication systems, where you enable the central node slave services to get changes only from a specific master, and the slave services on the peripheral nodes to accept changes from any master. It was as simple as that. There are, of course, benefits and drawbacks with a star topology, compared to a all-replicate-to-all design. In the star topology, we create a single point of failure. If the central node fails, replication stops, and the central node needs to be replaced. Instead, the all-to-all design has no weaknesses. Its abundance of connections makes sure that, if a node fails, the system continues working without any intervention. There is no need for fail-over.
Replication 6 all to all extending png

Fig 6. extending an all-to-all topology

Replication 7 star extending

Fig 7. Extending a star topology

However, there is a huge benefit in the node management. If you need to add a new node, it costs two services and two connections, while the same operation in the all-to-all replication costs 8 services and 8 connections. With the implementation of this topology, a new challenge has arisen. While conflict prevention by sharding is still possible, this is not the kind of scenario where you want to apply it. We have another conflict prevention mechanism in mind, and this new topology is a good occasion make it happen. YMMV. I like the additional choice. There are cases where a all-replicate-to-all topology is still the best option, and there are cases where a star topology is more advisable.

PlanetMySQL Voting: Vote UP / Vote DOWN

MySQL Cluster 7.2 (DMR2): NoSQL, Key/Value, Memcached

Октябрь 7th, 2011

70x Higher Performance, Cross Data Center Scalability and New NoSQL Interface

Its been an exciting week for all involved with MySQL Cluster, with the announcement of the second Development Milestone Release (7.2.1) at Oracle Open World. Highlights include:

- Enabling next generation web services: 70x higher complex query performance, native memcached API and integration with the latest MySQL 5.5 server

- Enhancing cross data scalability: new multi-site clustering and enhanced active/active replication

- Simplified provisioning: consolidated user privileges.

You can download the DMR for evaluation now from: http://dev.mysql.com/downloads/cluster/ (select Development Milestone Release tab).

You can also read up on the detail of each of these features in the new article posted at the MySQL Developer Zone. In this blog, I’ll summarize the main parts of the announcement.

70x Higher Performance with Adaptive Query Localization (AQL)

Previewed as part of the first MySQL Cluster DMR, AQL is enabled by a new Index Statistics function that allows the SQL optimizer to build a better execution plan for each query.

As a result, JOIN operations are pushed down to the data nodes where the query executes in parallel on local copies of the data. A merged result set is then sent back to the MySQL Server, significantly enhancing performance by reducing network trips.

Take a look at how this is used by a web-based content management to increase performance by 70x

Adaptive Query Localization enables MySQL Cluster to better serve those use-cases that have the need to run real-time analytics across live data sets, along with high throughput OLTP operations. Examples include recommendations engines and clickstream analysis in web applications, pre-pay billing promotions in mobile telecoms networks or fraud detection in payment systems.

New NoSQL Interface and Schema-less Storage with the memcached API

The memcached interface released as an Early Access project with the first MySQL Cluster DMR is now integrated directly into the MySQL Cluster 7.2.1 trunk, enabling simpler evaluation.

The popularity of Key/Value stores has increased dramatically. With MySQL Cluster and the new memcached API, you have all the benefits of an ACID RDBMS, combined with the performance capabilities of Key/Value store.

By default, every Key / Value is written to the same table with each Key / Value pair stored in a single row – thus allowing schema-less data storage. Alternatively, the developer can define a key-prefix so that each value is linked to a pre-defined column in a specific table.

Of course if the application needs to access the same data through SQL then developers can map key prefixes to existing table columns, enabling Memcached access to schema-structured data already stored in MySQL Cluster.

You can read more about the design goals and implementation of the memcached API for MySQL Cluster here.

Integration with MySQL 5.5

MySQL Cluster 7.2.1 is integrated with MySQL Server 5.5, providing binary compatibility to existing MySQL Server deployments. Users can now fully exploit the latest capabilities of both the InnoDB and MySQL Cluster storage engines within a single application.

Users simply install the new MySQL Cluster binary including the MySQL 5.5 release, restart the server and immediate have access to both InnoDB and MySQL Cluster!

Enhancing Cross Data Center Scalability: Simplified Active / Active Replication

MySQL Cluster has long offered Geographic Replication, distributing clusters to remote data centers to reduce the affects of geographic latency by pushing data closer to the user, as well as providing a capability for disaster recovery.

Geographic replication has always been designed around an Active / Active technology, so if applications are attempting to update the same row on different clusters at the same time, the conflict can be detected and resolved. With the release of MySQL Cluster 7.2.1, implementing Active / Active replication has become a whole lot simpler. Developers no longer need to implement and manage timestamp columns within their applications. Also rollbacks can be made to whole transactions rather than just individual operations.

You can learn more here.

Enhancing Cross Data Center Scalability: Multi-Site Clustering

MySQL Cluster 7.2.1 DMR provides a new option for cross data center scalability – multi-site clustering. For the first time splitting data nodes across data centers is a supported deployment option.

Improvements to MySQL Cluster’s heartbeating mechanism with a new “ConnectivityCheckPeriod” parameter enables greater resilience to temporary latency spikes on a WAN, thereby maintaining operation of the cluster.

With this deployment model, users can synchronously replicate updates between data centers without needing conflict detection and resolution, and automatically failover between those sites in the event of a node failure.

Users need to characterize their network bandwidth and latencies, and observe best practices in configuring both their network environment and Cluster. More guidance is available here.

User Privilege Consolidation

User privilege tables are now consolidated into the data nodes and centrally accessible by all MySQL servers accessing the cluster.

Previously the privilege tables were local to each MySQL server, meaning users and their associated privileges had to be managed separately on each server. By consolidating privilege data, users need only be defined once and managed centrally, saving Systems Administrators significant effort and reducing cost of operations.

Summary

The MySQL Cluster 7.2.1 DMR enables new classes of use-cases to benefit from web-scale performance with carrier-grade availability.

You can download the DMR for evaluation now from: http://dev.mysql.com/downloads/cluster/ (select Development Milestone Release tab).

You can learn more about the MySQL Cluster architecture from our Guide to scaling web databases

Let us know what you think of these enhancements directly in comments of this or the associated blogs. We look forward to working with the community to perfect these new features.


PlanetMySQL Voting: Vote UP / Vote DOWN