|
Visit satellite tv for pc elite here or click satellite tv for pc here

Above photo is a random extract from Flickr, owner of the blog do not claimed authorship nor owner ship of photo, visit Flickr for the actual owner of this photo.
So you want to mirror a drive across two different servers, maybe you have a heartbeat setup and need to have the exact same data on both drives for immediate availability, and you need more reliable and more instantaneous results than rsync or unison. Distributed Resource Block Device (DRBD) is a great tool for this need. DRBD is most easily understood as a network based RAID-1 device, where two different servers are acting as the raw devices for the RAID. DRBD is best suited for High-Availability (HA) clusters, see my heartbeat article to understand how to setup two servers in a heartbeat on Ubuntu. Ubuntu package system has DRBD available, but the package is a little old and it is best to build from source rather than use the package system.
What is DRBD?
DRBD is a block device which when written to writes to the local disk and sends the data to another host which then writes it to its local disk. A read to the DRBD device results in only a local read, no network activity. Effectively making a network RAID-1 device. DRBD has a primary and secondary node and is designed to work with heartbeat for use in High-Availability cluster.
If setup in a HA cluster, heartbeat will control the primary and secondary devices, switching as necessary. If the primary node fails, heartbeat switches the secondary to the primary, brings up the application and runs fsck if using a non-journaling file system. If the primary becomes alive again, it resynchronizes in the background. DRBD uses intelligent resynchronization, it only copies those parts of the disk which have changed.
DRBD is not a file system, it is an underlying block device, a file system must be laid on top of the DRBD device, and DRBD can alternatively be placed on top of an LVM partition, making it easy to resize and backup.
Why use DRBD?
DRBD is great for High-Availability server clusters. If you want to mirror data between two servers already setup in a High-Availability cluster, DRBD will act as a network RAID-1 for your servers. So the active HA server will be the active partition in the DRBD cluster. Thereby if data was altered on the primary server, moments prior to the server going down, the secondary server will also have the same data available once it comes up in the HA cluster.
Initial Installation:
To install DRBD from source on your Ubuntu system, you must download the source package, 8.3.2 at the time of this writing (see http://oss.linbit.com/drbd/ for latest release), compile it, and install it, and load the module, you will also need some build tools from the package system in order to compile. Alternatively, one could install from the package system, Hardy Heron (8.04 LTS) has drbd-8.0.11 included.
sudo apt-get install build-essential flex linux-headers-$(uname -r) cd /usr/src sudo wget 'http://oss.linbit.com/drbd/8.3/drbd-8.3.2.tar.gz' sudo tar -xzvf drbd-8.3.2.tar.gz sudo cd drbd-8.3.2/ sudo make KDIR=/usr/src/linux-headers-$(uname -r)/ sudo make install sudo modprobe drbd sudo /etc/init.d/drbd restart (it should complain about no resources, but have no other errors)
Network Setup:
Since DRBD runs across the network, it is best to have a good understanding of your network and how you want to set it up for use with DRBD. You have two options here, one is run the DRBD on your LAN, another is to isolate a LAN solely for the DRBD or use a crossover cable between the two machines. I prefer to have an isolated or dedicated LAN over using my internal LAN, DRBD is not necessarily traffic heavy, except during the initial synchronization and during heavy write times. Also performance will vary if your LAN is being saturated. A typical network config will look like this:
Host1:
sudo vi /etc/network/interfaces# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.125
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
auto eth1
iface eth1 inet static
address 192.168.111.125
netmask 255.255.255.0
network 192.168.111.0
broadcast 192.168.111.255
sudo vi /etc/hosts127.0.0.1 localhost.localdomain localhost
127.0.1.1 localhost.localdomain localhost
192.168.0.100 host.blackmesacapital.com host
192.168.0.125 host1.blackmesacapital.com host1
192.168.0.126 host2.blackmesacapital.com host2
On Host2:
sudo vi /etc/network/interfaces# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.126
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
auto eth1
iface eth1 inet static
address 192.168.111.126
netmask 255.255.255.0
network 192.168.111.0
broadcast 192.168.111.255
sudo vi /etc/hosts127.0.0.1 localhost.localdomain localhost
127.0.1.1 localhost.localdomain localhost
192.168.0.100 host.blackmesacapital.com host
192.168.0.125 host1.blackmesacapital.com host1
192.168.0.126 host2.blackmesacapital.com host2
Here the 192.168.0.x network is the internal LAN, 192.168.111.x network is the dedicated DRBD Network, 192.168.0.125 is the primary address for host1 on the LAN and 192.168.111.125 on the DRBD Network, 192.168.0.126 is the primary address for host2 on the LAN and 192.168.111.126 is the DRBD Network address, and 192.168.0.100 is the shared address for the servers when primary on the heartbeat (not necessary for DRBD to work, but necessary for heartbeat). We could give these hosts names on the DRBD network in /etc/hosts, but it is unnecessary.
Setting up Disks with LVM optionally
The basic idea her is that we will have an LVM volume with DRBD on top of it, then an ext2 or ext3 file system on top of the DRBD. The LVM volume is useful for easy resize of the partition and for the use of being able to backup with snapshots while still having the data available.
First we call fdisk and partition the whole disk for an lvm volume, you may use less if desired.
On both hosts:
Not Using LVM (if using LVM, skip this section):
fdisk /dev/cciss/c0d0 ← this is for a HP disk array, your disk may be different, perhaps /dev/sdaThe number of cylinders for this disk is set to 53132.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-53132, default 1058): ← enter for default
Using default value 1058
Last cylinder or +size or +sizeM or +sizeK (1-53132, default 53132): ← enter for default
Using default value 53132
Command (m for help):t
Partition number (1-4): 1
Hex code (type L to list codes): 83 ← hex code for linux system
Command (m for help):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
/dev/cciss/c0d0p1 is now partitioned.
Using LVM (if not using LVM skip to DRBD.conf Setup):
fdisk /dev/cciss/c0d0 ← this is for a HP disk array, your disk may be different, perhaps /dev/sdaThe number of cylinders for this disk is set to 53132.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-53132, default 1058): ← enter for default
Using default value 1058
Last cylinder or +size or +sizeM or +sizeK (1-53132, default 53132): ← enter for default
Using default value 53132
Command (m for help):t
Partition number (1-4): 1
Hex code (type L to list codes): 8e ← hex code for lvm
Command (m for help):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Now we have a blank partition set to a Linux LVM type. Now we need to setup LVM on it:
sudo pvcreate /dev/cciss/c0d0p1 # create a physical volume on /dev/cciss/c0d0p1Physical volume “/dev/cciss/c0d0p1″ successfully created
sudo vgcreate -s 16M vg0 /dev/ccis/c0d0p1 #create a volume group named vg0 using /dev/cciss/c0d0p1 physical volumeVolume group “vg0″ successfully created
sudo lvcreate -L 100G -n lvol0 vg0 #create a logical volume of 100G named “lvol0″ in vg0Logical volume “lvol0″ created
Now we have a 100G logical volume for our DRBD setup.
DRBD.conf Setup
Now we have to setup the drbd.conf to use the lvm and some config settings:
sudo vi /etc/drbd.confglobal {
usage-count no;
}
common {
protocol C;
handlers {
pri-on-incon-degr “echo 'DRBD: primary requested but inconsistent!' wall; /etc/init.d/heartbeat stop”;
“halt -f”;
pri-lost-after-sb “echo 'DRBD: primary requested but lost!' wall; /etc/init.d/heartbeat stop”;
“halt -f”;
}
syncer {
rate 10M;
al-extents 1801;
}
startup {
wfc-timeout 0;
degr-wfc-timeout 15;
}
disk {
on-io-error detach;
# fencing resource-and-stonith;
}
net {
sndbuf-size 64K;
timeout 60; # 6 seconds (unit = 0.1 seconds)
connect-int 10; # 10 seconds (unit = 1 second)
ping-int 10; # 10 seconds (unit = 1 second)
ping-timeout 5; # 500 ms (unit = 0.1 seconds)
max-buffers 2048;
max-epoch-size 2048;
cram-hmac-alg “sha1″;
shared-secret “secret”; # should change this to
}
}
resource r0 {
on mail1 {
disk /dev/vg0/lvol0; # location of lvm volume, use /dev/cciss/c0d0p1 for non-lvm
address 192.168.111.125:7788;
device /dev/drbd0; # name of drbd device
meta-disk internal;
}
on mail2 {
disk /dev/vg0/lvol0; # location of lvm volume, use /dev/cciss/c0d0p1 for non-lvm
address 192.168.111.126:7788;
device /dev/drbd0;
meta-disk internal;
}
}
The global section is allowed only once, the most important option is usage-count. Usage-count contacts the DRBD http server every time a new DRBD version is installed on the system for statistics purposes. Set it to no.
The common section sets options inherited to every resource.
Protocol C is the replication mode of DRBD we are using and is the “safest”. There are currently three modes of DRBD replication:
-
Protocol A: Asynchronous replication. Local writes on primary are complete as soon as the disk write has occurred and the replication packet has been sent to the local TCP send buffer. If a forced-failover occurs, the most recent update may be lost. (http://www.drbd.org/users-guide/s-replication-protocols.html)
-
Protocol B: Memory synchronous replication. Local writes on primary are complete as soon as the disk write has occurred and the replication packet has reached the remote node. If simultaneous power failure occurs on both nodes the most recent writes will be lost. (http://www.drbd.org/users-guide/s-replication-protocols.html)
-
Protocol C: Synchronous replication. Local writes on primary are complete only once both the local write and the remote disk write are confirmed. Data loss will occur if both disk subsystems are irreversibly destroyed at the same time. (http://www.drbd.org/users-guide/s-replication-protocols.html)
The two handlers I have first are used with heartbeat and tell heartbeat what to do if the DRBD is in an inconsistent state or has lost the primary role. They are unnecessary for DRBD to function, but useful in a heartbeat setup.
The syncer rate is the maximum bandwidth a resource will use for resynchronization in the background . It does not make sense to make this rate higher than the max write rate on the secondary node disk I/O, nor the bandwidth available on the network. We can not push more data than can be written or transmitted. Good rule of thumb according to drbd.org is use 30% of your available replication rate, so take the bottleneck and use 30% of it, i.e. 110MB/s effective bandwidth X 0.3 = 33 MB/s, so 33M would be your syncer rate (rate is in bytes not bits per second). (http://www.drbd.org/users-guide/s-configure-syncer-rate.html)
Startup is setting some timeouts, wfc-timeout is the wait for connection timeout, you can limit the amount of time DRBD waits for the rest of the cluster to connect up; degr-wfc-timeout is used if this is the only node in a cluster and the cluster is rebooted. These timeouts are in seconds.
Disk is the section where you can configure lower-level I/O error handling. The on-io-error sets the strategy to one of three options. Detach, recommended option, the node will drop the backing device and continue in a diskless mode. You must replace the disk or manually re-attach the device to continue using this node. Pass_on, DRBD will pass the error onto the upper disk handling layer. On the primary DRBD reports the error to the mounted file system, on the secondary this is ignored since there is no mounted file system. Call-local-io-error, will invoke a command or script designated by the administrator.
The net section sets up some network settings, most of which are self-explanatory.
The resource section defines your resources by name, here we have defined resource r0. We are using disk /dev/vg0/lvol0 (which is our lvm volume), we define the address and port for the server and we are using an internal meta-disk. An internal meta-disk is nice since it moves around with the disk, but is not always optimal, due to more disk activity, but do have the advantage of easier disk replacement upon failure since the meta data is part of the diskset. Otherwise you can define an external meta-disk by giving its location, i.e. meta-disk /dev/sda7;
Formatting Disk and Meta-Disk
Now we have DRBD configured. We need to initialize the meta data and format the disk still. DRBD itself is not a disk format, but a lower level mechanism to achieve a network based RAID-1.
On both hosts create the Meta-disk staging for resource r0:
sudo drbdadm create-md r0
Now on Host1 tell DRBD that this is the primary (Do this only on host1):
sudo drbdadm primary r0
Format the disk with ext3 on Host1 only, drbd will automatically format the disk on host2, whether you are setting up both hosts at the same time or not, drbd will synchronize the disk upon attachment.
sudo mkfs.ext3 -b 4096 /dev/drbd0
You are done, Check to see if all is well:
cat /proc/drbd or sudo /etc/init.d/drbd statusversion: 8.3.0 (api:88/proto:86-89)
GIT-hash: 9ba8b93e24d842f0dd3fb1f9b90e8348ddb95829 build by root@host1, 2009-01-29 09:46:57
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r—
ns:18819524 nr:0 dw:18819524 dr:3163845 al:828 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
This shows that the current computer is Primary, we have a Connected Secondary and both are UpToDate. If it states Standalone instead of Connected, we cannot contact the secondary. This command shows us some important information pertaining to DRBD and this hosts status.
To view what each statistic refers to go to http://www.drbd.org/users-guide-emb/ch-admin.html
What next:
You can mount your drbd partition on the primary and propagate data to it.
sudo mnt -t ext3 /dev/drbd0 /mnt
Having Heartbeat mount and umount your DRBD partition as needed (optional):
So now you have a DRBD partition and have the data propagated to it. Let's set up heartbeat to utilize this partition and only mount the device if we are the primary node in the HA cluster:
sudo vi /etc/ha.d/haresources
host1 IPaddr::192.168.0.100/24/eth0 drbddisk::r0 Filesystem::/dev/drbd0::/mnt::ext3 apache
this is a typical haresources file that takes over the 192.168.0.100 address, takes over the primary role on DRBD r0, mounts /dev/drbd0 to /mnt with the ext3 filesystem and starts up apache. The only DRBD specific parts fo this haresources file is drbddisk::r0 Filesystem::/dev/drbd0::/mnt::ext3.
Above is a random extract from Associated Content, visit Associated Content for the actual writer for this article.
|