Lates,
Sid
Setting up drbd on vps.net ubuntu
Thursday, June 25, 2009, 4:22:59 PM
Using vps.net's vps cloud allows you setup a backend and scale up on the fly,
unfornately vps.net's cloud system prevents you from modifying the current partition tables. In order to get around this we'll setup drbd using loopback devices instead of actual partions. Other than this limitation creating a high avaibility san on vps.net is pretty straight forward.
So lets get rocking
Create the filesystem
first things first we'll need to create the folders for everything we'll be doing
mkdir -p /srv/fs /srv/data
and now we'll answer the question of how do we create new partitions without being able to edit the actual partion table, drum roll please... loopback devices.
A big thank you to James Withall at vps.net for recommending I look into loopback devices.
creating loopback devices for drbd
we'll be creating 2 devices for drbd, 1 for drbd meta data and 1 for drbd data. Our meta data disk will be 256mb and our data disk will be 7.5gb. So lets create our devices.
Create the meta data file
dd if=/dev/zero of=/srv/fs/meta.img bs=1024 count=250000
Create the data file
dd if=/dev/zero of=/srv/fs/data.img bs=1024 count=7325000
The next step is to create our loopback device.
Loopback device
We'll need to connect our LOFS at system startup, so I created a script to handle this for you. Place this script at: /etc/init.d/vpsdrbdlofs
Create File via Nano
sudo nano /etc/init.d/vpsdrbdlofs
Here is the script
#!/bin/bash
#
#Startup script to create LOFSs for drbd on ubuntu / vps.net
#
#Author: Sid Sidberry <greg@halfgray.com> http://himynameissid.com
#
#Description: This script attaches files from the file system to loopback
# devices for use as drbd partitions.
# Two files are required, 1 for drbd meta-data and 1 for drbd data
#
#your partion files
DRBD_METADATA_SRC="/srv/fs/meta.img"
DRBD_FILEDATA_SRC="/srv/fs/data.img"
#loopback devices
DRBD_METADATA_DEVICE="/dev/loop6"
DRBD_FILEDATA_DEVICE="/dev/loop7"
#losetup
LOSETUP_CMD=/sbin/losetup
#make sure the src files exist
[ -x $LOSETUP_CMD ] || exit 0
[ -e "$DRBD_METADATA_SRC" ] || exit 0;
[ -e "$DRBD_FILEDATA_SRC" ] || exit 0;
#includes lsb functions
. /lib/lsb/init-functions
function connect_lofs
{
log_daemon_msg "Connecting loop devices $DRBD_METADATA_DEVICE, $DRBD_FILEDATA_DEVICE"
$LOSETUP_CMD $DRBD_METADATA_DEVICE $DRBD_METADATA_SRC
$LOSETUP_CMD $DRBD_FILEDATA_DEVICE $DRBD_FILEDATA_SRC
}
function release_lofs
{
log_daemon_msg "Releasing loop devices $DRBD_METADATA_DEVICE, $DRBD_FILEDATA_DEVICE"
$LOSETUP_CMD -d $DRBD_METADATA_DEVICE
$LOSETUP_CMD -d $DRBD_FILEDATA_DEVICE
}
case "$1" in
start)
connect_lofs
;;
release)
release_lofs
;;
*)
echo "Usage: /etc/init.d/vpsdrbdlofs {start|release}"
exit 1
;;
esac
exit 0Make the script executable and add to startup
sudo chmod +x /etc/init.d/vpsdrbdlofs sudo update-rc.d vpsdrbdlofs defaults
Now your loopback devices will be attached at startup BEFORE our drbd resources are started, and we're ready to setup our server.
Configure fstab for our drbd file system
If your on vps.net your fstab loks something similar to:
proc /proc proc defaults 0 0 /dev/sda1 / ext3 relatime,errors=remount-ro 0 1 /dev/sda2 none swap sw 0 0
add an entry for drbd
/dev/drbd0 /srv/data ext3 noauto 0 0
afterwards your fstab looks like
proc /proc proc defaults 0 0 /dev/sda1 / ext3 relatime,errors=remount-ro 0 1 /dev/sda2 none swap sw 0 0 /dev/drbd0 /srv/data ext3 noauto 0 0
Configure /etc/hosts
We'll need to map our servers to there internal ips, the simplest way to do this is via the /etc/hosts file.
TODO
Install the userspace portion of drbd
sudo apt-get install drbd8-utils
enable the drbd module
check if drbd module is enabled
sudo cat /etc/modules | grep drbd
If found you should see
drbd
If not found add it
sudo echo 'drbd' > /etc/modules
or you can use nano
sudo nano /etc/modules
add
drbd
load drbd module
sudo modprobe drbd
Configure drbd
sudo nano /etc/drbd.conf
common {
protocol C;
handlers {
pri-on-incon-degr "echo 'DRBD: primary requested but inconsistent!' wall; /etc/init.d/heartbeat stop";
outdate-peer "/usr/lib/heartbeat/drbd-peer-outdater";
}
startup {
wfc-timeout 60;
degr-wfc-timeout 120; # 2 minutes.
}
disk {
on-io-error detach;
fencing resource-only;
}
net {
max-buffers 2500;#buffer a max of 10mb of data before writing to disk
ko-count 4;
}
syncer {
rate 5M;
cram-hmac-alg "sha1";
shared-secret "strongpassword+app_cluster@NASTUT2009";
al-extents 257;
}
}
resource web0{
on fuel61{
device /dev/drbd0; #
disk /dev/loop7; #data partition on server 1
address 10.0.0.22:7788; #server 1 ip
meta-disk /dev/loop6[0]; #meta-data partition on server 1
}
on fuel62{
device /dev/drbd0; #
disk /dev/loop7; #data partition on server 2
address 10.0.0.23:7788; #server 2 ip
meta-disk /dev/loop6[0]; #meta-data partition on server 2
}
}create drbd meta data for our resource
sudo drbdadm create-md web0
after creating our meta data on both machines start drbd by running
sudo drbdadm up all
check the drbd status
cat /proc/drbd
Quote
GIT-hash: b3fe2bdfd3b9f7c2f923186883eb9e2a0d3a5b1b build by phil@mescal, 2008-02-12 11:56:43
0: cs:Connected st:Secondary/Secondary ds:Inconsistent/Inconsistent C r---
ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0
resync: used:0/31 hits:0 misses:0 starving:0 dirty:0 changed:0
act_log: used:0/127 hits:0 misses:0 starving:0 dirty:0 changed:0
Both servers should be secondary with the data being inconsistent. So the next step is to set our master.
On your master server run
sudo drbdsetup /dev/drbd0 primary -o sudo drbdadm primary all
This will set the master server as the drbd primary and do the initial sync
Now check the status of drbd
cat /proc/drbd
Quote
GIT-hash: b3fe2bdfd3b9f7c2f923186883eb9e2a0d3a5b1b build by phil@mescal, 2008-02-12 11:56:43
0: cs:SyncSource st:Primary/Secondary ds:UpToDate/Inconsistent C r---
ns:340704 nr:0 dw:0 dr:340704 al:0 bm:20 lo:312 pe:0 ua:311 ap:0
[>....................] sync'ed: 4.7% (6991/7324)M
finish: 0:48:42 speed: 2,400 (2,660) K/sec
resync: used:2/31 hits:21583 misses:22 starving:0 dirty:0 changed:22
act_log: used:0/127 hits:0 misses:0 starving:0 dirty:0 changed:0
You'll now see the master server is the primary and it's data is considered up to date. Our secondary servers data is still inconsistent
The next step is to create the file system
sudo mkfs.ext3 /dev/drbd0
check the status of drbd again
cat /proc/drbd
Quote
GIT-hash: b3fe2bdfd3b9f7c2f923186883eb9e2a0d3a5b1b build by phil@mescal, 2008-02-12 11:56:43
0: cs:SyncSource st:Primary/Secondary ds:UpToDate/Inconsistent C r---
ns:1616496 nr:0 dw:192500 dr:1424036 al:91 bm:87 lo:312 pe:1 ua:311 ap:0
[==>.................] sync'ed: 19.8% (5883/7324)M
finish: 0:33:28 speed: 2,984 (2,332) K/sec
resync: used:1/31 hits:101907 misses:187 starving:0 dirty:0 changed:187
act_log: used:0/127 hits:48034 misses:146 starving:0 dirty:55 changed:91
Now our devices are syncing the file systems. when done you should see:
cat /proc/drbd
version: 8.0.11 (api:86/proto:86) GIT-hash: b3fe2bdfd3b9f7c2f923186883eb9e2a0d3a5b1b build by phil@mescal, 2008-02-12 11:56:43 0: cs:Connected st:Primary/Secondary ds:UpToDate/UpToDate C r--- ns:7641396 nr:0 dw:192500 dr:7448936 al:91 bm:458 lo:0 pe:0 ua:0 ap:0 resync: used:0/31 hits:477879 misses:557 starving:0 dirty:0 changed:557 act_log: used:0/127 hits:48034 misses:146 starving:0 dirty:55
Now that the drbd file system is in sync and we're ready to setup our servers to use drbd's filesystem
Heartbeat configuration
To add drbd control to heartbeat add the following to your haresources file
drbddisk::web0 Filesystem::/dev/drbd0::/srv/data::ext3::rw
Heartbeat mysql setup is covered in detail in our ha mysql setup and ha active / active mysql tuts
If you need help setting up heartbeat read the heartbeat installation tut.

Help
This topic is locked













