Compile and Configure DRBD

Published 12/21/2007 by Andy in MySQL

This will compile and install DRBD on Fedora 8. The following steps were run against a bare Fedora system, kernel 2.6.23.9-85.fc8, and DRBD 8.2.1.

Prework

Before we can setup DRBD, you will need at least one raw partitioned disk device (can be LVM partition) and a dedicated network interface that will be used for DRBD synch traffic only. If you are following along the Building MySQL Service Cluster on VMware, our raw disk was already created and partitioned as /dev/sbd1 and the private, host-only VMware network was added with addresses in teh 10.0.0 subnet, with fedora1 as 10.0.0.11 and fedora2 as 10.0.0.12.

Compile DRBD

First thing is first, you will need the following if they are not already installed on a vanilla install of Fedora

gcc
flex
kernel-headers
kernel-devel
rpm-build

Now would also be a good time to update your kernel, since DRBD runs in two componets, one of which is a kernel module. To update your kernel for the first time:

yum install kernel

After it is installed, reboot, then run the following:

yum upgrade kernel-headers kernel-devel flex gcc rpm-build

Download the current DRBD source, and build and install:

cd /tmp
get http://oss.linbit.com/drbd/8.2/drbd-8.2.1.tar.gz
tar xvzf drbd-8.2.1.tar.gz
cd drbd-8.2.1
make tools
make module
make install

To make sure install works correctly, confirm that modprobe returns nothing, and /proc/drbd returns the version:

modprobe drbd
cat /proc/drbd

Repeat all of the above steps on the other node(s) that will be sharing resources, or you can create an RPM on this machine with:

make rpm

Two RPM's will be created, on for the userland tools and the other for the kernel module. Both will be located under./dist/RPMS/i386/

drbd-8.2.1-3.i386.rpm drbd-km-2.6.23.9_85.fc8-8.2.1-3.i386.rpm 

SCP and then run these two RPMs on the other machine. Don't forget to run modprob and check the version as well to ensure things are working properly.

Configure

With DRBD modules installed on both machines, it is time to configure each virtual machine's /etc/drbd.conf file. Easiest way to manage this, is to setup one machine, and then scp the config file to the other.

You can view the minimal config example from the drbd.conf man page. In our setup of a MySQL Service Cluster, we will call our single DRBD resource, mysql1. The configuration file we will be using:

global { usage-count yes; }
common { syncer { rate 10M; } }
resource mysql1 {
protocol C;
net {
cram-hmac-alg sha1;
shared-secret "ShareNothing";
}
on fedora1 {
device /dev/drbd1;
disk /dev/sdb1;
address 10.0.0.11:8000;
meta-disk internal;
}
on fedora2 {
device /dev/drbd1;
disk /dev/sdb1;
address 10.0.0.12:8000;
meta-disk internal;
}
}

drbd.conf file is broken into sections wrapped in {} curly brackets. The common {} section applies default options to sections further down. In ours, syncer {rate 10M;} will set the the syncer rate of 10Mbits for all other net {} sections that don't explictly set the rate. If you are running 100Mbit private network between hosts, change this value to 100M.

shared-secret - This sets our shared password among all hosts in the DRBD cluster. This is really necessary if you are running the DRBD communications over public, unsecured networks.

on hostname {} - This section is for configuring each host resource. The hostname after each must exactly match the output of uname -n. In our configuration, the other differences between each host section will be the address option, which specifies the IP address and port used by DRBD to transfer it's sync data, and the hostname.

This setup skips over several other configuration options for DRBD, namely the handlers and what to do if an error occurs. These can be further refined and configured later on. For now we will scp our configuration file to our two virtuals and do the initial synch and formating of the drbd1 device.

Initialize our DRBD device

With our config on both virtuals, now we need to initialize our DRBD device. We will preform the device initialization on only one host, fedora1 in our example. All commands will be run using drdbadm command.

On fedora1 only:

drbdadm create-md

This initializes the meta-data DRBD uses internal to manage the synch process, and is only run once per resource configuration. The first time, you will also be prompted to submit in to the usage counters by pressing enter.

v08 Magic number not found
v07 Magic number not found
About to create a new drbd meta data block
on /dev/sdb1.

==> This might destroy existing data! <==

Do you want to proceed?
[need to type 'yes' to confirm] yes

Creating meta data...
initialising activity log
NOT initialized bitmap (256 KB)
New drbd meta data block sucessfully created.
success

If all goes well, you will see output like above. You will have to type yes at the prompt since you will be destroying all data on the /dev/sdb1 partition. Next run adjust to ensure the adjust command to sync configuration of the device with the config file.

drbdadm adjust mysql1

This should produced no output if all is well. Now we must seize control of the drbd1 device on the current node, so we can further intialize the device. This is done with the following drbdsetup command:

drbdadm primary all

Now owning the drbd device on fedora1, we need to format the filesystem and mount it somewhere useful. For use that will be a root directory /mysql

mkfs.ext3 /dev/drbd1
mkdir /mysql
mount /dev/drbd1 /mysql

On our secondary server, fedora2, we need to create our DRBD device and setup the meta-data as well, so run the following there:

drbdadm create-md
mkdir /mysql

 

Primary/Secondary State

If you run the following on fedora1:

drbdadm state all

You should get:

Primary/Secondary

Meaning the mysql1 resource is currently the primary owner of (and the only node that can write) /dev/drbd1 device.

To move the resource to be primary on fedora2, we must first unmount and then change the state on fedora1, them reverse the process on fedora2:

#fedora1
touch /mysql/Hello
umount /mysql
drbdadm secondary all

You can confirm the resource is in a secondary state by running drbdadm state all.

#fedora2
drbdadm primary all
mount /dev/drbd1 /mysql1

Checking the state on fedora2 will now show it as primary, and you should also see our Hello file.

 

 

 


This is a guide to configure and install Fedora 8 as guest virtual machine in VMware Server. To download VMware Server, you will need to create a login and obtain a free license key from VMware's website. This was done using the Windows version of VMware Server 1.0.4.  Steps should be the same for Linux based host OS's.

 

A New Virtual Machine

With VMware Server installed, launch the VMware Server console, then click 'File->New..->Virtual Machine...'.

 

Choose 'Custom' so we can configure the SCSI adaptor type.

 

Set your guest operating system as 'Linux' and 'Other Linux' as the version.

 

Call the VM whatever you like, I used 'Fedora1', setting the location to a place with enough space to hold your virtual disk (~4 GB free space).

Accept the defaults for 'Access Rights', 'Memory for VM' and 'Startup / Shutdown' options.

 

Change the SCSI adapter to 'LSI Logic' instead of default 'BusLogic', otherwise you will run into problems when the installer trys to load the ata_piix driver.

Set the number of CPU's to match the number of physical CPU on the host machine.

Network type should be the default, 'Use bridged networking' to allow the guest to have network access outside of the host.

'Create a new virtual disk', disk type 'SCSI', adjust the size to your liking, and uncheck 'Allocate all disk space now' to keep the HD image smaller. That is it.

Selecting the guest from the inventory list, click 'Edit virtual machine settings'.

 

Uncheck 'Connect at power' for the floopy drive (you will never need).

 

Finally, select the CD-ROM drive, and set 'Use ISO image', browsing to the Fedor 8 install DVD. Ok will get you back to the console. Finally, click 'Start this virtual machine'

No GUI Fedora 8 installation 

 

At the GRUB/Welcome to Fedora 8! prompt, select 'text mode' install or upgrade option

Skip the media check, and accept the defaults until 'Configure Network Interface'.

 

Hit space over 'Enable IPv4'.

 

Choose manual and set the hostname to whatever you like.

 

Packages

To do a minimalist install (no GUI, no X, no Gnome), uncheck all packages, and select 'Customized software selection'

 

Unselect all package groups, except Editors. View the details of 'Editors' by pressing F2, making sure vim-enhanced is selected. After a bit, you will have a fresh, clean guest VM install of Fedor 8.

Copy Virtual Machine and Never Run Setup Again

Shutdown the guest. Copy the location folder to a new name..e.g.

cp Fedora1 Fedora2

Rename the .vmx file to match your new folder name, in our case, Fedora2.vmx. Edit the vmx file in the new directory, changing the line:

displayName = "Fedora1"

to

displayName = "Fedora2"

Now, back in the console, do 'File->Open...', click Browse, and select the edited vmx file. Select the duplicate VM name in the inventory pane, renaming it to Fedora2. The first time you start the copied image, you will get the following:

 

Accept the default 'Create' to create a new identifier for the VM. Copy complete.


MySQL Backup VBScript

Published 9/20/2007 by Andy in MySQL | VBScript | Windows

The following VBScript will backup all MySQL databases on the localhost to a directory and maintain 10 days worth of backups

'* Copyright (C) 2007 Andrew Loree
'****************************************************************************
'* mysqlbackup.vbs - Backup all mysql databases to a daily backup file
'*	doing a rotation, limiting maximum number of backups retained
'****************************************************************************
'*  This program is free software; you can redistribute it and/or
'*  modify it under the terms of the GNU General Public License
'*  as published by the Free Software Foundation; either version 2
'*  of the License, or (at your option) any later version.
'*
'*  This program is distributed in the hope that it will be useful,
'*  but WITHOUT ANY WARRANTY; without even the implied warranty of
'*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'*  GNU General Public License for more details.
'*
'*  You should have received a copy of the GNU General Public License
'*  along with this program; if not, write to the Free Software
'*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
'****************************************************************************
'* Version History:
'*	1.0 - Initial Release
'****************************************************************************
Option Explicit
Dim backup_dir, num_days, user, password, arguments, backup_file
Dim oShell, oFS, oDrive, nResults

	backup_dir = "C:\some\path\here\"
	num_days = 10
	user = "XXXXXX"
	password = "YYYYYYY"

	backup_file = backup_dir & Year(Date) & PadZero(Month(Date)) & PadZero(Day(Date)) & "_all_databases.bak"
	arguments = "--user=" & user & " --password=" & password & " --all-databases --quick --result-file=" & backup_file

	Set oShell = CreateObject("WScript.Shell")

	WScript.Echo("Creating backup file " & backup_file)
	nResults = oShell.Run("mysqldump.exe " & arguments, 1, TRUE)

	Set oShell = Nothing


	
	Dim folder, files, file, regex, Matches, Match, counter, backups, i, cur

	Set oFS = CreateObject("Scripting.FileSystemObject")
	Set regex = New regexp
	regex.Pattern = "[0-9]{8}_all_databases\.bak"
	regex.Global = True
	regex.IgnoreCase = True
	
	Set folder = oFS.GetFolder(backup_dir)
	Set files = folder.Files

	counter = 0

	ReDim backups(0)

	For Each file In files
		Set Matches = regex.Execute(file.Name)
		For Each Match in Matches
			Redim Preserve backups(counter)
			backups(counter) = Match.Value
			counter = counter + 1
		Next
	Next

	cur = 0
	For i = counter - 1 To 0 Step -1
		If (cur >= num_days) Then
			WScript.Echo("Deleting " & backups(i))
			oFS.DeleteFile(backup_dir & backups(i))
		Else
			WScript.Echo("Keeping " & backups(i))
		End If
		cur = cur + 1
	Next


	Set oFS = Nothing



' PadZero - adds preceding zero to values less than 10
Function PadZero(val)

	If (val < 10) Then
		PadZero = "0" & val
	Else
		PadZero = val
	End If
End Function