Linux - HA (High Availability) su Centos - P. 2 - Installiamo DRBD (Distributed Replicated Block Device)


1) Procediamo adesso all’installazione del DRBD(Distributed Replicated Block Device) e settiamo la copia.


Supponiamo di avere il seguente ambiente, usiamo hda6 che è una partizione vuota per la configurazione:

 (1) www1.instyle.locale [192.168.0.21]
(2) www2.instyle.locale [192.168.0.22]


2) Va installato DRBD su entrambi gli host, va configurato con gli stessi settaggi su entrambi gli host. Per l’installazione specificare "kmod-drbd", anche DRBD deve essere installato, negli esempi è stato indicato "kmod-drbd-xen" perché si parla di ambienti con kernel XEN

[root@www1 ~]# yum -y install kmod-drbd-xen

[root@www1 ~]# vi /etc/drbd.conf


resource r0 {
# Specify A or B or C
protocol C;
syncer {
# settimao la bandwidth
rate 300M;
}
disk {
on-io-error detach;
}
on www1.instyle.locale {
# DRBD device
device /dev/drbd0;
# phisical device
disk /dev/hda6;
# IP address:port
address 192.168.100.21:7788;
meta-disk internal;
}
on www2.instyle.locale {
device /dev/drbd0;
disk /dev/hda6;
address 192.168.100.22:7788;
meta-disk internal;
}
}

3) [root@www1 ~]# modprobe drbd # carichiamo il modulo

4) [root@www1 ~]# lsmod | grep drbd

drbd      185096   0# si vede che è caricato il modulo

5) [root@www1 ~]# dd if=/dev/zero of=/dev/hda6 bs=1M count=128

128+0 records in
128+0 records out
134217728 bytes (134 MB) copied, 2.39478 seconds, 56.0 MB/s

6) [root@www1 ~]# drbdadm create-md r0   # creiamo il  meta-data

v08 Magic number not found
v07 Magic number not found
v07 Magic number not found
v08 Magic number not found
Writing meta data...
initialising activity log
NOT initialized bitmap
New drbd meta data block sucessfully created.

--== Creating metadata ==--
As with nodes we count the total number of devices mirrored by DRBD at
at http://usage.drbd.org.

The counter works completely anonymous. A random number gets created for
this device, and that randomer number and the devices size will be sent.

http://usage.drbd.org/cgi-bin/insert_usage.pl?nu=5112098206248082396&ru=12990301505065341479&rs=1073741824
Enter 'no' to opt out, or just press [return] to continue:
success

7) [root@www1 ~]# /etc/init.d/drbd start

8) [root@www1  ~]# cat /proc/drbd # visualizziamo lo stato

version: 8.0.11 (api:86/proto:86)
GIT-hash: b3fe2bdfd3b9f7c2f923186883eb9e2a0d3a5b1b build by buildsvn@c5-i386-build, 2008-03-09 10:26: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
[2]          Make a Host you set primary first. Then mirroring is started.
[root@www ~]# drbdsetup /dev/drbd0 primary -o   # make it primary
drbd0: Forced to consider local data as UpToDate!
[root@www ~]# cat /proc/drbd
version: 8.0.11 (api:86/proto:86)
GIT-hash: b3fe2bdfd3b9f7c2f923186883eb9e2a0d3a5b1b build by buildsvn@c5-i386-build, 2008-03-09 10:26:43
  0: cs:SyncSource st:Primary/Secondary ds:UpToDate/Inconsistent C r--- # changed
 ns:77968 nr:0 dw:0 dr:85524 al:0 bm:4 lo:111 pe:259 ua:1999 ap:0
 [>...................] sync'ed: 7.5% (971572/1048508)K
 finish: 0:00:37 speed: 25,644 (25,644) K/sec
 resync: used:2/31 hits:40719 misses:6 starving:0 dirty:0 changed:6
 act_log: used:0/127 hits:0 misses:0 starving:0 dirty:0 changed:0

9) [root@www1 ~]# mkfs -t ext3 /dev/drbd0

10) [root@www1 ~]# mkdir /mnt/drbd

11) [root@www1 ~]# mount /dev/drbd0 /mnt/drbd

12) [root@www1 ~]# touch /mnt/drbd/test.txt   # make test file

13) [root@www1 ~]# ll /mnt/drbd

total 16
drwx------ 2 root root 16384 May 11 02:18 lost+found
-rw-r--r-- 1 root root 0 May 11 02:22 test.txt

14) Se uno vuole montare DRBD device sull’host secocndario, va fatto l’unmount sul DRBD device sul server primario e far diventare l’host secondario primario. Successivamente sull’host primario è necessario montare il DRBD, ecco la procedura.

########### sull’host primario ###########

[root@www1 ~]# umount /mnt/drbd

[root@www1 ~]# drbdadm secondary r0# make it secondary

########### sull’host secondario ###########

[root@www2 ~]# drbdadm primary r0# make it primary

[root@www2 ~]# mkdir /mnt/drbd

[root@www2 ~]# mount /dev/drbd0 /mnt/drbd

[root@www2 ~]# ll /mnt/drbd

total 16
drwx------ 2 root root 16384 May 11 02:18 lost+found
-rw-r--r-- 1 root root 0 May 11 02:22 test.txt   # just exist