<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL Fanboy</title>
	<atom:link href="http://www.mysqlfanboy.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlfanboy.com</link>
	<description>Almost crazy about Opensource / Free  information.</description>
	<lastBuildDate>Mon, 16 Apr 2012 20:17:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Percona Tease Kit</title>
		<link>http://www.mysqlfanboy.com/2012/04/percona-tease-kit/</link>
		<comments>http://www.mysqlfanboy.com/2012/04/percona-tease-kit/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 20:17:40 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Commentary]]></category>
		<category><![CDATA[HOW TO]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=827</guid>
		<description><![CDATA[Percona you know I love you.  You have the largest brains working with MySQL. Your toolkit (formerly Maatkit and Aspersa) is a real gift to the MySQL community. But stop teasing us with webinars about what it can do and show us how to use it. The Percona ToolKit needs a cookbook. The documentation is [...]]]></description>
			<content:encoded><![CDATA[<div><strong></strong><strong>Percona you know I love you.  You have the largest brains working with MySQL. Your toolkit (formerly Maatkit and Aspersa) is a real gift to the MySQL community. But stop teasing us with webinars about what it can do and show us how to use it.</p>
<p>The Percona ToolKit needs a cookbook. The documentation is reference only, very thin and total void of useful examples. You’re beginning to frustrate the masses.</p>
<p>Here is what’s happening.  My MySQL server crashes or stalls ever few months.  I searched the Goog and find PT-Stalk :</p>
<p>“watches for a trigger condition to become true, and then collects data to help in diagnosing problems. It is designed to run as a daemon with root privileges, so that you can diagnose intermittent problems that you cannot observe directly. You can also use it to execute a custom command, or to gather the data on demand without waiting for the trigger to happen.”</p>
<p>I attend your webinar.  I even attend the Percona Live conference in San Francisco to talke with the developer in person and still I get little more then:</p>
<p></strong></p>
<p dir="ltr">pt-stalk [OPTIONS] [-- MYSQL OPTIONS]</p>
</div>
<div><strong id="internal-source-marker_0.3143007152248174"><br />
??!!</p>
<p>Anyone else feel the same?</p>
<p>I’m going to take a deep dive into the Percona ToolKit code and try to bring you some working examples (Cut and Paste).  I’m going to start with PT-STALK because it fills a need.  I’ll pick the next in the line of useful tools that need more documentation.</p>
<p>If you would like be to document a Percona tool you need, leave me a comment.</strong></div>
<div></div>
<div><img class="alignnone" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></div>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F2012%2F04%2Fpercona-tease-kit%2F&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=Percona Tease Kit - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/2012/04/percona-tease-kit/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>The Full Monty &#8211; Version 2</title>
		<link>http://www.mysqlfanboy.com/2012/02/the-full-monty-version-2-3/</link>
		<comments>http://www.mysqlfanboy.com/2012/02/the-full-monty-version-2-3/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 21:13:43 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Commentary]]></category>
		<category><![CDATA[DRDB]]></category>
		<category><![CDATA[HA]]></category>
		<category><![CDATA[Heartbeat]]></category>
		<category><![CDATA[HOW TO]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=794</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<h2>Installing MySQL on CentOS 6.2 with PaceMaker, MHA and more</h2>
<p>When I work with High Availability software, I’m reminded of the maze in the original computer adventure game<em> “You are Lost in a maze of twisty-turny passages all alike…”</em>.</p>
<p>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 <strong>99.999%</strong> access to your data and be able to scale read requests as you grow.</p>
<p>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.</p>
<p>Here is what we’ll be using:</p>
<ul>
<li><a href="http://centos.org/ ">CentOS </a>(Redhat) 6.2</li>
<li>MySQL 5.5.xx (<a href="http://www.percona.com">Percona</a>) or the MySQL of your choice</li>
<li><a href="http://www.clusterlabs.org/">Pacemaker </a>- to monitor MySQL’s health</li>
<li><a href="http://code.google.com/p/mysql-master-ha/ ">MySQL HA </a>(MHA) &#8211; to fail over when something happens to the master</li>
<li><a href="http://www.drbd.org/mc/management-console/ ">DRDB </a>Cluster Management Console</li>
<li><a href="http://www.drbd.org/mc/management-console/ ">Percona Toolkit</a> &#8211; to make live easy</li>
<li><a href="http://code.openark.org/forge/openark-kit">OpenArk Kit</a> &#8211; a set of utilities for MySQL</li>
<li><a href="http://www.percona.com/docs/wiki/percona-xtrabackup">xtrabackup </a>for database backups</li>
<li><a href="http://www.mysqlfanboy.com/mytop">mytop </a>and innotop &#8211; for real time monitoring</li>
</ul>
<p>If you want to see all this work check out my Youtube Video at : <a href="http://tinyurl.com/7yqj5gz">http://tinyurl.com/7yqj5gz</a></p>
<p>I&#8217;ve worked hard to make these instructions cut and past. The <strong><span style="color: #008000;">GREEN</span></strong> stuff gets cut and pasted into the linux command line. The <strong><span style="color: #0000ff;">BLUE</span></strong> is copied into an application (vi, crm etc), but the <strong><span style="color: #ff0000;">RED</span></strong> needs to be edited to fit your environment (passwords, IP). I enjoyed the work. I hope you do to.</p>
<h3><span id="more-794"></span></h3>
<h3>Getting started</h3>
<p>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.</p>
<p>To test this installation I&#8217;m building on a VMware server. If you&#8217;d like to know more about my hardware read my &#8220;<a href="http://www.grennan.com/?p=135">Building a Home VMware server</a>&#8221; story.</p>
<h3></h3>
<h3>The Hardware</h3>
<p>The operating system I&#8217;m using is<a href="http://isoredirect.centos.org/centos/6.2/isos/x86_64/ "> CentOS 6.2 64 bit</a>. Don’t use the 32bit versions.</p>
<p>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&#8217;ve found the OS system logs in /var/log take care of them selves. MySQL logs should be keep in the MySQL /data directory.</p>
<p>I&#8217;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.</p>
<p>This table show my for virtual disk and how they are raid-ed and partitioned.</p>
<div>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top"></td>
<td valign="top">
<p align="center"><strong>Md0 &#8211; /boot</strong></p>
</td>
<td valign="top">
<p align="center"><strong>Md1 &#8211; /</strong></p>
</td>
<td valign="top">
<p align="center"><strong>Md2 – /tmp</strong></p>
</td>
<td valign="top">
<p align="center"><strong>Md3 &#8211; /data</strong></p>
</td>
</tr>
<tr>
<td valign="top">
<p align="center"><strong>Disk 0 &#8211; 15G</strong></p>
</td>
<td valign="top">
<p align="center">256M</p>
</td>
<td valign="top">
<p align="center">4G</p>
</td>
<td valign="top">
<p align="center">512M</p>
</td>
<td valign="top">
<p align="center">11G</p>
</td>
</tr>
<tr>
<td valign="top">
<p align="center"><strong>Disk 1 &#8211; 15G</strong></p>
</td>
<td valign="top">
<p align="center">256M</p>
</td>
<td valign="top">
<p align="center">4G</p>
</td>
<td valign="top">
<p align="center">512M</p>
</td>
<td valign="top">
<p align="center">11G</p>
</td>
</tr>
<tr>
<td valign="top">
<p align="center"><strong>Disk 2 &#8211; 15G</strong></p>
</td>
<td valign="top">
<p align="center">256M</p>
</td>
<td valign="top">
<p align="center">4G</p>
</td>
<td valign="top">
<p align="center">512M</p>
</td>
<td valign="top">
<p align="center">11G</p>
</td>
</tr>
<tr>
<td valign="top">
<p align="center"><strong>Disk 3 &#8211; 15G</strong></p>
</td>
<td valign="top">
<p align="center">256M</p>
</td>
<td valign="top">
<p align="center">Checksum</p>
</td>
<td valign="top">
<p align="center">512M</p>
</td>
<td valign="top">
<p align="center">Checksum</p>
</td>
</tr>
<tr>
<td valign="top">
<p align="center"><strong>Total</strong></p>
</td>
<td valign="top">
<p align="center">1G</p>
</td>
<td valign="top">
<p align="center">12G</p>
</td>
<td valign="top">
<p align="center">2G</p>
</td>
<td valign="top">
<p align="center">33G</p>
</td>
</tr>
</tbody>
</table>
<p>I created a KickStart for this install to make is simpler.<a href=" http://www.mysqlfanboy.com/mysql.ks"> http://www.mysqlfanboy.com/mysql.ks </a></p>
<p>I left the /data parition out of the kickstart because of a bug.  I then build it my hand with this command.</p>
<p>mdadm -Cv /dev/md3 -l5 -n4 /dev/sda6 /dev/sdb6 /dev/sdc6 /dev/sdd6</p>
</div>
<h3></h3>
<h3>Install the OS</h3>
<p>Start with a <span style="text-decoration: underline;"><strong>minimum installation</strong></span> so you&#8217;ll have as few applications installed as possible. No desktop or server applications are needed.</p>
<p>After the install you should update the installed packages and include any packages you know you will be wanting or needed.</p>
<pre><strong><span style="color: #008000;"> yum -y update</span></strong>
<strong><span style="color: #008000;"> yum -y install openssh-clients rsync wget perl-DBI perl-TermReadKey</span></strong></pre>
<p>Remove any supplied MySQL.</p>
<p>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.</p>
<pre><strong><span style="color: #008000;"> rpm -e mysql</span></strong>
<strong><span style="color: #008000;"> rpm -e mysql-libs --nodeps</span></strong></pre>
<h3></h3>
<h3>Security</h3>
<p>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.</p>
<pre><strong><span style="color: #008000;"> service iptables stop</span></strong>
<strong><span style="color: #008000;"> chkconfig iptables off</span></strong>
<strong><span style="color: #008000;"> service ip6tables stop</span></strong>
<strong><span style="color: #008000;"> chkconfig ip6tables off</span></strong></pre>
<p>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.</p>
<pre><strong><span style="color: #008000;"> vi /etc/selinux/config</span></strong></pre>
<p><span style="color: #0000ff;">SELINUX=disabled</span></p>
<pre><strong><span style="color: #008000;"> echo 0 &gt;/selinux/enforce</span></strong></pre>
<p>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.</p>
<pre><span style="color: #008000;"><strong> yum -y install policycoreutils-python</strong></span>
<span style="color: #008000;"><strong> semanage fcontext -a -t mysqld_db_t "/data/mysql(/.*)?"</strong></span>
<span style="color: #008000;"><strong> restorecon -Rv /data/mysql</strong></span></pre>
<h3>Swap System</h3>
<p>Serving queries from memory is much better then feeding it from disk. MySQL works hard to store data in a way to improve disk assess.  Feeding data from swap-ed out memory seems like a bad thing.  You not only have to go extra system code and the data is not stored in a way optimized for data.</p>
<p>Turning swap off altogether is a bad idea.  Some system utilities and applications expect there to be some swap available.  Turning down how much swap is used is the way to go.</p>
<p>Edit system control file and turn &#8216;swappness&#8217; to zero.</p>
<pre><strong><span style="color: #008000;">vi /etc/sysctl.conf</span></strong></pre>
<p>and add the line</p>
<pre><strong><span style="color: #0000ff;">sys.swappiness=0</span></strong></pre>
<p>&nbsp;</p>
<h3>Syncing Time</h3>
<p>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.</p>
<pre><span style="color: #008000;"><strong> yum -y install ntp</strong></span>
<span style="color: #008000;"><strong> chkconfig ntpd on</strong></span>
<span style="color: #008000;"><strong> ntpdate 0.pool.ntp.org</strong></span>
<span style="color: #008000;"><strong> service ntpd start</strong></span></pre>
<h3></h3>
<h3>Setup SSH</h3>
<p>Now is a good time to make sure DNS works on all servers and each knows their names.</p>
<p>MHA need ssh access to each server. You need to create ssh keys and copy to the mysql servers.</p>
<p>Skip this if you already have ssh keys installed.</p>
<pre><span style="color: #008000;"><strong> ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ""</strong></span>
<span style="color: #008000;"><strong> cp ~/.ssh/id_dsa.pub ~/.ssh/authorized_keys</strong></span>
<span style="color: #008000;"><strong> scp -r ~/.ssh <span style="color: #ff0000;">db2</span>:.</strong></span></pre>
<h3></h3>
<h3>Network configuration</h3>
<p>You can edit all the network setting with the network system configuration utility.</p>
<pre><span style="color: #008000;"><strong> system-config-network</strong></span></pre>
<p>Except you need to insure the hosts can ALWAY resolve each other.</p>
<pre><span style="color: #008000;"><strong> vi /etc/hosts</strong></span></pre>
<p><span style="color: #ff0000;">192.168.2.160 db.grennan.com db</span><br />
<span style="color: #ff0000;"> 192.168.2.161 db1.grennan.com db1</span><br />
<span style="color: #ff0000;"> 192.168.2.162 db2.grennan.com db2</span><br />
<span style="color: #ff0000;"> 192.168.2.163 db3.grennan.com db3</span></p>
<pre><strong><span style="color: #008000;"> scp /etc/hosts <span style="color: #ff0000;">db2</span>:/etc</span></strong></pre>
<p>Now is a good time to reboot each system and check the install.</p>
<pre><strong><span style="color: #008000;"> init 6</span></strong></pre>
<h3></h3>
<h3>MySQL Setup</h3>
<p>Install the MySQL of your choise. I’m installing Percona’s version 5.5.</p>
<pre><span style="color: #008000;"><strong> rpm -e mysql-libs-5.1.52 --nodeps</strong></span>
<span style="color: #008000;"><strong> rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm</strong></span>
<span style="color: #008000;"><strong> yum -y install Percona-Server-shared-compat</strong></span>
<span style="color: #008000;"><strong> yum -y install percona-toolkit</strong></span>
<span style="color: #008000;"><strong> yum -y install Percona-Server-server-55.x86_64</strong></span>
<span style="color: #008000;"><strong> yum -y install Percona-Server-client-55</strong></span></pre>
<p>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.</p>
<pre><strong><span style="color: #008000;"> service mysql stop</span></strong>
<strong><span style="color: #008000;"> mkdir /data</span></strong>
<strong><span style="color: #008000;"> mkdir /data/mysql</span></strong>
<strong><span style="color: #008000;"> cp -prv /var/lib/mysql/* /data/mysql</span></strong>
<strong><span style="color: #008000;"> mv /var/lib/mysql /var/lib/mysql-empty</span></strong>
<strong><span style="color: #008000;"> ln -s /data/mysql /var/lib/mysql</span></strong>
<strong><span style="color: #008000;"> chown -R mysql.mysql /data/mysql</span></strong></pre>
<h3></h3>
<h3>Configure MySQL</h3>
<p>You need to change the server-id number on each server. The minimum setting you will need are:</p>
<pre><strong><span style="color: #008000;"> vi /etc/my.cnf</span></strong></pre>
<p><strong><span style="color: #0000ff;">[mysqld]</span></strong><br />
<strong> <span style="color: #0000ff;"> log-bin=mysql-bin</span></strong><br />
<strong> <span style="color: #0000ff;"> server-id=1                         # Each system needs a unique id number</span></strong><br />
<strong> <span style="color: #0000ff;"> innodb_flush_log_at_trx_commit=2</span></strong><br />
<strong> <span style="color: #0000ff;"> sync_binlog=<span style="color: #ff0000;">1</span></span></strong><br />
<strong> <span style="color: #0000ff;"> # relay_log_purge=0 # uncomment on slaves</span></strong><br />
<strong> <span style="color: #0000ff;"> # read_only=1                 # uncomment on slaves</span></strong></p>
<p>Percona has a service to help you configure MySQL for your hardware.   <a href="http://tools.percona.com/">MySQL Configuration Wizard</a></p>
<p>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.</p>
<p>If you have skip-name-resolve set you will need to substitute the host names for IP addresses.</p>
<pre><strong><span style="color: #008000;"> service mysql start</span></strong>
<strong><span style="color: #008000;"> mysql -h localhost -u root -p</span></strong></pre>
<p>The next set of command are entered into the mysql client. You should have a ‘mysql &gt;’ prompt.</p>
<pre><strong><span style="color: #008000;"> DROP USER ``@`localhost`;</span></strong>
<strong><span style="color: #008000;"> DROP USER ``@`<span style="color: #ff0000;">db1.grennan.com</span>` ;</span></strong>
<strong><span style="color: #008000;"> GRANT ALL on *.* TO `root`@`<span style="color: #ff0000;">192.168.2.</span>%` IDENTIFIED by `<span style="color: #ff0000;">P@ssw0rd</span>` with GRANT option;</span></strong>
<strong><span style="color: #008000;"> GRANT ALL on *.* TO `root`@`localhost` IDENTIFIED by `<span style="color: #ff0000;">P@ssw0rd</span>` with GRANT option;</span></strong>
<strong><span style="color: #008000;"> CREATE USER `repl`@`<span style="color: #ff0000;">192.168.2.</span>%` IDENTIFIED BY `<span style="color: #ff0000;">RepP@ssw0rd</span>`;</span></strong>
<strong><span style="color: #008000;"> GRANT REPLICATION SLAVE ON *.* TO `repl`@`<span style="color: #ff0000;">192.168.2.</span>%`;</span></strong>
<strong><span style="color: #008000;"> grant all on *.* to `hauser`@`<span style="color: #ff0000;">db1.grennan.com</span>` identified by `<span style="color: #ff0000;">P@ssw0rd</span>`;</span></strong>
<strong><span style="color: #008000;"> grant all on *.* to `hauser`@`<span style="color: #ff0000;">db2.grennan.com</span>` identified by `<span style="color: #ff0000;">P@ssw0rd</span>`;</span></strong>
<strong><span style="color: #008000;"> flush privileges;</span></strong>
<strong><span style="color: #008000;"> quit ;</span></strong></pre>
<p>Now, stop MySQL on all servers and copy all the MySQL data files to the slaves.</p>
<p>From the master (db1) at a system prompt ‘#’ :</p>
<pre><strong><span style="color: #008000;"> service mysql stop</span></strong>
<strong><span style="color: #008000;"> ssh db2 `service mysql stop`</span></strong>
<strong><span style="color: #008000;"> rsync -rog --delete /data/mysql root@</span><span style="color: #ff0000;">db2<span style="color: #008000;">:/data</span></span></strong></pre>
<p>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.</p>
<pre><strong><span style="color: #008000;"> vi ~/.my.cnf</span></strong></pre>
<p><strong><span style="color: #0000ff;">[Client]</span></strong><br />
<strong> <span style="color: #0000ff;"> user=root</span></strong><br />
<strong> <span style="color: #0000ff;"> password=<span style="color: #ff0000;">P@ssw0rd</span></span></strong><br />
<strong> <span style="color: #0000ff;"> host=localhost</span></strong><br />
<strong> <span style="color: #0000ff;"> socket=/data/mysql/mysql.sock</span></strong></p>
<pre><strong><span style="color: #008000;"> scp .my.cnf <span style="color: #ff0000;">db2</span>:.</span></strong></pre>
<h3></h3>
<h3>Start Replication</h3>
<p>On each system start MySQL and connect the two slaves to the master.</p>
<p>On the master we need to now the bin-file and the position. Note the numbers in <strong><span style="color: #800080;">purple</span></strong>.</p>
<pre><strong><span style="color: #008000;"> service mysql start</span></strong>
<strong><span style="color: #008000;"> mysql -e `reset master; reset slave;`</span></strong>
<strong><span style="color: #008000;"> mysql -e `show master status\G`</span></strong></pre>
<p><strong>*************************** 1. row ***************************</strong><br />
<strong> File: mysql-bin.<span style="color: #800080;">000001</span></strong><br />
<strong> Position: <span style="color: #800080;">107</span></strong><br />
<strong> Binlog_Do_DB:</strong><br />
<strong> Binlog_Ignore_DB:</strong><br />
<strong> 1 row in set (0.00 sec)</strong></p>
<p>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. (<strong>Yes</strong>).<br />
service mysql start</p>
<pre> <strong><span style="color: #008000;">mysql</span></strong></pre>
<pre> <strong><span style="color: #008000;">stop slave;</span></strong>
<strong><span style="color: #008000;"> CHANGE MASTER TO MASTER_HOST='192.168.2.201', MASTER_USER='repl',</span></strong>
<strong><span style="color: #008000;"> MASTER_PASSWORD='RepP@ssw0rd', MASTER_LOG_FILE='mysql-bin.<span style="color: #800080;">000001</span>', MASTER_LOG_POS=<span style="color: #800080;">107</span> ;</span></strong>
<strong><span style="color: #008000;"> start slave ;</span></strong>
<strong><span style="color: #008000;"> show slave status\G</span></strong></pre>
<p><strong>Slave_IO_Running: Yes</strong><br />
<strong> Slave_SQL_Running: Yes</strong></p>
<h3></h3>
<h3>Installing MHA</h3>
<p>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.</p>
<p>http://code.google.com/p/mysql-master-ha/downloads/list</p>
<p>There are a number of required Perl modules. I chose to use the Fedora evaluation packages to resolve these.</p>
<ul>
<li>DBD::mysql</li>
<li>Config::Tiny</li>
<li>Log::Dispatch</li>
<li>Parallel::ForkManager</li>
<li>Time::HiRes</li>
</ul>
<p>Here is my install with the fedora packages.</p>
<pre><strong><span style="color: #008000;"> wget http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm</span></strong>
<strong><span style="color: #008000;"> rpm -i epel-release-6-5.noarch.rpm</span></strong>
<strong><span style="color: #008000;"> yum -y install perl-DBD-MySQL</span></strong>
<strong><span style="color: #008000;"> yum -y install perl-Config-Tiny</span></strong>
<strong><span style="color: #008000;"> yum -y install perl-Log-Dispatch</span></strong>
<strong><span style="color: #008000;"> yum -y install perl-Parallel-ForkManager</span></strong>
<strong><span style="color: #008000;"> yum -y install perl-Time-HiRes</span></strong>
<strong><span style="color: #008000;"> wget http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.53-0.el6.noarch.rpm</span></strong>
<strong><span style="color: #008000;"> rpm -i mha4mysql-node-0.53-0.el6.noarch.rpm</span></strong>
<strong><span style="color: #008000;"> wget http://mysql-master-ha.googlecode.com/files/mha4mysql-manager-0.53-0.el6.noarch.rpm</span></strong>
<strong><span style="color: #008000;"> rpm -i mha4mysql-manager-0.53-0.noarch.rpm</span></strong></pre>
<p>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.</p>
<pre><strong><span style="color: #008000;"> vi /etc/MHA.cnf</span></strong></pre>
<p>Insert this configuration data into the MHA.cnf file.</p>
<p><strong><span style="color: #0000ff;">[server default]</span></strong><br />
<strong> <span style="color: #0000ff;"> user=root</span></strong><br />
<strong> <span style="color: #0000ff;"> password=<span style="color: #ff0000;">P@ssw0rd</span></span></strong><br />
<strong> <span style="color: #0000ff;"> manager_workdir=/var/log/masterha</span></strong><br />
<strong> <span style="color: #0000ff;"> manager_log=/var/log/masterha/MHA.log</span></strong><br />
<strong> <span style="color: #0000ff;"> remote_workdir=/var/log/masterha</span></strong></p>
<p><strong><span style="color: #0000ff;">[server1]</span></strong><br />
<strong> <span style="color: #0000ff;"> hostname=<span style="color: #ff0000;">db1</span></span></strong></p>
<p><strong><span style="color: #0000ff;">[server2]</span></strong><br />
<strong> <span style="color: #0000ff;"> hostname=<span style="color: #ff0000;">db2</span></span></strong></p>
<p>You should have already installed SSH keys (see above) and the ‘hauser’ installed in MySQL.</p>
<p>masterha_check_ssh is used to check if you have SSH working. Look for the OK after the connect test.</p>
<pre><strong><span style="color: #008000;"> masterha_check_ssh --conf=/etc/MHA.cnf</span></strong></pre>
<p><strong>Thu Dec 1 10:10:52 2011 &#8211; [info] Starting SSH connection tests..</strong><br />
<strong> Thu Dec 1 10:10:53 2011 &#8211; [debug]</strong><br />
<strong> Thu Dec 1 10:10:52 2011 &#8211; [debug] Connecting via SSH from root@db1(192.168.0.11) to root@db2(192.168.2.12)..</strong><br />
<strong> Thu Dec 1 10:10:53 2011 &#8211; [debug] ok.</strong></p>
<p>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.</p>
<pre><strong><span style="color: #008000;"> masterha_check_repl --conf=/etc/MHA.cnf</span></strong></pre>
<p><strong>&#8212;</strong><br />
<strong> Thu Dec 1 10:07:22 2011 &#8211; [info] Checking slave configurations..</strong><br />
<strong> Thu Dec 1 10:07:22 2011 &#8211; [warning] read_only=1 is not set on slave db2(192.168.0.11:3306).</strong><br />
<strong> Thu Dec 1 10:07:22 2011 &#8211; [warning] relay_log_purge=0 is not set on slave db2(192.168.0.12:3306).</strong><br />
<strong> &#8212;</strong><br />
<strong> MySQL Replication Health is OK.</strong></p>
<p>&nbsp;</p>
<p>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.</p>
<p>We’ll be using Pacemaker and a command like this to fail over to a slave when the master dies.</p>
<p>masterha_master_switch &#8211;master_state=dead &#8211;dead_master_host=db1 &#8211;conf=/etc/MHA.cnf</p>
<h3></h3>
<h3>Putting the H in High Availability (HA)</h3>
<p>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.</p>
<h3>Install Pacemaker / CoroSync</h3>
<p>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.</p>
<p>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.</p>
<pre><strong><span style="color: #008000;"> wget -O /etc/yum.repos.d/pacemaker.repo http://clusterlabs.org/rpm/epel-5/clusterlabs.repo</span></strong>
<strong><span style="color: #008000;"> yum -y install libtool-ltdl</span></strong>
<strong><span style="color: #008000;"> ln -s /usr/lib64/libltdl.so.7.2.1 /usr/lib64/libltdl.so.3</span></strong>
<strong><span style="color: #008000;"> yum -y install net-snmp</span></strong>
<strong><span style="color: #008000;"> wget http://www.clusterlabs.org/rpm/epel-5/x86_64/cluster-glue-1.0.6-1.6.el5.x86_64.rpm</span></strong>
<strong><span style="color: #008000;"> wget http://www.clusterlabs.org/rpm/epel-5/x86_64/cluster-glue-libs-1.0.6-1.6.el5.x86_64.rpm</span></strong>
<strong><span style="color: #008000;"> rpm -i cluster-glue-1.0.6-1.6.el5.x86_64.rpm --nodeps</span></strong>
<strong><span style="color: #008000;"> rpm -i cluster-glue-libs-1.0.6-1.6.el5.x86_64.rpm --nodeps</span></strong>
<strong><span style="color: #008000;"> yum -y install pacemaker corosync heartbeat</span></strong></pre>
<p>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.</p>
<h3>Configure CoroSync</h3>
<p>On both DB1 and DB2.</p>
<pre><strong><span style="color: #008000;"> corosync-keygen</span></strong>
<strong><span style="color: #008000;"> chown root:root /etc/corosync/authkey</span></strong>
<strong><span style="color: #008000;"> chmod 400 /etc/corosync/authkey</span></strong></pre>
<pre><strong><span style="color: #008000;"> vi /etc/corosync/corosync.conf</span></strong></pre>
<p><strong><span style="color: #0000ff;">totem {</span></strong><br />
<strong> <span style="color: #0000ff;">    version: 2</span></strong><br />
<strong> <span style="color: #0000ff;">    token: 5000 # How long before declaring a token lost (ms)</span></strong><br />
<strong> <span style="color: #0000ff;">    token_retransmits_before_loss_const: 20 # How many token retransmits</span></strong><br />
<strong> <span style="color: #0000ff;">    # before forming a new configuration</span></strong><br />
<strong> <span style="color: #0000ff;">    join: 1000 # How long to wait for join messages in the membership protocol (ms)</span></strong><br />
<strong> <span style="color: #0000ff;">    consensus: 7500 # How long to wait for consensus to be achieved before</span></strong><br />
<strong> <span style="color: #0000ff;">    # starting a new round of membership configuration (ms)</span></strong><br />
<strong> <span style="color: #0000ff;">    vsftype: none # Turn off the virtual synchrony filter</span></strong><br />
<strong> <span style="color: #0000ff;">    max_messages: 20 # Number of messages that may be sent by</span></strong><br />
<strong> <span style="color: #0000ff;">    #one processor on receipt of the token</span></strong><br />
<strong> <span style="color: #0000ff;">    secauth: off # Disable encryption</span></strong><br />
<strong> <span style="color: #0000ff;">    threads: 0 # How many threads to use for encryption/decryption</span></strong><br />
<strong> <span style="color: #0000ff;">    clear_node_high_bit: yes # Limit generated nodeids to 31-bits (positive signed integers)</span></strong><br />
<strong> <span style="color: #0000ff;">    # Optionally assign a fixed node id (integer)</span></strong><br />
<strong> <span style="color: #0000ff;">    # nodeid: 1234</span></strong><br />
<strong> <span style="color: #0000ff;">    interface {</span></strong><br />
<strong> <span style="color: #0000ff;">        ringnumber: 0</span></strong><br />
<strong> <span style="color: #0000ff;">        # The following three values need to be set based on your environment</span></strong><br />
<strong> <span style="color: #0000ff;">        bindnetaddr: <span style="color: #ff0000;">192.168.2.201</span></span></strong><br />
<strong> <span style="color: #0000ff;">        mcastaddr: 239.255.42.0</span></strong><br />
<strong> <span style="color: #0000ff;">        mcastport: 5405</span></strong><br />
<strong> <span style="color: #0000ff;">        }</span></strong><br />
<strong> <span style="color: #0000ff;"> }</span></strong><br />
<strong> <span style="color: #0000ff;"> logging {</span></strong><br />
<strong> <span style="color: #0000ff;">    fileline: off</span></strong><br />
<strong> <span style="color: #0000ff;">    to_syslog: yes</span></strong><br />
<strong> <span style="color: #0000ff;">    to_stderr: no</span></strong><br />
<strong> <span style="color: #0000ff;">    syslog_facility: daemon</span></strong><br />
<strong> <span style="color: #0000ff;">    debug: on</span></strong><br />
<strong> <span style="color: #0000ff;">    timestamp: on</span></strong><br />
<strong> <span style="color: #0000ff;"> }</span></strong><br />
<strong> <span style="color: #0000ff;"> amf {</span></strong><br />
<strong> <span style="color: #0000ff;">    mode: disabled</span></strong><br />
<strong> <span style="color: #0000ff;"> }</span></strong></p>
<pre><strong><span style="color: #008000;"> vi /etc/corosync/service.d/pcmk</span></strong></pre>
<p><strong><span style="color: #0000ff;">service {</span></strong><br />
<strong> <span style="color: #0000ff;">    # Load the Pacemaker Cluster Resource Manager</span></strong><br />
<strong> <span style="color: #0000ff;">    name: pacemaker</span></strong><br />
<strong> <span style="color: #0000ff;">    ver: 0</span></strong><br />
<strong> <span style="color: #0000ff;"> }</span></strong></p>
<p>If you didn’t edit this on both servers copy it from second server.</p>
<pre><strong><span style="color: #008000;"> rsync -rop /etc/corosync db2:/etc</span></strong></pre>
<p>Now start corosync on both servers.</p>
<pre><strong><span style="color: #008000;"> chkconfig corosync on</span></strong>
<strong><span style="color: #008000;"> /etc/init.d/corosync start</span></strong></pre>
<p>Check CoroSync healty. Look for ‘no faluts’ and both members show up as members.</p>
<pre><strong><span style="color: #008000;"> corosync-cfgtool -s</span></strong></pre>
<p><strong>Printing ring status.</strong><br />
<strong> Local node ID -922572608</strong><br />
<strong> RING ID 0</strong><br />
<strong> id = 192.168.2.201</strong><br />
<strong> status = ring 0 active with no faults</strong></p>
<pre><strong><span style="color: #008000;"> corosync-objctl | grep members</span></strong></pre>
<p><strong>totem.join=1000 # How long to wait for join messages in the membership protocol (ms)</strong><br />
<strong> runtime.totem.pg.mrp.srp.members.-922572608.ip=r(0) ip(192.168.2.201)</strong><br />
<strong> runtime.totem.pg.mrp.srp.members.-922572608.join_count=1</strong><br />
<strong> runtime.totem.pg.mrp.srp.members.-922572608.status=joined</strong><br />
<strong> runtime.totem.pg.mrp.srp.members.-905795392.ip=r(0) ip(192.168.2.202)</strong><br />
<strong> runtime.totem.pg.mrp.srp.members.-905795392.join_count=1</strong><br />
<strong> runtime.totem.pg.mrp.srp.members.-905795392.status=joined</strong></p>
<h3></h3>
<h3>Patch for Pacemaker</h3>
<p>Yves Trudeau had created a newer version of the mysql resource agent for Pacemaker. He keeps it at:<br />
https://github.com/y-trudeau/. Just download it and copy it into the ocf resource heartbeat directory.</p>
<pre><strong><span style="color: #008000;"> wget https://raw.github.com/y-trudeau/resource-agents/master/heartbeat/mysql</span></strong>
<strong><span style="color: #008000;"> cp mysql /usr/lib/ocf/resource.d/heartbeat/mysql</span></strong></pre>
<h3></h3>
<h3>Configure Pacemaker</h3>
<p>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:</p>
<pre><strong><span style="color: #008000;"> crm configure property stonith-enabled="false"</span></strong></pre>
<p>If your cluster consists of just two nodes, switch the quorum feature off with:</p>
<pre><strong><span style="color: #008000;"> crm configure property no-quorum-policy=ignore</span></strong></pre>
<p>This is a bit of magic. I’ll explain after we’re done. Create file to configure crm and paste this document into it.</p>
<pre><strong><span style="color: #008000;"> crm configure node db2.grennan.com attributes IP="<span style="color: #ff0000;">192.168.2.202</span>"</span></strong></pre>
<pre><strong><span style="color: #008000;"> crm configure</span></strong></pre>
<p>Now your in the CRM configuration utility. Type in the blue part of this txt and edit the red parts to fit your configuration.</p>
<pre><strong>crm(live)configure# <span style="color: #0000ff;">primitive failover-ip ocf:heartbeat:IPaddr \</span></strong>
<span style="color: #0000ff;"><strong> params ip="<span style="color: #ff0000;">192.168.2.200</span>" \</strong></span>
<span style="color: #0000ff;"><strong> operations $id="failover-ip-operations" \</strong></span>
<span style="color: #0000ff;"><strong> op monitor start-delay="0" interval="2"</strong></span></pre>
<pre><strong>crm(live)configure# <span style="color: #0000ff;">primitive p_mysql ocf:heartbeat:mysql \</span></strong>
<span style="color: #0000ff;"><strong> params pid="/var/run/mysqld/mysqld.pid" socket="/data/mysql/mysql.sock" \</strong></span>
<span style="color: #0000ff;"><strong> test_passwd="<span style="color: #ff0000;">P@ssw0rd</span>" enable_creation="false" replication_user="root" \</strong></span>
<span style="color: #0000ff;"><strong> replication_passwd="<span style="color: #ff0000;">P@ssw0rd</span>" MHASupport="true" \</strong></span>
<span style="color: #0000ff;"><strong> operations $id="p_mysql-operations" \</strong></span>
<span style="color: #0000ff;"><strong> op monitor interval="20" timeout="30" depth="0" \</strong></span>
<span style="color: #0000ff;"><strong> op monitor interval="10" role="Master" timeout="30" depth="0" \</strong></span>
<span style="color: #0000ff;"><strong> op monitor interval="30" role="Slave" timeout="30" depth="0"</strong></span></pre>
<pre><strong>crm(live)configure# <span style="color: #0000ff;">ms ms_mysql p_mysql </span></strong><span style="color: #0000ff;"><strong>meta clone-max="2" notify="true"</strong></span></pre>
<pre><strong>crm(live)configure# <span style="color: #0000ff;">colocation col_ms_mysql_failover-ip inf: failover-ip ms_mysql:Master</span></strong></pre>
<pre><strong>crm(live)configure# <span style="color: #0000ff;">order ord_ms_mysql_failover-ip inf: ms_mysql:promote failover-ip:start</span></strong></pre>
<pre><strong>crm(live)configure# <span style="color: #0000ff;">commit</span></strong></pre>
<pre><strong>crm(live)configure# <span style="color: #0000ff;">quit</span></strong></pre>
<p>&nbsp;</p>
<h3>Monitor Pacemaker</h3>
<p>Back at the system prompt you can monitor the health of Pacemaker from the command line.</p>
<pre><strong><span style="color: #008000;"> crm_mon -Arf</span></strong></pre>
<p><strong>============</strong><br />
<strong> Last updated: Fri Feb 10 14:28:53 2012</strong><br />
<strong> Last change: Fri Feb 10 14:26:15 2012 via crm_attribute on db1.grennan.com</strong><br />
<strong> Stack: openais</strong><br />
<strong> Current DC: db1.grennan.com &#8211; partition with quorum</strong><br />
<strong> Version: 1.1.6-3.el6-a02c0f19a00c1eb2527ad38f146ebc0834814558</strong><br />
<strong> 2 Nodes configured, 2 expected votes</strong><br />
<strong> 3 Resources configured.</strong><br />
<strong> ============</strong></p>
<p><strong>Online: [ db1.grennan.com db2.grennan.com ]</strong></p>
<p><strong>Full list of resources:</strong></p>
<p><strong>failover-ip (ocf::heartbeat:IPaddr): Started db1.grennan.com</strong><br />
<strong> Master/Slave Set: ms_mysql [p_mysql]</strong><br />
<strong> Masters: [ db1.grennan.com ]</strong><br />
<strong> Slaves: [ db2.grennan.com ]</strong></p>
<p><strong>Node Attributes:</strong><br />
<strong> * Node db1.grennan.com:</strong><br />
<strong> + IP : 192.168.2.201</strong><br />
<strong> + master-p_mysql:0 : 3601</strong><br />
<strong> + readerOK : 1</strong><br />
<strong> + writerOK : 1</strong><br />
<strong> * Node db2.grennan.com:</strong><br />
<strong> + IP : 192.168.2.202</strong><br />
<strong> + master-p_mysql:1 : 1</strong><br />
<strong> + readerOK : 0</strong><br />
<strong> + writerOK : 0</strong></p>
<p><strong>Migration summary:</strong></p>
<p><strong>* Node db1.grennan.com:</strong><br />
<strong> * Node db2.grennan.com:</strong></p>
<h3></h3>
<h3><a href="http://www.mysqlfanboy.com/wp-content/uploads/2012/02/image001.png"><img class="alignright size-medium wp-image-806" title="image001" src="http://www.mysqlfanboy.com/wp-content/uploads/2012/02/image001-300x179.png" alt="" width="300" height="179" /></a>Install DRBD Management Console</h3>
<p>The DRBD Management Console is a Java application that eases the burden of managing your DRBD and Pacemaker/Corosync or Heartbeat based cluster systems.</p>
<p>Download this Jar file to your workstation.</p>
<p>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.</p>
<p>http://sourceforge.net/projects/lcmc/files/LCMC-1.2.3.jar/download</p>
<p>[I'll post a video of configuring the Management Console here.]</p>
<p>&nbsp;</p>
<h3>But wait there is MORE</h3>
<h3>Percona Tool kit</h3>
<p>You install the Perconal Tool kit when you installed MySQL. :-) Percona Toolkit is a collection of advanced command-line tools used by Percona (<a href="http://www.percona.com/ ">http://www.percona.com/</a>) 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:</p>
<ul>
<li>pt-duplicate-key-checker &#8211; Find duplicate indexes and foreign keys on MySQL tables.</li>
<li>pt-heartbeat &#8211; Monitor MySQL replication delay.</li>
<li>pt-index-usage &#8211; Read queries from a log and analyze how they use indexes.</li>
<li>pt-query-advisor &#8211; Analyze queries and advise on possible problems.</li>
<li>pt-query-digest &#8211; Analyze query execution logs and generate a query report, filter, replay, or transform queries for MySQL, PostgreSQL, memcached, and more.</li>
<li>pt-query-profiler &#8211; Execute SQL statements and print statistics, or measure activity caused by other processes.</li>
<li>pt-show-grants &#8211; Print MySQL grants so you can effectively replicate, compare and version-control them.</li>
<li>pt-table-checksum &#8211; Perform an online replication consistency check, or checksum MySQL tables efficiently on one or many servers.</li>
<li>pt-table-sync &#8211; Synchronize MySQL table data efficiently.</li>
<li>pt-visual-explain &#8211; Format EXPLAIN output as a tree.</li>
</ul>
<h3>openark kit</h3>
<p><a href="http://code.openark.org/blog/shlomi-noach">Shlomi Noach</a> maintains another great set of utility.</p>
<ul>
<li>oak-apply-ri: apply referential integrity on two columns with parent-child relationship.</li>
<li>oak-block-account: block or release MySQL users accounts, disabling them or enabling them to login.</li>
<li>oak-chunk-update: perform long, non-blocking UPDATE/DELETE operation in auto managed small chunks.</li>
<li>oak-get-slave-lag: print slave replication lag and terminate with respective exit code.</li>
<li>oak-hook-general-log: hook up and filter general log entries based on entry type or execution plan criteria.</li>
<li>oak-kill-slow-queries: terminate long running queries.</li>
<li>oak-modify-charset: change the character set (and collation) of a textual column.</li>
<li>oak-online-alter-table: perform a non-blocking ALTER TABLE operation.</li>
<li>oak-prepare-shutdown: make for a fast and safe MySQL shutdown.</li>
<li>oak-purge-master-logs: purge master logs, depending on the state of replicating slaves.</li>
<li>oak-repeat-query: repeat query execution until some condition holds.</li>
<li>oak-security-audit: audit accounts, passwords, privileges and other security settings.</li>
<li>oak-show-limits: show AUTO_INCREMENT “free space”.</li>
<li>oak-show-replication-status: show how far behind are replicating slaves on a given master.</li>
</ul>
<p>You can find them here. <a href="http://code.openark.org/forge/openark-kit">http://code.openark.org/forge/openark-kit</a></p>
<h3>MyTOP</h3>
<p>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 &lt;Jeremy@Zawodny.com&gt; 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.</p>
<p>I would be amiss if I didn&#8217;t say something about innotop. Some consider this a  successors to mytop. It is if you are using InnoDB. I still find mytop useful. More than half of my tables are MyISAM.</p>
<pre><strong><span style="color: #008000;"> wget http://www.mysqlfanboy.com/mytop/mytop-1.9.tar.gz</span></strong>
<strong><span style="color: #008000;"> tar zxf mytop-1.9.tar.gz</span></strong>
<strong><span style="color: #008000;"> cd mytop-1.9</span></strong>
<strong><span style="color: #008000;"> perl Makefile.PL</span></strong>
<strong><span style="color: #008000;"> make install</span></strong></pre>
<pre><strong><span style="color: #008000;"> wget https://innotop.googlecode.com/files/innotop-1.8.0.tar.gz</span></strong>
<strong><span style="color: #008000;"> cd innotop-1.8.0</span></strong>
<strong><span style="color: #008000;"> perl Makefile.PL</span></strong>
<strong><span style="color: #008000;"> make install</span></strong></pre>
<h3>Backup</h3>
<p>Percona XtraBackup is a hot backup utility that doesn’t lock your database during the backup!</p>
<p>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.</p>
<pre><strong><span style="color: #008000;"> yum -y install xtrabackup</span></strong></pre>
<pre><strong><span style="color: #008000;"> innobackupex --user=root --password=`<span style="color: #ff0000;">P@ssw0rd</span>` /tmp/Backup</span></strong></pre>
<p>Here is an example script.</p>
<p>export HOST=`/bin/hostname -a`<br />
mkdir /root/Backup<br />
/usr/bin/innobackupex &#8211;user=root &#8211;password=`P@ssword` /root/Backup<br />
/usr/bin/xtrabackup &#8211;prepare &#8211;target-dir=/tmp/backup<br />
/bin/find /tmp/Backup/* -mtime +1 -exec rm {} -Rf \;</p>
<h3>Last word</h3>
<p>If you’ve made it this fare, now is a good time to restart everything and do some testing.</p>
<pre><strong><span style="color: #008000;"> init 6</span></strong></pre>
<p>&nbsp;</p>
<p><img class="Left" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F2012%2F02%2Fthe-full-monty-version-2-3%2F&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=The Full Monty - Version 2 - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/2012/02/the-full-monty-version-2-3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>I have proof of UFOs</title>
		<link>http://www.mysqlfanboy.com/2012/02/i-have-proof-of-ufos/</link>
		<comments>http://www.mysqlfanboy.com/2012/02/i-have-proof-of-ufos/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 00:11:27 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=776</guid>
		<description><![CDATA[Un-maned Failover Operations I have video of two MySQL servers (one master, on slave) failing over from Master to Slave.  The Master becomes the Slave and vise-verse with the slave becoming read-only.  Next some load testing and then I&#8217;ll post how I did it with FREE software. Tweet]]></description>
			<content:encoded><![CDATA[<p>Un-maned Failover Operations</p>
<p>I have video of two MySQL servers (one master, on slave) failing over from Master to Slave.  The Master becomes the Slave and vise-verse with the slave becoming read-only.  Next some load testing and then I&#8217;ll post how I did it with FREE software.</p>
<p><a href="http://www.youtube.com/watch?v=WwSOjrXVaP8"><img src="http://img.youtube.com/vi/WwSOjrXVaP8/2.jpg"></a></p>
<p><a href="http://www.youtube.com/watch?v=WwSOjrXVaP8">Click here</a> to view the video on YouTube.</p>

<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F2012%2F02%2Fi-have-proof-of-ufos%2F&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=I have proof of UFOs - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/2012/02/i-have-proof-of-ufos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>To NULL or NOT to NULL that is the question.</title>
		<link>http://www.mysqlfanboy.com/2012/01/to-null-or-not-to-null-that-is-the-question/</link>
		<comments>http://www.mysqlfanboy.com/2012/01/to-null-or-not-to-null-that-is-the-question/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 17:07:19 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=762</guid>
		<description><![CDATA[I liked Shlomi Noach post on &#8220;IS TRUE and IS FALSE&#8220;.  This kind of logic create bugs. What will this return? select if((1 = true) and ( 1 is TRUE) and (NULL is not TRUE), TRUE, FALSE) as answer; You should know, NULL is never TRUE or FALSE but NULL is always NOT TRUE or [...]]]></description>
			<content:encoded><![CDATA[<p>I liked Shlomi Noach post on &#8220;<a title="Permanent Link to Syntax of the day: IS TRUE and IS FALSE" href="http://code.openark.org/blog/mysql/syntax-of-the-day-is-true-and-is-false" rel="bookmark">IS TRUE and IS FALSE</a>&#8220;.  This kind of logic create bugs.</p>
<p>What will this return?</p>
<p>select if((1 = true) and ( 1 is TRUE) and (NULL is not TRUE), TRUE, FALSE) as answer;</p>
<p>You should know,</p>
<p>NULL is never TRUE or FALSE but</p>
<p>NULL is always NOT TRUE or NOT FALSE.</p>
<p>NULL is a little like a vacuum.  Ancient <a title="Greek philosophy" href="http://en.wikipedia.org/wiki/Greek_philosophy">Greek philosophers</a> did not like to admit the existence of a vacuum, asking themselves &#8220;how can &#8216;nothing&#8217; be something?&#8221;.    Does GOD exist in NULL?</p>
<p>If  select &#8220;&#8221; is NOT NULL; is TRUE what is &#8220;&#8221;?</p>
<pre>select "" is NOT NULL;
+----------------+
| "" is NOT NULL |
+----------------+
|              1 |
+----------------+</pre>
<p>Is the lack of an answer, an answer? Is the lack of datum, DATA?  Or should it be &#8220;&#8221;.  Should we record the blank spaces?</p>
<p>Given:</p>
<div>
<table>
<tbody>
<tr>
<td>Create Table</td>
</tr>
<tr>
<td>CREATE TABLE `test` (<br />
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,<br />
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,<br />
`data` varchar(16) DEFAULT NULL,<br />
KEY `id` (`id`)<br />
) ENGINE=MyISAM</td>
</tr>
</tbody>
</table>
</div>
<p>When should this happen?</p>
<p>for x = 1 to X;<br />
INSERT INTO `test`(`data`) VALUES ( NULL);<br />
next x;</p>
<p>Null happens.</p>
<p><img class="left" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F2012%2F01%2Fto-null-or-not-to-null-that-is-the-question%2F&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=To NULL or NOT to NULL that is the question. - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/2012/01/to-null-or-not-to-null-that-is-the-question/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The State of High Availability</title>
		<link>http://www.mysqlfanboy.com/2012/01/the-state-of-high-availability/</link>
		<comments>http://www.mysqlfanboy.com/2012/01/the-state-of-high-availability/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 16:55:06 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Commentary]]></category>
		<category><![CDATA[DRDB]]></category>
		<category><![CDATA[HA]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=742</guid>
		<description><![CDATA[Searching for the Holly GrailFor months I have been writing and rewriting an blog post called “The Full Monty”. It’s a kind of how to build complete production system from scratch. I’m still not done. Maybe I’m fullish thinking I can build a one type fits all database server. But that’s not the problem. I’ve [...]]]></description>
			<content:encoded><![CDATA[<div><strong id="internal-source-marker_0.19038121355697513"><a href="http://www.mysqlfanboy.com/wp-content/uploads/2012/01/HolyGrail.jpg"><img class="alignright size-medium wp-image-743" title="HolyGrail" src="http://www.mysqlfanboy.com/wp-content/uploads/2012/01/HolyGrail-300x165.jpg" alt="" width="300" height="165" /></a></strong>Searching for the Holly GrailFor months I have been writing and rewriting an blog post called “The Full Monty”. It’s a kind of how to build complete production system from scratch. I’m still not done. Maybe I’m fullish thinking I can build a one type fits all database server. But that’s not the problem. I’ve found myself chasing the Holly Grail of HA and replication.I’ve build many virtual clusters with all the HA / replication package I could find.</div>
<div></div>
<div></div>
<div>I’ve tried <a href="http://www.drbd.org/">DRBD</a>, <a href="http://linux-ha.org/wiki/Heartbeat">Heartbeat</a>,  <a href="http://mysql-mmm.org/">Multi Master Management</a> (MMM), <a href="http://code.google.com/p/tungsten-replicator/">Tungsten</a>, <a href="http://provenscaling.com/software/flipper/">Flipper</a>, <a href="http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5/html/Cluster_Suite_Overview/s1-rhcs-intro-CSO.html">Redhat Cluster Suite</a> (RCS), <a href="http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster.html">MySQL Cluster</a>, <a href="http://code.google.com/p/mysql-master-ha/">MySQL Master HA</a> (MHA) and the <a href="http://www.percona.com/doc/percona-xtradb-cluster/index.html">Percona XtraDB Cluster</a> (PXC).  Some of these are just very simple (Flipper) some are heavy (RCS) and some are promising but in Alpha (PXC) or still a little rough (MHA).  Yoshinori Matsunobu (author of MHA) describes some of the <a href="http://code.google.com/p/mysql-master-ha/wiki/Other_HA_Solutions">solutions</a>to the issues.</div>
<div></div>
<div>White papers and discussions abound. Shlomi Noach and Baron Schwartz have public discussed problems with MMM show just how hard this problem is. ( <a href="http://code.openark.org/blog/mysql/problems-with-mmm-for-mysql">SH </a>/ <a href="http://www.xaprb.com/blog/2011/05/04/whats-wrong-with-mmm/">BS</a> ) Even <a href="http://kovyrin.net/">Alexey Kovyrin</a> said in a reply to Brian “<em>&#8230;Every time I try to add HA to my clusters I remember MMM and want to stab myself because I simply could not trust my data to the tool&#8230;</em>”.</div>
<div>
<p>Tungsten works. But size does matter. It is one of the heaver solutions requiring Java and many moving parts with version requirements and dependencies. As a result you can build a working system but its rock and hard to move forward to newer releases its parts.</p>
<p>Percona’s XtraDB Cluster gives me hope. It’s Alpha and only works on InnoDB tables (now) but it’s light, eazy to install and maintain.  (I think I can see the Holly Grail.)</p>
<p>I’m currently taking a second look at MySQL Master HA. My first run through was rough. MHA suffered from some dependency trouble and documentation holes. It seems to be currently under rapid development. That’s both good and bad. MHA may be your best choose if you’re looking from something free, simple to install and easy to maintain that keep your DBS alive. Unlike MMM, MHA does not move IP address.  You&#8217;ll still need something more like heartbeat.</p>
<p>How can you choose wisely?  Lets talk.</p>
</div>
<div><img class="left" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></div>
<div></div>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F2012%2F01%2Fthe-state-of-high-availability%2F&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=The State of High Availability  - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/2012/01/the-state-of-high-availability/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Install mysql-master-ha (MHA) on CentOS</title>
		<link>http://www.mysqlfanboy.com/2011/12/install-mysql-master-ha-mha-on-centos/</link>
		<comments>http://www.mysqlfanboy.com/2011/12/install-mysql-master-ha-mha-on-centos/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 22:32:15 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=721</guid>
		<description><![CDATA[MySQL doesn’t often crash, but, if you use MySQL on a production system you should have High Availability. Maybe you’ve not heard of MHA.  Yoshinori Matsunobu only released it in July of this year (2011).  I’ve been reviewing it and I think you should too. There are a lot of people chasing after this “holy [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>MySQL doesn’t often crash, but, if you use MySQL on a production system you should have High Availability.</p>
<p>Maybe you’ve not heard of <a href="http://code.google.com/p/mysql-master-ha/">MHA</a>.  <a href="http://yoshinorimatsunobu.blogspot.com/2011/07/announcing-mysql-mha-mysql-master-high.html">Yoshinori Matsunobu</a> only released it in July of this year (2011).  I’ve been reviewing it and I think you should too. There are a lot of people chasing after this “holy grail” and most systems are complex and / or <a href="http://www.xaprb.com/blog/2011/05/04/whats-wrong-with-mmm/">hard to recover</a> when they fail. MHA simple and easy to use.</p>
<p>MHA is a fail over tool. It’s designed to fail a master and promote a slave to a new master. (This is simply to say but you should read how it’s done.) It can monitor your master or you can manually fail over.  Failing back doesn’t happen. Your expected to fix the failed master and turn it into a slave.  The monitoring program (masterha_manager) will stop running after a fail over.</p>
<p>I’m not going to give details on <a href="http://code.google.com/p/mysql-master-ha/wiki/Overview">how MHA works</a>. I’ll assume you have a master and some number of slaves already working.</p>
<p><strong>Your slave/s server should be ready to become masters.</strong> This means they have sever_id and bin-log set.  You should be able to run &#8216;show master status&#8217; on your slave/s and get an answer. Slaves should also be set with read_only=1 and realy_log_purge=0;</p>
<h3><strong>Preparing the way </strong></h3>
<p>Download the latest version of MHA from the Google Code server. <a href="http://code.google.com/p/mysql-master-ha/downloads/list">http://code.google.com/p/mysql-master-ha/downloads/list</a></p>
<p>Every MySQL server needs to have a copy of the MHA node installed.</p>
<pre><strong><span style="color: #339966;"> yum install perl-DBD-MySQL.x86_64 </span></strong></pre>
<pre><strong> <span style="color: #339966;">rpm -i mha4mysql-node-0.52-0.noarch.rpm</span></strong></pre>
<h3>The Manager</h3>
<p>The Manageris a little more difficult.  It should be run on a system outside your cluster.  Should the Manager process fail your HA process fails with it.  (<a href="http://en.wikipedia.org/wiki/Quis_custodiet_ipsos_custodes%3F">Quis custodiet ipsos custodes?</a>)</p>
<p>There are a number of required Perl modules.  You may find you have to use CPAN to install these. CPAN will require you install perl-YAML, make and gcc.  (I found this the easiest for CentOS 6.2)  If you use CPAN you will need to tell RPM to skip dependencies.</p>
<ul>
<li>DBD::mysql</li>
<li>Config::Tiny</li>
<li>Log::Dispatch</li>
<li>Parallel::ForkManager</li>
<li>Time::HiRes</li>
</ul>
<pre><strong><span style="color: #339966;"> rpm -i mha4mysql-manager-0.52-0.noarch.rpm --nodeps</span></strong></pre>
<p><strong>This may not be needed.</strong> On some systems, because I installed on a x64 version (as you should be too) I found I had to copy the MHA libraries to the perl lib64 space.  You might want to make simlinks instead.</p>
<pre><strong> <span style="color: #339966;"> cp -crp  /usr/lib/perl5/vendor_perl/MHA  /usr/lib64/perl5/vendor_perl</span></strong></pre>
<p>You only need one configuration file if you are not going to monitor multiple Master/Slave clusters.  You can name this configuration file anything you want.  Change these setting and make sure the directories exist and are writable.</p>
<p>On the server where the Manager will be running:</p>
<pre><strong> <span style="color: #339966;"> vi /etc/MHA.cnf</span></strong>

[server default]
user=<span style="color: #ff0000;">hauser</span>
password=<span style="color: #ff0000;">P@ssw0rd</span>
manager_workdir=<span style="color: #ff0000;">/var/log/masterha</span>
manager_log=<span style="color: #ff0000;">/var/log/masterha/MHA.log</span>
remote_workdir=<span style="color: #ff0000;">/var/log/masterha</span>

[server1]
hostname=<span style="color: #ff0000;">db1</span>

[server2]
hostname=<span style="color: #ff0000;">db2</span></pre>
<p>The MHA will need access to each server so you need to add the user to each.  On all MySQL server add the hauser.</p>
<pre> <strong><span style="color: #339966;"><span style="color: #000000;">mysql&gt;</span> grant all on *.* to 'hauser'@'192.168.%.%'  identified by 'P@ssw0rd'; </span></strong> <strong>mysql&gt;<span style="color: #339966;"> flush privileges;</span></strong><strong><span style="color: #339966;"> </span></strong></pre>
<p>Now is a good time to make sure all the server names resolve on each system and they know their own names.</p>
<p>MHA also need ssh access to each server. You need to create ssh keys and copy to the mysql servers.</p>
<p><strong>Don’t do these steps </strong>if you already have ssh keys installed.</p>
<pre><strong> <span style="color: #339966;">ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ""  </span></strong></pre>
<pre><strong><span style="color: #339966;"> cp ~/.ssh/id_dsa.pub ~/.ssh/authorized_keys</span></strong></pre>
<pre><strong><span style="color: #339966;"> scp -r ~/.ssh <span style="color: #ff0000;">db2:</span></span></strong></pre>
<p>Check if you have ssl working with the masterha_check_ssh tool.  Look for the <strong>OK</strong> after the connect test.</p>
<p>From the Manager server:</p>
<pre><strong> <span style="color: #339966;">masterha_check_ssh  --conf=/etc/MHA.cnf</span></strong>

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]   <span style="color: #339966;"><strong>ok</strong></span>.</pre>
<p>MHA need to control replication so you should test it with masterha_check_repl. This will outout a lot of chat.  Your looking for the ‘MySQL Replication Health is<strong> OK</strong>’ at the end.   You might also pay attention to any warnings.</p>
<pre><strong> <span style="color: #339966;">masterha_check_repl  --conf=/etc/MHA.cnf</span></strong>

---
Thu Dec  1 10:07:22 2011 - [info] Checking slave configurations..
Thu Dec  1 10:07:22 2011 - [warning]  <span style="color: #800000;"><strong>read_only=1</strong></span> is not set on slave db2(192.168.0.11:3306).
Thu Dec  1 10:07:22 2011 - [warning]  <span style="color: #800000;"><strong>relay_log_purge=0</strong></span> is not set on slave db2(192.168.0.12:3306).
---
MySQL Replication Health is <strong>OK</strong>.</pre>
<p><strong>You now have MHA installed</strong>.  If you configure it wrong MHA will give some errors that are not helpful and die. Check your settings again.</p>
<p>If you want MHA to monitor the status of your master server you need to run masterha_manager.  It does not normally run as a daemon.  If masterha_manage is not running your server will not automatically fail over.  This is a weakness in MHA.  You might want to use something like <a href="http://www.linux-ha.org/wiki/Pacemaker">Pacemaker(Heartbeat)</a> to monitor your systems and MHA to do the fail over.  Here is how I make MHA run in the background.</p>
<pre><strong> <span style="color: #339966;">nohup  masterha_manager  --conf=/etc/MHA.cnf &amp;</span></strong></pre>
<p>You can check masterha_manager with masterha_check_status.</p>
<pre><strong> <span style="color: #339966;">masterha_check_status  --conf=/etc/MHA.cnf</span></strong></pre>
<p>Now the magic. If you want to manual fail over you can use masterha_master_switch and tell it the master is alive.</p>
<pre><strong> <span style="color: #339966;">masterha_master_switch  --master_state=alive --conf=/etc/MHA.cnf</span></strong></pre>
<p>If your using another monitoring system like Pacemaker you can have it run this command to automatically fail your master.</p>
<pre><strong> <span style="color: #339966;">masterha_master_switch --master_state=dead --dead_master_host=db1 --conf=/etc/MHA.cnf</span></strong></pre>
<p>If you find I’ve missed something or it works different on your OS please drop me a comment.</p>
<p><img class="Left" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p>&nbsp;</p>
</div>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F2011%2F12%2Finstall-mysql-master-ha-mha-on-centos%2F&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=Install mysql-master-ha (MHA) on CentOS - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/2011/12/install-mysql-master-ha-mha-on-centos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simplified MySQL SSL connections</title>
		<link>http://www.mysqlfanboy.com/2011/11/simplified-mysql-ssl-connections/</link>
		<comments>http://www.mysqlfanboy.com/2011/11/simplified-mysql-ssl-connections/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 23:09:42 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=712</guid>
		<description><![CDATA[In last weeks OurSQL postcast (episode 65)  Sheeri,  Sarah and Jerry talked about making MySQL safe with SSL.  Encryption always seems to be such a confusing subject. I think every database should be using SSL by default.  So, I was wondering just how easily SSL could be setup. Most existing examples I found  setup SSL authentication and encryption.  If you are handling  PCI [...]]]></description>
			<content:encoded><![CDATA[<p>In last weeks OurSQL postcast (<a href="http://technocation.org/content/oursql-episode-66%3A-breaking-news-reels">episode 6</a>5)  <a href="http://en.wikipedia.org/wiki/Sheeri_Cabral" target="_blank">Sheeri</a>,  <a href="http://sarahnovotny.com/" target="_blank">Sarah</a> and Jerry talked about making MySQL safe with SSL.  Encryption always seems to be such a confusing subject. I think every database should be using SSL by default.  So, I was wondering just how easily SSL could be setup.</p>
<p>Most existing examples I found  setup SSL authentication and encryption.  If you are handling  <a href="http://www.elementps.com/merchants/pci-dss-requirements/">PCI DSS</a> or <a href="http://www.hhs.gov/ocr/privacy/hipaa/understanding/srsummary.html">HIPAA</a> data you must encrypt the data on the wire, but passwords are all you need to authenticate the application to the data source.</p>
<pre> # mkdir /etc/mysql/certs
 # cd /etc/mysql/certs</pre>
<p>This looks complicated, it&#8217;s not.  JUST PRESS ENTER when openssl ask you a question.  This will not make you any less secure.  Your data will be encrypted.   Note these keys will expire in three years (1095 days).</p>
<pre> # openssl genrsa 2048 &gt; ca-key.pem
 # openssl req -new -x509 -nodes -days 1095 -key ca-key.pem -out ca-cert.pem
 # openssl req -newkey rsa:2048 -days 1095 -nodes -keyout server-key.pem -out server-req.pem
 # openssl rsa -in server-key.pem -out server-key.pem
 # openssl x509 -req -in server-req.pem -days 1095 -CA ca-cert.pem -CAkey ca-key.pem \
 -set_serial 01 -out server-cert.pem</pre>
<p>With the keys generated you need to tell MySQL to use them. Add these lines to your my.cnf.</p>
<pre> # vi /etc/my.cnf</pre>
<pre> ssl
 ssl-cipher=DHE-RSA-AES256-SHA
 ssl-ca=/etc/mysql/certs/ca-cert.pem
 ssl-cert=/etc/mysql/certs/server-cert.pem
 ssl-key=/etc/mysql/certs/server-key.pem</pre>
<p>Now restart mysql.</p>
<pre> # service mysql restart</pre>
<p>You should see SSL is enabled and mysql sees the keys.</p>
<pre> mysql&gt; show variables like '%ssl%';
 +---------------+----------------------------------+
 | Variable_name | Value                            |
 +---------------+----------------------------------+
 | have_openssl  | <span style="color: #ff0000;"><strong>YES </strong></span> |
 | have_ssl      | <span style="color: #ff0000;"><strong>YES </strong></span> |
 | ssl_ca        | /etc/mysql/certs/ca-cert.pem     |
 | ssl_capath    |                                  |
 | ssl_cert      | /etc/mysql/certs/server-cert.pem |
 | ssl_cipher    | DHE-RSA-AES256-SHA               |
 | ssl_key       | /etc/mysql/certs/server-key.pem  |
 +---------------+----------------------------------+
 7 rows in set (0.00 sec)</pre>
<p>Duplicate these keys and the configuration segment to all your servers.</p>
<p>&nbsp;</p>
<p><strong>Client</strong></p>
<p>If the client system is not a server, copy of the MySQL SSL keys to it was well.  Then, you need to tell the client to use SSL.  Edit your user&#8217;s .my.cnf file and give it the keys too.</p>
<pre> # vi ~/.my.cnf</pre>
<pre>[client]
 ssl
 ssl-cipher=DHE-RSA-AES256-SHA
 ssl-ca=/etc/mysql/certs/ca-cert.pem</pre>
<p>Thats it.  It should be working.  Look for &#8216;Cipher in use&#8217;.</p>
<pre> # mysql -e "\s"</pre>
<pre>mysql Ver 14.14 Distrib 5.1.59, for unknown-linux-gnu (x86_64) using readline 5.1</pre>
<pre> Connection id: 7
 Current database:
 Current user: root@localhost
 SSL: <span style="color: #ff0000;"><strong>Cipher in use</strong></span> is DHE-RSA-AES256-SHA
 ......
 Threads: 1 Questions: 22 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables: 8 Queries per second avg: 2.0</pre>
<p>&nbsp;</p>
<p><strong>Replication</strong></p>
<p>On the master, you need to tell the replication user to require SSL connections. Replace the <em>rep_user</em> with your replication user&#8217;s ID.</p>
<pre> mysql&gt; GRANT USAGE ON *.* TO '<em>rep_user</em>'@'%'  <span style="color: #ff0000;"><strong>REQUIRE SSL</strong></span>;
 mysql&gt; flush privileges;</pre>
<p>and on the slave tell it to connect to the master with SSL.  Then make sure you are still connecting. Change the IP and user name, show here,  to your settings.</p>
<pre> mysql&gt; stop slave;
 mysql&gt; CHANGE MASTER TO master_host='<em>192.168.1.12</em>', master_user='<em>rep_user</em>', \
MASTER_SSL=1, MASTER_SSL_CA = '/etc/mysql/certs/ca-cert.pem' ;
 mysql&gt; start slave;
 mysql&gt; show slave status;</pre>
<p>&nbsp;</p>
<p><strong>Applications</strong></p>
<p>Your application could be written in lots of different languages and I can&#8217;t go over each of them but here are some links to setup up SSL connection to MySQL in several of the most popular.  If you know where there are some better examples, please leave me a comment.</p>
<p><a href="http://mysql-python.sourceforge.net/MySQLdb.html">Python</a></p>
<p><a href="http://code.activestate.com/lists/perl-dbi-users/34958/">Perl</a></p>
<p><a href="http://www.razorsql.com/articles/mysql_ssl_jdbc.html">JDBC</a></p>
<p><img class="alignleft" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F2011%2F11%2Fsimplified-mysql-ssl-connections%2F&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=Simplified MySQL SSL connections - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/2011/11/simplified-mysql-ssl-connections/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The Full Monty- Part 3</title>
		<link>http://www.mysqlfanboy.com/2011/10/the-full-monty-part-3/</link>
		<comments>http://www.mysqlfanboy.com/2011/10/the-full-monty-part-3/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 16:19:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=680</guid>
		<description><![CDATA[This is more boring parts but you must lay a good foundation. MySQL Setup: All the resources must be in place before you configure Pacemaker. The default location for MySQL data is /var/lib/mysql.  You will be moving this to the DRBD file system in /data/mysql.   The default MySQL configuration is in /etc/my.cnf.  I move it [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>This is more boring parts but you must lay a good foundation.</p>
<h3>MySQL Setup:</h3>
<p>All the resources must be in place before you configure Pacemaker. The default location for MySQL data is /var/lib/mysql.  You will be moving this to the DRBD file system in /data/mysql.   The default MySQL configuration is in /etc/my.cnf.  I move it to /data/mysql so updates will move with system fail overs.   To keep life simple I use sym-links to point from /var/lib/mysql and /etc/my.cnf to their new locations.<br />
Install MySQL of your choise on DB1, DB2 and DB3.</p>
<pre># <strong><span style="color: #008000;">rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm</span></strong>
# <strong><span style="color: #008000;">yum -y install Percona-Server-server-51.x86_64 Percona-Server-client-51.x86_64 \
 Percona-Server-shared-51.x86_64 xtrabackup.x86_64</span></strong>
# <strong><span style="color: #008000;">service mysql start</span></strong>
# <strong><span style="color: #008000;">mysql -e "CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so'"</span></strong>
# <strong><span style="color: #008000;">mysql -e "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'"</span></strong>
# <strong><span style="color: #008000;">mysql -e "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'"</span></strong>
# <strong><span style="color: #008000;">service mysql stop</span></strong>
# <strong><span style="color: #008000;">chkconfig mysql off</span></strong></pre>
<p>ON DB1, move MySQL data to the DRBD file system.</p>
<pre># <strong><span style="color: #008000;">df</span></strong></pre>
<pre>Filesystem        1K-blocks   Used Available Use% Mounted on
 /dev/md2           11903664      1633608   9655620   15% /
 /dev/md1             505508        218159    261250    46% /tmp
 /dev/md0             256586         25967    217371    11% /boot
 tmpfs               2037412  16348   2021064    1% /dev/shm
 /dev/drbd1         30477552 176200  28753152    1% /data</pre>
<p>On DB1 and DB3</p>
<pre># <strong><span style="color: #008000;">mkdir /data/mysql</span></strong>
# <strong><span style="color: #008000;">cp -prv /var/lib/mysql/* /data/mysql</span></strong>
# <strong><span style="color: #008000;">mv /var/lib/mysql /var/lib/mysql-empty</span></strong>
# <strong><span style="color: #008000;">ln -s /data/mysql /var/lib/mysql</span></strong>
# <strong><span style="color: #008000;">touch /data/mysql/my.cnf</span></strong>
# <strong><span style="color: #008000;">ln -sf /data/mysql/my.cnf /etc/my.cnf</span></strong>
# <strong><span style="color: #008000;">chown -R mysql.mysql /data/mysql</span></strong>
# <strong><span style="color: #008000;">chmod 644 /data/mysql/my.cnf</span></strong></pre>
<p>On DB2, make it ready for a fail over.</p>
<pre># <strong><span style="color: #008000;">mv /var/lib/mysql /var/lib/mysql-empty</span></strong>
# <strong><span style="color: #008000;">ln -sf /data/mysql /var/lib/mysql</span></strong>
# <strong><span style="color: #008000;">ln -sf /data/mysql/my.cnf /etc/my.cnf</span></strong></pre>
<h4 dir="ltr">Configure MySQL (/data/mysql/my.cnf)</h4>
<p>I have a documented <a href="http://www.mysqlfanboy.com/Files/my.cnf">my.cnf</a> file I start with. You need to change the server-id number on each server.  The minimum setting you will need are:</p>
<pre>[mysqld]
 log-bin=mysql-bin
 server-id=1
 innodb_flush_log_at_trx_commit=2
 sync_binlog=1</pre>
<p>on DB1</p>
<pre># <strong><span style="color: #008000;">service mysql start</span></strong></pre>
<p>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.</p>
<p>If you have skip-name-resolve set you will need to substitute the host names for IP addresses.</p>
<pre># <span style="color: #008000;"><span style="color: #000000;">mysql</span><strong> -h localhost -u root -p
 </strong><span style="color: #000000;"> mysql&gt;</span><strong> DROP USER ''@'db.grennan.com';
 </strong><span style="color: #000000;"> mysql&gt;</span><strong> DROP USER ''@'localhost';
 </strong><span style="color: #000000;"> mysql&gt;</span><strong> GRANT ALL on *.* TO 'root'@'%' IDENTIFIED by 'P@ssw0rd' with GRANT option;
 </strong><span style="color: #000000;"> mysql&gt;</span><strong> GRANT ALL on *.* TO 'root'@'localhost' IDENTIFIED by 'P@ssw0rd' with GRANT option;
 </strong><span style="color: #000000;"> mysql&gt;</span><strong> GRANT ALL ON *.* TO 'tungsten'@'127.0.0.1' IDENTIFIED BY 'P@ssw0rd' WITH GRANT OPTION;
 </strong><span style="color: #000000;"> mysql&gt;</span><strong> GRANT ALL ON *.* TO 'tungsten'@'localhost' IDENTIFIED BY 'P@ssw0rd' WITH GRANT OPTION;
 </strong><span style="color: #000000;"> mysql&gt;</span><strong> GRANT ALL ON *.* TO 'tungsten'@'db.grennan.com' IDENTIFIED BY 'P@ssw0rd' WITH GRANT OPTION;
 </strong><span style="color: #000000;"> mysql&gt;</span><strong> GRANT ALL ON *.* TO 'tungsten'@'db2.grennan.com' IDENTIFIED BY 'P@ssw0rd' WITH GRANT OPTION;
 </strong><span style="color: #000000;"> mysql&gt;</span><strong> GRANT ALL ON *.* TO 'tungsten'@'db3.grennan.com' IDENTIFIED BY 'P@ssw0rd' WITH GRANT OPTION;
 </strong><span style="color: #000000;"> mysql&gt;</span><strong> flush privileges;</strong></span></pre>
<p>Now that we can access MySQL from any of the servers we need to prepare each as a master and replication.  We can fix DB1 and then copy all of the data tables to the other servers.</p>
<pre><span style="color: #000000;"> mysql&gt;</span><strong><span style="color: #008000;"> reset master; reset slave;
 </span></strong><span style="color: #008000;"><span style="color: #000000;"> mysql&gt;</span></span><strong><span style="color: #008000;"> exit</span></strong>
# <strong><span style="color: #008000;">service mysql stop</span></strong>
# <strong><span style="color: #008000;">rsync -rog --delete /data/mysql  root@db2:/data</span></strong>
# <strong><span style="color: #008000;">rsync -rog --delete /data/mysql  root@db3:/data</span></strong></pre>
<p>Remember we put the my.cnf file in the /data/mysql directory.  We need to make sure each has a unique server_id number.</p>
<pre># <strong><span style="color: #008000;">vi /etc/my.cnf</span></strong>
 server_id = 1
# <strong><span style="color: #008000;">ssh db2</span></strong>
# <strong><span style="color: #008000;">vi /etc/my.cnf</span></strong>
 server_id = 2
# <strong><span style="color: #008000;">exit</span></strong>
# <strong><span style="color: #008000;">ssh db3</span></strong>
 server_id = 3
# <strong><span style="color: #008000;">exit</span></strong></pre>
<p>Rather than type the password for MySQL each type we connect.  We can also setup a private my.cnf to prevent this. This should connect you to the master (RW) server from each host.</p>
<pre># <strong><span style="color: #008000;">vi ~/.my.cnf</span></strong></pre>
<pre>[Client]
 user=root
 password=P@ssw0rd
 host=db.grennan.com
 socket=/data/mysql/mysql.sock</pre>
<pre># <strong><span style="color: #008000;">scp .my.cnf db2:.</span></strong>
# <strong><span style="color: #008000;">scp .my.cnf db3:.</span></strong></pre>
<p>&nbsp;</p>
<p><strong>Next up,  Configuring Heartbeat and making failover work!</strong></p>
<p>&nbsp;</p>
<p><img class="alignnone" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p>&nbsp;</p>
</div>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F2011%2F10%2Fthe-full-monty-part-3%2F&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=The Full Monty- Part 3 - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/2011/10/the-full-monty-part-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What can I DROP?</title>
		<link>http://www.mysqlfanboy.com/2011/09/what-can-i-drop/</link>
		<comments>http://www.mysqlfanboy.com/2011/09/what-can-i-drop/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 17:35:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HOW TO]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=675</guid>
		<description><![CDATA[So you have inherited a MySQL server and no one know what applications are use what databases.   Space is every tight and every night transactions logs almost fill your hard disk.  The server was once used as a replication server and it seems every database the company uses is duplicated here. You could do [...]]]></description>
			<content:encoded><![CDATA[<p>So you have inherited a MySQL server and no one know what applications are use what databases.   Space is every tight and every night transactions logs almost fill your hard disk.  The server was once used as a replication server and it seems every database the company uses is duplicated here.</p>
<p>You could do a full dump, drop everything and wait for the requests to restore. (This might be OK on a test database.)</p>
<p>We could ask MySQL for all the databases that have tables that have been updated in the last 30 days.</p>
<pre>$ mysql information_schema -e  \
"select DISTINCT TABLE_SCHEMA as NAME from TABLES
  WHERE UPDATE_TIME IS NOT NULL and UPDATE_TIME &gt; NOW() - INTERVAL 30 DAY"  \
&gt; Databases</pre>
<p>But this only gives a list of databases that have changed.  What about tables that are only read from?</p>
<p>Bin-Logs don&#8217;t help because they too only have updates.  What we really need is a long snapshot of the general log. But, starting the general log will just fill your disk space even more.</p>
<p>As long as all queries are remote we can use tcpdump.</p>
<p>Filter all the MySQL connections for  &#8216;FROM tablenames&#8217;.</p>
<pre>$ tcpdump -i eth1 -s 0 -l -w - dst port 3306 | strings | \
 sed -n 's/\(.*\)\(from.*\)/\2/p' | awk '{print $2}' &gt; TableList
 $ cat TableList | sort | uniq &gt; ShortList</pre>
<p>Some of the queries may reference databases.tablename so we can filter out the database names and add them to your Database list.</p>
<pre>$ cat TableList | sed -n 's/\./ /p' | awk '{print $1}' | sort | uniq &gt;&gt; Databases</pre>
<p>Now for the queries that only use table names. We need to find the database each belongs to.  This isn&#8217;t completely accurate because the table name may be in more then one databases.</p>
<pre>$  for x in `cat TableList | sort | uniq` ;
 do
 mysql information_schema -e "select TABLE_SCHEMA from TABLES where TABLE_NAME='$x'\G"  \
 | grep TABLE | awk '{print $2}' ;
 done | sort | uniq &gt;&gt; Databases</pre>
<p>To create the final list of database that should not be dropped.</p>
<pre>$ sort Databases | uniq &gt; KEEPTHESE ; cat KEEPTHESE</pre>
<p>Now you can do the deed with some confidence your not removing anything being used.</p>
<p>&nbsp;</p>
<p><img class="alignleft" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>P.S.  Did I tell you, Never do anything you can&#8217;t reverse.   Make a BACKUP FIRST!</p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F2011%2F09%2Fwhat-can-i-drop%2F&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=What can I DROP? - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/2011/09/what-can-i-drop/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Full Monty- Part 2</title>
		<link>http://www.mysqlfanboy.com/2011/08/the-full-month-part-2/</link>
		<comments>http://www.mysqlfanboy.com/2011/08/the-full-month-part-2/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 19:39:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://www.mysqlfanboy.com/?p=651</guid>
		<description><![CDATA[Installing DRDB in CentOS 5.6. In Part 1 I when through the process of preparing a number of CentOS 5.6 servers. Now make the services they’ll preform more stable. High Availability (HA) I’ll be presenting two ways to provide redundant data and high available services. First, Pacemaker &#8211; with DRDB will duplicate your data at [...]]]></description>
			<content:encoded><![CDATA[<p>Installing DRDB in CentOS 5.6.
</p>
<p>In <a href="http://www.mysqlfanboy.com/2011/08/the-full-monty-centos-5-5-drbd-pacemaker-mysql-tunsten-replication-and-more/">Part 1</a> I when through the process of preparing a number of <a href="https://www.centos.org/">CentOS </a>5.6 servers. Now make the services they’ll preform more stable.</p>
<h3>High Availability (HA)</h3>
<p>I’ll be presenting two ways to provide redundant data and high available services. First, Pacemaker &#8211; with <a href="www.drbd.org">DRDB </a>will duplicate your data at the disk partition level and watch for failures. Should the hardware failure, Pacemaker will take all the needed steps to start MySQL on the Hot Stand By (HSB). This is not perfect. Should someone run ‘rm *’ or drop a database DRDB will duplicate the loss on the HSB.</p>
<p>In another part, I’ll use <a href="http://code.google.com/p/tungsten-replicator/">Tungsten replicator</a>. It offers a set of features that surpass the built-in MySQL replicator. The community version of Tungsten has global transaction IDs so even with many slaves, global transactions IDs make turning a slave into the master easy. Tungsten replicator is not a HA service. You have to manually fail to a new master. Tungsten Enterprise (if you have money) solves all the issues. With the tools the enterprise version supplies you can easily migrate the “master” server to any slave.</p>
<h3>HA with Pacemaker:</h3>
<p>Neither RedHat or CentOS supply PaceMaker packages. Redhat support their own propitiatory clustering suite. CentOS is suck trying to maintain compatibility with Redhat while still giving you a high availability system. CentOS does supply heartbeat and openais but not pacemaker. Thankful Redhat helps out by supporting the <a href="http://fedoraproject.org/">Fedora project</a> and in turn Fedora provide an <a href="http://www.google.com/url?q=http%3A%2F%2Fwww.clusterlabs.org%2Frpm%2F&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNF0XcJrX5pKiMfKi3GCKycEfrMosA">EPEL repository for Redhat 5</a>.</p>
<p>The Pacemaker packages in Fedora&#8217;s EPEL directories are built against some additional packages that don&#8217;t exist on vanilla RHEL/CentOS installs. For more information on EPEL, see <a href="http://fedoraproject.org/wiki/EPEL/FAQ">http://fedoraproject.org/wiki/EPEL/FAQ</a> So before installing Pacemaker, you will first need to tell the machine how to find the EPEL packages Pacemaker depends on. To do this, download and install the EPEL package that matches your RHEL/CentOS version.</p>
<p>LINBIT is the primary maintainer of DRBD and offers a product and service portfolio for exactly what we are building here. They have produced a <a href="http://www.google.com/url?q=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dd0jXgrtkVJ4">video </a>that takes you through this same process using the the DRDB Console Manager. I&#8217;m going to take you through the same process by hand. I hope this way you will better understand the management touch points.</p>
<h3>DRBD Installation:</h3>
<p>I build two computer alike in every way (clones) and use DRBD to sync the data partitions on each. CentOS provides the packages needed.</p>
<pre><strong> # <span style="color: #008000;">wget http://www.clusterlabs.org/rpm/epel-5/clusterlabs.repo</span>  
 # <span style="color: #008000;">mv clusterlabs.repo /etc/yum.repos.d</span>  
 # <span style="color: #008000;">rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm</span>  
 # <span style="color: #008000;">yum -y install pacemaker.x86_64 heartbeat.x86_64 drbd83.x86_64 kmod-drbd83.x86_64</span></strong>
<strong> # <span style="color: #008000;">/sbin/chkconfig --add heartbeat</span>  
 # <span style="color: #008000;">depmod</span>  
 # <span style="color: #008000;">modprobe drbd</span></strong></pre>
<h3>DRBD Configuration:</h3>
<p>On both machines (db1 and db2), edit the DRBD configuration file. The host names must be the save as returned by &#8216;hostname&#8217; command. You may also need to edit the host name in <strong>/etc/sysconfig/network</strong>. I have highlighted parts you will need to edit in red.</p>
<p>To replace the shared-secret, select at least half of the characters from the &#8220;63 random alpha-numeric characters&#8221; from Gibson Research <a href="http://www.grc.com/passwords.htm">Ultra High Security Passwords</a>.</p>
<pre><strong> # <span style="color: #008000;">vi /etc/drbd.conf</span></strong></pre>
<pre> include "drbd.d/global.conf";
 include "drbd.d/*.res";</pre>
<pre><strong># <span style="color: #008000;">vi /etc/drbd.d/global.conf</span></strong></pre>
<pre><span style="color: #0000ff;">global { usage-count yes; }
common { startup { degr-wfc-timeout 0; }
net { cram-hmac-alg sha1; shared-secret <span style="color: #ff0000;">R4x2alEkxtIg2kzbXqUL6l4uoTI7Ab7Qt</span>; }
disk { on-io-error detach; } }</span></pre>
<pre># <strong><span style="color: #008000;">hostname</span></strong>
 db1.grennan.com</pre>
<pre><strong># <span style="color: #008000;">vi /etc/drbd.d/db.res</span></strong></pre>
<pre><span style="color: #0000ff;">resource db { protocol C; syncer { rate 10M; }
on <span style="color: #ff0000;">db1.grennan.com</span> { device /dev/<span style="color: #ff0000;">drbd0</span>; disk /dev/<span style="color: #ff0000;">md3</span>; address <span style="color: #ff0000;">192.168.4.1</span>:7788; flexible-meta-disk internal; }
on <span style="color: #ff0000;">db2.grennan.com</span> { device /dev/<span style="color: #ff0000;">drbd0</span>; disk /dev/<span style="color: #ff0000;">md3</span>; address <span style="color: #ff0000;">192.168.4.2</span>:7788; flexible-meta-disk internal; } }</span></pre>
<pre><strong> # <span style="color: #008000;">scp -r /etc/drbd.d db2:/etc</span>  # <span style="color: #008000;">scp -r /etc/drbd.conf db2:/etc</span></strong></pre>
<h3>Manage DRDB processes:</h3>
<p>If the disk was formatted during the OS install you may need to erase the ext3 file system info on both DB1 and DB2.</p>
<pre><strong> # <span style="color: #008000;">umount /data</span>  # <span style="color: #008000;">dd if=/dev/zero of=/dev/<span style="color: #ff0000;">md3</span> count=2048</span></strong></pre>
<p>Write the DRBD meta data on both DB1 and DB2.</p>
<p># <span style="color: #008000;">drbdadm create-md db</span></p>
<p>On &gt;&gt;&gt; DB1 only &lt;&lt;&lt;</p>
<pre><strong>  # <span style="color: #008000;">drbdadm adjust db</span> </strong>
<strong>  # <span style="color: #008000;">drbdsetup /dev/<span style="color: #ff0000;">drbd0</span> primary -o</span></strong>
<strong>  # <span style="color: #008000;">service drbd start</span></strong></pre>
<p>On DB2</p>
<p><strong>  #<span style="color: #008000;"> service drbd start</span></strong></p>
<p>Did you miss the &gt;&gt;&gt; DB1 only &lt;&lt;&lt; above?   If you did you&#8217;ll need to re-run &#8216;drbdsetup /dev/drbd0 primary -o&#8217; on DB1.</p>
<p><strong><span style="color: #ff0000;">WAIT until the sync process completes.</span></strong></p>
<p>Back on DB1 create the file system and mount it.</p>
<pre><strong>  # <span style="color: #008000;">mkdir /data</span> </strong>
<strong>  # <span style="color: #008000;">mkfs -j /dev/<span style="color: #ff0000;">drbd0</span></span></strong>
<strong>  # <span style="color: #008000;">tune2fs -c -1 -i 0 /dev/<span style="color: #ff0000;">drbd0</span></span></strong>
<strong>  # <span style="color: #008000;">mkdir /data</span></strong>
<strong>  # <span style="color: #008000;">mount -o rw /dev/<span style="color: #ff0000;">drbd0</span> /data</span></strong></pre>
<p>Don&#8217;t forget to make the /data directory on DB2.</p>
<pre><strong>  # <span style="color: #008000;">mkdir /data/mysql</span></strong>
<strong>  # <span style="color: #008000;">cat /proc/drbd</span></strong></pre>
<pre>version: 8.3.8 (api:88/proto:86-94)
 GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:09</pre>
<pre>1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----
 ns:2433920 nr:0 dw:0 dr:2433920 al:0 bm:148 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:28530088
 [==&gt;.................] sync'ed: 21.9% (27860/30236)M delay_probe: 757
 finish: 4:57:11 speed: 1,248 (6,404) K/sec</pre>
<p>In the next post I’ll go through installing MySQL in preparation for configuring Pacemaker. Then I’ll show you how to test fail over.</p>
<p>In the next part I will go over setting up MySQL.</p>
<p><img class="alignleft" src="http://mark.grennan.com/images/MarkGrennanSigniture.bmp" alt="" width="166" height="69" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.mysqlfanboy.com%2F2011%2F08%2Fthe-full-month-part-2%2F&amp;count=none&amp;via=MySQLFanBoy&amp;related=MySQLFanBoy:Site+Twitter+account&amp;text=The Full Monty- Part 2 - MySQL Fanboy" class="twitter-share-button">Tweet</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlfanboy.com/2011/08/the-full-month-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

