How to create a RAID1 for backup in Linux (using DRBD)

  • drbd/drbd@wiki is a distributed replicated storage system.
    Writes to the primary node are transferred to the lower-level block device and simultaneously propagated to the secondary node. Should the primary node fail, a cluster management process promotes the secondary node to a primary state.
# install
$ sudo apt-get install drbd8-utils drbd8-module | sudo yum install drbd84-utils kmod-drbd84 (ELRepo)
$ modprobe drbd or reboot
# make sure all hosts have same time
$ sudo apt-get install ntp ntpdate | sudo yum install ntp ntpdate

# partition /dev/sdb, on each host
$ fdisk /dev/sdb

# configure
$ cat /etc/drbd.conf
global { usage-count no; }
common { syncer { rate 100M; } }
resource r0 {
        protocol C;
        startup {
                wfc-timeout  15;
                degr-wfc-timeout 60;
        }
        net {
                cram-hmac-alg sha1;
                shared-secret "secret";
        }
        on drbd01 {
                device /dev/drbd0;
                disk /dev/sdb1;
                address 192.168.0.1:7788;
                meta-disk internal;
        }
        on drbd02 {
                device /dev/drbd0;
                disk /dev/sdb1;
                address 192.168.0.2:7788;
                meta-disk internal;
        }
} 
$ scp /etc/drbd.conf drbd02:/etc/drbd.conf
# initialize the meta data storage, on each server
$ sudo drbdadm create-md r0 ; sudo service drbd start
# set drbd01 as primary
$(drbd01) sudo drbdadm -- --overwrite-data-of-peer primary all
# watch progress on secondary
$(drbd02) watch -n1 cat /proc/drbd
# mount fs
$(drbd01) sudo mkfs.ext3 /dev/drbd0 ; mkdir /mnt/data ; sudo mount /dev/drbd0 /mnt/data

# testing
$(drbd01) touch /mnt/data/test.txt
# on primary, unmount and demote-it to secondary
$(drbd01) sudo umount /mnt/data ; sudo drbdadm secondary r0
# on secondary, promote-it to primary
$(drbd02) sudo drbdadm primary r0
# remount; you should see '/mnt/data/test.txt' copied from the former primary host drbd01
$(drbd02) sudo mount /dev/drbd0 /srv ; ls /mnt/data/test.txt

# check status, see http://www.drbd.org/users-guide/ch-admin.html#s-check-status
$ drbd-overview
$ cat /proc/drbd

from drbd@ubuntu and drbd@debian

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s