Monday, April 18, 2016

create raid 1 disk from two hosts over tcp/ip

RAID 1 (redundant array of independent disks level 1) is a way to create reliable data stores from two computer hard disk, or we can call it mirror. it create an exact copy of a set of data on two disks. With RAID 1 if one of the disk is broken, the data will remain intact. This layout is useful when read performance or reliability is more important than write performance or the resulting data storage capacity. So we need two disks on the computer to configure raid 1.

But with drbd we just need to have one partition from two computer can can create raid 1 as well on tcp/ip. it  is a software-based, shared-nothing, replicated storage solution mirroring the content of block devices (hard disks, partitions, logical volumes etc.) between hosts. It mirror data in real time, transparently and synchronously/asynchronously.

*** setup information ***
- host 1, ip:
              hostname: ununtuxenial
              raid disk: primary
              partition: sdb1
- host 2, ip:
              hostname: ununtuxenial1
              raid disk: secondary
              partition: sdb1

you have to update your hosts file for both host like below  ununtuxenial  ununtuxenial1

*** host1 ***
1- install drbd (on ubuntu 16.04 host) if you use 14.04 the package name is drbd8-utils
$ sudo  apt-get install drbd-utils

2- update drbd configuration file /etc/drbd.conf as bellow
include "drbd.d/global_common.conf";
include "drbd.d/*.res";

3- update global drbd configuration file
global {
    usage-count no;
common {
    handlers {
    startup {
    options {
    disk {
    net {
        protocol C;

4- create resource file call /etc/drbd.d/r1.res with the following content
resource r1 {
  on ubuntuxenial1 {
    device    /dev/drbd1;
    disk      /dev/sdb1;
    meta-disk internal;
  on ubuntuxenial {
    device    /dev/drbd1;
    disk      /dev/sdb1;
    meta-disk internal;

5- initial the resource with the following command
$ sudo drbdadm create-md r1
$ sudo drbdadm up r1

6-  restart drbd service
$ sudo /etc/init.d/drbd restart

7- this host will be the primary so we set it to primary by command below
$ sudo drbdadm primary --force  r1

*** host2 ***
do the same as host1 except step 5, and 7


now we can check status of drbd from both host
- on primary - host1
$ sudo  drbd-overview
 1:r1/0  Connected Primary/Secondary UpToDate/UpToDate /mnt ext4 20G 44M 19G 1%

-on secondary - host2
$ drbd-overview
 1:r1/0  Connected Secondary/Primary UpToDate/UpToDate

or we can just read from file in proc for drbd status
$ cat /proc/drbd

-*** mount disk host1 ***
- create file system on it
$ sudo mkfs.ext4 /dev/drbd/by-res/r1
- after that, we can use mount command to mount it as normal, but we can do only on primary host, host1
$ sudo  mount /dev/drbd/by-res/r1 /mnt 
$ df -h
df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            975M     0  975M   0% /dev
tmpfs           199M  5.9M  193M   3% /run
/dev/sda1       196G  2.8G  184G   2% /
tmpfs           992M     0  992M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           992M     0  992M   0% /sys/fs/cgroup
tmpfs           199M     0  199M   0% /run/user/1000
/dev/drbd1       20G   44M   19G   1% /mnt

There are many other options available, you can explore it more on the drbd websites, but is very long, who like reading long articles

No comments:

Post a Comment