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-buildNow 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 kernelAfter it is installed, reboot, then run the following:
yum upgrade kernel-headers kernel-devel flex gcc rpm-buildDownload 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 installTo make sure install works correctly, confirm that modprobe returns nothing, and /proc/drbd returns the version:
modprobe drbd
cat /proc/drbdRepeat 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 rpmTwo 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.
