Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com

This Blog is protected by DMCA.com

huuphan.com. Powered by Blogger.

How to installing and configuring DRBD

installing configuring DRBD

The scenario  install and configure DRBD

Node1:
FQDN: node1.huuphan.local
HDD1: 10GB (/dev/sda1)
HDD2: 1GB (/dev/sdb1)
Node2:
FQDN: node2.huuphan.local
HDD1: 10GB (/dev/sda1)
HDD2: 1GB (/dev/sdb1)

Note: device /dev/sdb a unpartitioned for 2 node.
Selinux: disabled mode
sed -i 's/SELINUX=enforcing/SELINUX=disable/' /etc/sysconfig/selinux
To installing NTP for two node
yum install ntp ntpdate -y
To iptables firewall to allow 7788 port
iptables -I eth1 -m state --state NEW -m tcp -p tcp --dport 7788 -j ACCEPT
service iptables save
To configure /etc/hosts file
vim /etc/hosts
The output as bellow
172.16.235.145 node1.huuphan.local node1
172.16.235.146 node2.huuphan.local node2
To create /dev/sdb1 device for two node
fdisk -l
fdisk /dev/sdb
The output as bellow
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa3977c63.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-783, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-783, default 783):
Using default value 783
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Install and configure DRBD for two node
rpm -ivh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
yum -y install drbd84-utils.x86_64 kmod-drbd84.x86_64
To load module drbd for two node
modprobe drbd 
To verify module drbd for two node
lsmod | grep drbd
The output as bellow
drbd                  372759  0
libcrc32c               1246  1 drbd

Node 1

To configure drbd.conf file
cp /etc/drbd.conf /etc/drbd.conf_orig
cat /dev/null > /etc/drbd.conf
vim /etc/drbd.conf
The output as bellow
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 node1.huuphan.local {
                device /dev/drbd0;
                disk /dev/sdb1;
                address 172.16.235.145:7788;
                meta-disk internal;
        }
        on node2.huuphan.local {
                device /dev/drbd0;
                disk /dev/sdb1;
                address 172.16.235.146:7788;
                meta-disk internal;
        }
}
To copy /etc/drbd.conf file to node 2 usescp command
scp /etc/drbd.conf node2:/etc/
To initiate meta data for 2 disk
drbdadm create-md r0
/etc/init.d/drbd start
To sync to between 2 node
drbdadm -- --overwrite-data-of-peer primary all
From node 2 to view status
cat /proc/drbd
or
watch cat /proc/drbd
The output as bellow
Every 2,0s: cat /proc/drbd                                                                                                                 Wed Nov 30 14:44:40 2016
version: 8.4.7-1 (api:1/proto:86-101)
GIT-hash: 3a6a769340ef93b1ba2792c6461250790795db49 build by [email protected], 2016-01-12 13:27:11
 0: cs:SyncTarget ro:Secondary/Primary ds:Inconsistent/UpToDate C r-----
    ns:0 nr:618496 dw:618496 dr:0 al:8 bm:0 lo:0 pe:4 ua:0 ap:0 ep:1 wo:f oos:5670692
        [>...................] sync'ed:  9.9% (5536/6140)M
        finish: 0:02:17 speed: 41,232 (41,232) want: 50,280 K/sec
CTRL+C if exit

Only to run node 1
mkfs.ext4 /dev/drbd0
mkdir /data
mount /dev/drbd0 /data
touch /data/test1.txt
umount /data
To assign secondary for node 1
drbdadm secondary r0

Node 2

drbdadm primary r0
cat /proc/drbd
mkdir /data
mount /dev/drbd0 /data
ls -l /data/
The above  is Primary/Secondry mode. How to Dual-Primary mode?.
Some error:
mount -t ext4 /dev/drbd0  /data
mount: block device /dev/drbd0 is write-protected, mounting read-only
mount: Wrong medium type

post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com