Sunteți pe pagina 1din 8

DRBD and MySQL - Virtualbox Setup — DatabaseJournal.

com Page 1 of 8

IT Professionals Developers Solutions eBook Library Webopedia Login Register

Free Newsletters:
DatabaseDaily
Search Database Jour

MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

Database Journal | DBA Support | SQLCourse | SQLCourse2

Best Practices for Developing a Web Site: Checklists, Tips, Strategies & More. Download Exclusive eBook N

Customer Service Engineer


Next Step Systems
US-NC-Winston-Salem

Post A Job | Post A


» Database Journal Home
Resume
» DBA Videos
» Database Articles
Featured Database Articles
» Database Tutorials
MS SQL
MYSQL
Oracle
MS Access
MySQL January 4, 2010
DB2 DRBD and MySQL - Virtualbox Setup
» RESOURCES
By Sean Hull
Database Tools
SQL Scripts & Samples Introduction
Links
» Database Forum DRBD is a Linux project to provide a
» DBA Jobs real time distributed filesystem.
Part two of this series will dig deep
» Sitemap
into a real-world installation
News Via RSS Feed example. We'll use Sun's virtualbox
software to create a couple of VMs,
then configure those VMs with
DRBD, and finally install and test
MySQL running on volumes sitting
on DRBD.

http://www.databasejournal.com/features/mysql/article.php/3856061/DRBD-and-MySQL-... 2/24/2011
DRBD and MySQL - Virtualbox Setup — DatabaseJournal.com Page 2 of 8

Virtualbox - An Easy and


Be a Marketplace Powerful VM Solution
Partner
Sun has a great free virtual machine
solution called Virtualbox. There
Visit the Internet.com are many such options, but I chose
eBook Library for theirs because it runs on Linux,
Technology Professionals Windows and Mac, so it should work
for everyone.

The download can be found here:


Business Insurance for
the IT services industry

Your trusted Web Host


since 1997
MARKETPLACE

Business EMail Business On Main: Online Commu


Free Online Tools and Resources To Help
Grow Your Business. Join Today!
www.BusinessOnMain.com
Business Insurance for
the IT services industry
Network Management Software
Discover, Map, Monitor & Manage all net
devices, Apps, AD, Services, etc. Try Fre
Edition
www.OpManager.com

Bandwidth Monitoring w/ NetFlow


Analyzer
Monitor Bandwidth, Identify top talkers,
better capacity planning. Try Now!
www.NetFlowAnalyzer.com

http://www.virtualbox.org/wiki/Downloads

It of course comes with a simple GUI installer, so I won't go through that in too m
detail. That is pretty straightforward. Once you have that installed, fire it up and
run through the steps to create a vm. Since we will also be installing CentOS on
virtual machines, I recommend you go find that here:

http://mirror.centos.org/centos/5/isos/

Create Your VMs


I went with penguin names. The first host is called adelie, and the second
african. The steps are as follows:

1. Create the vm using the virtualbox GUI by clicking "New". A wizard will tak
you through the process. Enter the name, specify "Linux" as the OS, and sele
Redhat 64 bit as the OS. Unfortunately it won't install that for you too, but it
wouldn't really be a true vm if it did that for you. Leave base memory, boot h
disk, create new hard disk, etc. all at their defaults. It creates an 8GB disk an
left that at default too. Then click finish and it will create the virtual
finish again and it will create the vm.

http://www.databasejournal.com/features/mysql/article.php/3856061/DRBD-and-MySQL-... 2/24/2011
DRBD and MySQL - Virtualbox Setup — DatabaseJournal.com Page 3 of 8

2. You'll need to add a second disk for your DRBD use. A small 25M disk will b
fine. Click the "Settings" for your new vm, and then select the "Storage" tab.
simplicities sake we used a new SCSI controller. Click the add disk button a fe
times until the wizard comes up. Click "Create". Use defaults, and give it a na
like adelie_data.vdi, then make it 25M in size.

3. We'll also need to configure the networking interface. By default, virtualbox


makes it NAT. This doesn't allow us to see other machines in the sandbox. So
click the "Network" tab, and select "Bridged Adapter" from the popup menu.

4. Per our recommendation above, if you haven't already, download your Cent
ISO for 5.4.

5. We'll also need to specify the ISO media. This can be a little tricky as the
interface is a little odd in this regard. Go back to the "Storage" tab, and
the CD/DVD symbol under IDE Controller. Click the little folder icon on the rig
hand side, and a popup comes up. If you don't see your ISO image, use the "
button, and find your ISO and select it. The virtualbox will treat your
mounted CD image.

6. Start your engines. That's right, finally we can start the vm. Hopefully the
CentOS installer comes up. If you have trouble, use the disk symbol at the
bottom of the window, click for the menu, and select your DVD ISO of CentOS

7. Install CentOS 5.4. Run through the screens and click OK.

8. Verify and start your network. Hopefully this has already happened by defa
with DHCP. See also these commands:
$ /sbin/ifconfig eth0
$ /sbin/ifup eth0

You'll now need to run through these same eight steps again to create the second
we called it african.

Install DRBD on both Nodes

1. Use yum to install the drbd tools, and the kernel module:
internet.commerce
$ yum install drbd83.x86_64
Be a Commerce Partner $ yum install kmod-drbd83.x86_64
VPS Hosting
Liability Insurance 2. Install the mysql server software:
Televisions
Calling Cards $ yum install mysql-server.x86_64
Virtual Server
Host your Site 3. Install emacs:
Prepaid Phone Card
Site Hosting $ yum install emacs
Desktop Computers
Promote Your Website
Web Hosting 4. Configure drbd.conf as follows (same on both boxes). Note the IP addresse
Phone Cards device and disk specification. If you created your virtualbox just like we
Business Liability
should all be the same. IP address will still depend on your DHCP server.
Website Hosting
common {
protocol C;
}
resource sean {
on adelie {
device /dev/drbd0;
disk /dev/sda1;

http://www.databasejournal.com/features/mysql/article.php/3856061/DRBD-and-MySQL-... 2/24/2011
DRBD and MySQL - Virtualbox Setup — DatabaseJournal.com Page 4 of 8

meta-disk internal;
address 192.168.0.106:7789;
Nokia CEO Warns of
}
Sinking Smartphone on african {
Business device /dev/drbd0;
disk /dev/sda1;
Google Updates meta-disk internal;
Chrome 9 Security, address 192.168.0.105:7789;
Again }
}
Is Microsoft Planning a
Management Shakeup?
Start DRBD
This part turned out to be a huge struggle. I configured it, but tried over and ove
internet.com avail to get things working. It turned out that the firewall that Linux by default in
IT blocked the ports 7789 on both machines. So DRBD couldn't reach each other on
Developer two nodes. This failed silently and repeatedly and all I knew was that it wasn't
Internet News
Small Business
connecting. So be sure to disable iptables. Since these are virtual boxes, I recom
Personal Technology just deleting the file: /etc/rc.d/rc3.d/S08iptables
Search internet.com Use fdisk to create a partition roughly 25M in size on each node.
Advertise
Corporate Info $ fdisk /dev/sda
Newsletters
Tech Jobs
E-mail Offers Use drbdadm to create the initial mirrored device as follows:
$ drbdadm create-md sean

This will synchronize all data between the two volumes for the first time. Note th
you have data you want to preserve you should (a) do a backup of it of
(b) perform this step on the node whose data you want to preserve!
$ drbdadm -- --overwrite-data-of-peer primary sean

Verify syncronization with:


$ watch cat /proc/drbd

Create a filesystem in the usual way:


$ mkfs.ext3 /dev/drdb0

Mount it on /mnt/mysql (create that dir if necessary):


$ mount /dev/drbd0 /mnt/mysql

Configure MySQL and Start


Edit the /etc/my.cnf file and set the datadir as follows:
datadir=/mnt/mysql

We'll simple start mysql manually now:


$ mysqld_safe &

Let's create a table and add a row:


$ mysql
mysql> use test;
mysql> create table sean_test (c1 varchar(64));
mysql> insert into sean_test values ('hi there');
mysql> commit;
mysql> quit

http://www.databasejournal.com/features/mysql/article.php/3856061/DRBD-and-MySQL-... 2/24/2011
DRBD and MySQL - Virtualbox Setup — DatabaseJournal.com Page 5 of 8

Test Switching to the Other Node


To verify what's happening on the other node you'll need to "promote" it to being
primary. Do the following:

On your current primary do:


$ ps auxw | grep mysql
$ kill <procid>

$ umount /mnt/mysql

$ drbdadm secondary sean

Then on the other node do:


$ drbdadm primary sean

Mount it:
$ mount /dev/drbd0 /mnt/mysql

Start MySQL:
$ mysqld_safe &

Lastly login and see your change:


$ mysql
mysql> use test;
mysql> select * from sean_test;
mysql> quit

Conclusion
DRBD is some sophisticated technology. Luckily, with today's VM technology such
Sun's Virtualbox, we can set up a couple of virtual machines quite easily, and test
the technology. We've tried to break that whole process down into really simple s
You should be able to follow those and get your whole DRBD setup in no time. H
the lessons we learned in the process will save you some time.

In our next installment of this series, we'll explain how to set up heartbeat to han
failover automatically and gracefully. This is the piece that we describe in "test
switching to the other node" above. Heartbeat will automatically perform all of th
steps, and determine when a node is out of commission.

» See All Articles by Columnist

Sean Hull

Tools:

Add databasejournal.com to your favorites

Add databasejournal.com to your browser search box


IE 7 | Firefox 2.0 | Firefox 1.5.x

http://www.databasejournal.com/features/mysql/article.php/3856061/DRBD-and-MySQL-... 2/24/2011
DRBD and MySQL - Virtualbox Setup — DatabaseJournal.com Page 6 of 8

Receive news via our XML/RSS feed

MySQL Archives

3 Comments (click to add your comment)

By Joe Tole January 4 2010 11:34 AMPDT

This is a very bad idea on a few aspects. First off, ext3 file system will lead to problems. This is not
cluster file system designed to be written simultaneously by two machines corrupt inodes will stack v
quickly, You should format with either ocfs2 or gfs2 as these file systems are designed to written to
same time from many different machines. Secondly, mysql is not designed to run with
not in this type of setup and that is just asking for errors. I don't know if there is a shared disk option
but if you are running on two hosts then you are better off with replication, in the case where you wa
writes to either host, then multi master replication. If you have 3 or more then look into mysql
which case all allow writes by default.

Reply to this comment

Reply by Hohlraum January 4 2010 3:17 PMPDT

Did you even RTFA? I'm gunna guess no.

By No... January 4 2010 2:39 PMPDT

NO, he's configuring active/passive. This is much safer than using mysql replication (which can lose
transactions).
Read about why Sun recommends and supports DRBD for MySQL clustering:
http://www.mysql.com/products/enterprise/drbd.html

What is a bad idea, though, is using virtualbox. OK for testing, but don't expect decent

Reply to this comment

Comment and Contribute

Your name/nickname

Your email

XHTML: You can use these tags: <b> <u> <i>

(Maximum characters: 1200). You have 1200 characters left.

http://www.databasejournal.com/features/mysql/article.php/3856061/DRBD-and-MySQL-... 2/24/2011
DRBD and MySQL - Virtualbox Setup — DatabaseJournal.com Page 7 of 8

Please type the alphanumeric characters above and click "Submit" to continue.What's this?

I cannot read this. Please generate a New Image

See our comment policy.

Submit Your Comment

The Future of IT Continuity: Check out this webcast to see what it will take to get there.
Get a free identity and access management assessment by Quest Software and the Aberdeen
Microsoft Article: Enterprise Social Computing with Microsoft SharePoint 2010. Learn
How much will an IT security breach cost you? IBM and industry leaders share their
Virtual Event: The Future of IT Continuity. Register now to see what will happen to IT

Latest Forum Thread


MySQL Forum
Topic By Replies Updated
Download for free? londonbabe 1 February 8th, 04:26
problem with Lock table engegnerring 0 February 6th, 05:38
Selecting based on bitflags Aza 1 February 4th, 02:57
not in tab1 or not in tab2 sql 0 January 11th, 03:47

http://www.databasejournal.com/features/mysql/article.php/3856061/DRBD-and-MySQL-... 2/24/2011
DRBD and MySQL - Virtualbox Setup — DatabaseJournal.com Page 8 of 8

The Network for Technology Professionals

Search:

About Internet.com
Copyright 2011 QuinStreet Inc. All Rights Reserved.

Legal Notices, Licensing, Permissions, Privacy Policy.


Advertise | Newsletters | E-mail Offers

Solutions
Whitepapers and eBooks
PHP for Windows Showcase MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Resource: PHP for Windows Showcase

Webcasts
Software License Operations - Cleaning Up the Backoffice MORE WEBCASTS, PODCASTS, AND VIDEOS

Downloads and eKits


Display Your Commitment to Software Quality With the Windows 7 Logo! MORE DOWNLOADS, EKITS, AND FREE TRIALS

Tutorials and Demos


Exceptional Web Experiences MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
Internet.com Hot List: Get the Inside Scoop on IT and Developer Products

http://www.databasejournal.com/features/mysql/article.php/3856061/DRBD-and-MySQL-... 2/24/2011

S-ar putea să vă placă și