How DRBD Works
DRBD is a block device that can be used in high availability (HA). It is similar to a network RAID-1 feature. When you write data to the local file system, the data is also sent to another host on the network. Recorded in a file system in the same form. The data of the local (master) and remote host (standby node) can guarantee real-time synchronization. When the local system fails, a copy of the same data remains on the remote host and can continue to be used. Using the DRBD feature in high Availability (HA) can be used instead of a shared disk array.
Because the data exists both on the local host and on the remote host, when switching, the remote host can use the backup data on it.
You can continue with the service.
The environment of the two machines is as follows:
Hostname:srv5.localdomain
192.168.8.5
Hostname:srv6.localdomain
192.168.8.6
Prepare the Environment
Add a new disk to each of the two machines
Fdisk-l list all disks and partitions
In the experiment, you can see that the newly added disk is not partitioned
disk/dev/sdb:1073 MB, 1073741824 bytes
255 heads, Sectors/track, cylinders
Units = Cylinders of 16065 * 8225280 bytes
To the newly added disk partition
[Email protected] ~]#Fdisk/dev/sdb
Command (M for help): N
Command Action
E Extended
P primary partition (1-4)
e
Partition number (1-4):1
First cylinder (1-130, default 1):
Using Default value 1
Last cylinder or +size or +sizem or +sizek (1-130, default 130):
Using Default Value 130
Command (M for help):N
Command Action
L logical (5 or over)
P primary partition (1-4)
L
First cylinder (1-130, default 1):
Using Default value 1
Last cylinder or +size or +sizem or +sizek (1-130, default 130):
Using Default Value 130
Command (M for help):W
The partition table has been altered!
Calling IOCTL () to re-read partition table.
Syncing disks.
Loading disk information
Partprobe/dev/sdb
Cat/proc/partions
Installing and configuring DRBD
1, install DRBD separately on both machines
Yum-y Install kmod-drbd83 drbd83
Check if the installation is successful
[Email protected] yum.repos.d]# Modprobe-l | Grep-i DRBD
/lib/modules/2.6.18-53.el5/weak-updates/drbd83/drbd.ko
After the installation is complete and then/sbin the command file with DRBD in the directory, there is a DRBD startup script in the/etc/init.d/directory
[Email protected] yum.repos.d]# ls/sbin/drbd*
/sbin/drbdadm/sbin/drbdmeta/sbin/drbdsetup
2, configuring DRBD
2.1, add the following content to the hosts file of the two machines:
192.168.8.5 Srv5.localdomain
192.168.8.6 Srv6.localdomain
2.2,DRBD to read the/etc/drbd.conf file when running,
Save the contents of the file as follows:
Include "drbd.d/global_common.conf";
Include "Drbd.d/*.res";
Modify the contents of the global_common.conf file as follows:
global {Usage-count No;} Common {protocol C;startup {wfc-timeout; Degr-wfc-timeout; outdated-wfc-timeout; } disk {On-io-error detach; Fencing resource-only; } NET {cram-hmac-alg SHA1; Shared-secret "123456"; } syncer {rate 100M; }}
Create a Xserver.res file with the following contents:
Resource Xserver { meta-disk internal; device/dev/drbd0; #device指定的参数最后必须有一个数字, for the minor-count of Global, #否则会报错. device Specifies the DRBD application-tier appliance. On srv5.localdomain{ #注意: The machine name is case sensitive in the DRBD configuration file! Address 192.168.8.5:7789; DISK/DEV/SDB5; } On srv6.localdomain { address 192.168.8.6:7789; DISK/DEV/SDB5; } }
2.3, assuming that the above configuration is done on the 92.168.8.5, copy the 3 files configured above to 92.168.8.6
Scp/etc/drbd.conf 192.168.8.6:/etc/drbd.conf
scp/etc/drbd.d/* 192.168.8.6:/etc/drbd.d/
3, create the DRBD metadata information on both machines:
[Email protected] ~]# Drbdadm CREATE-MD All
Writing Meta Data ...
Initializing activity log
Not initialized bitmap
New DRBD Meta data block successfully created.
4, start the service,
4.1, on the master node 92.168.8.5
Service DRBD Start
On the backup node 92.168.8.6
Service DRBD Start
On both machines, Drbd-overview or CAT/PROC/DRBD with the following command, found to be secondary backup status
[Email protected] ~]# Drbd-overview
0:xserver Connected secondary/secondary inconsistent/inconsistent C r-----
[Email protected] ~]# CAT/PROC/DRBD
version:8.3.15 (api:88/proto:86-97)
git-hash:0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by [email protected], 2013-03-27 16:04:08
0:cs:connected ro: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 ep:1 wo:b oos:1044092
4.2, execute the following command on the master node 92.168.8.5 to make it the master node
DRBDADM----Overwrite-data-of-peer primary all
And then look at the status:
[Email protected] ~]# Drbd-overview
0:xserver syncsource primary/secondary uptodate/inconsistent C r---N-
[=============> ...] Sync ' ed:70.6% (310268/1044092) K
[Email protected] ~]# Drbd-overview
0:xserver syncsource primary/secondary uptodate/inconsistent C r---N-
[================> ...] Sync ' ed:89.1% (117372/1044092) K
[Email protected] ~]# Drbd-overview
0:xserver Connected primary/secondary uptodate/uptodate C r-----
4.3, format and mount the/DEV/DRBD0
Execute the following command on the master node 192.168.8.5
Mkfs.ext3/dev/drbd0
Mkdir/xserver-storage
Mount/dev/drbd0/xserver-storage
4.4, Test Sync
Execute the following command on the master node 192.168.8.5
Cd/xserver-storage
echo "A file created in Server5" > Testfile
Execute the following command on the backup node 192.168.8.6
Mkdir/xserver-storage
Mount/dev/drbd0/xserver-storage
#mount can go wrong, because mount can only be used on the primary end
Execute the following command on the primary node 192.168.8.5 to become the backup node
Umount/xserver-storage
Drbdadm Secondary All
On the backup node 192.168.8.6, perform the following command to change to the master node, and you can see 192.168.8.5 Synchronized Content
Drbdadm Primary All
Mount/dev/drbd0/xserver-storage
Less/xserver-storage/testfile
You can see the contents of the file as "A-file created in Server5"
Create a new file in 192.168.8.6
echo "A file created in Server6" > Testfile2
After turning 192.168.8.5 into the master node, mount can see that the contents of the Testfile2 are also synchronized.
Configuring the DRBD deployment on Linux