File system: DRBD Master standby Server file synchronization

Source: Internet
Author: User

I. Introduction to DRBD

DRBD is a block device that can be used in high availability (HA). It resembles a network RAID-1 feature. When you write data to a local
File system, the data will also be sent to another host on the network. Recorded in a file system in the same form.
The data on the local (master) and remote host (standby node) can guarantee real-time synchronization. When the local system fails, the remote host Also
Keep a copy of the same data that you can continue to use.

Using the DRBD feature in high Availability (HA) can replace the use 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 continue to service as long as it uses the backup data on top of it.
DRBD works like this:

        +--------+        |  File Systems |        +--------+             |             V        +----------+        |   Block Device Layer  |        | (/DEV/DRBD1) |        +----------+         |            |         |            |         V           v   +----------+  +-----------+   |  Local drive   | |   remote host hard Drive | |   (/DEV/HDB1)  |   | (/DEV/HDB1)  |   +----------+  +-----------+
Two. Installation of DRBD

Download the source package from the official website:

www.drbd.org

We use the drbd-8.0.4 version on the Turbolinux10.5. Install DRBD on two hosts, respectively:

# tar jxf drbd-8.0.4.tar.gz# CD drbd-8.0.4# make# make install

After make install executes:
The Drbd.ko is installed under the/lib/modules/$KernelVersion/kernel/drivers/block.
The DRBD-related tool (Drbdadm,drbdsetup) is installed under/sbin.
The DRBD startup script is established under/etc/init.d/.

Three. DRBD configuration 1.DRBD HDD partition used

You need to specify a hard disk partition that is used by DRBD for both the local host and the remote host. The two partitions must be the same size.
We specify the/DEV/HDB1 partition of the two hosts as the partition used by DRBD. Both of these partitions are 300MB in size.

2.drbd.conf configuration file

The DRBD runtime reads a configuration file/etc/drbd.conf. This file describes the mapping between the DRBD device and the hard disk partition,
And some configuration parameters for DRBD.
Here is a simple example of a drbd.conf file:
< host >turbolinux 10.5 operating system, host name G105-1,IP address is 10.0.1.2,DRBD partition for/DEV/HDB1.
< standby >turbolinux 10.5 operating system, host name G105-2,IP address is 10.0.2.2,DRBD partition for/DEV/HDB1.

The drbd.conf file is then copied to the/etc directory of the two hosts, respectively.

3.DRBD Start-up

Before starting DRBD, you need to create a block of data for the DRBD record information on the HDB1 partition of the two hosts, respectively. In
Execute on both hosts:

[[email protected]/]# drbdadm create-md r0[[email protected]/]# drbdadm CREATE-MD r0

"R0" is the name of the resource we defined in drbd.conf.
Now we can start DRBD and execute it on two hosts, respectively:

[[email protected]/]#/ETC/INIT.D/DRBD start[[email protected]/]#/ETC/INIT.D/DRBD start

You can now view the status of DRBD and then execute it on the G105-1 host:

[Email protected]/]# cat/proc/drbdversion:8.0.4 (api:86/proto:86) SVN revision:2947 build by [email protected], 2007-0  7-28 07:22:30 1: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 mis ses:0 starving:0 dirty:0 changed:0

The current state of DRBD is shown in "/PROC/DRBD". The first line of St represents the state of both hosts, both of which are "standby".
The DS is a disk state, which is an "inconsistent" state.
This is because DRBD cannot determine which side is the host and which side of the disk data to use as standard data. So we need to initialize
A host. Execute on g105-1:

[Email protected]/]# DRBDSETUP/DEV/DRBD1 Primary-o

Now look at the DRBD status on a g105-1:

[Email protected]/]# cat/proc/drbdversion:8.0.4 (api:86/proto:86) SVN revision:2947 build by [email protected], 2007-0 7-28 07:22:30 1:cs:syncsource st:primary/secondary ds:uptodate/inconsistent C r---    ns:42688 nr:0 dw:0 dr:42688 al:0 b M:2 lo:4 pe:0 ua:4 ap:0        [==>....] Sync ' ed:14.7% (262464/305152) K        finish:0:02:58 speed:1,440 (1) , 292) k/sec        resync:used:1/31 hits:2669 misses:3 starving:0 dirty:0 changed:3 act_log:used:0/127 hits:0 misses        : 0 starving:0 dirty:0 changed:0

The main standby state is "master/standby", the host disk status is "real-time" and the standby state is "inconsistent".
On line 3rd, you can see that the data is synchronizing, that is, the host is passing the data on the disk to the standby machine. The progress is now 14.7%.
Now look at the DRBD state above the g105-2.

[Email protected]/]# cat/proc/drbdversion:8.0.4 (api:86/proto:86) SVN revision:2947 build by [email protected], 2007-0 7-28 07:13:14 1:cs:synctarget st:secondary/primary ds:inconsistent/uptodate C r---    ns:0 nr:56608 dw:56608 dr:0 al:0 b M:3 lo:0 pe:0 ua:0 ap:0        [===>....] Sync ' ed:20.0% (248544/305152) K        finish:0:02:57 speed:1,368 (1 , 284) k/sec        resync:used:0/31 hits:3534 misses:4 starving:0 dirty:0 changed:4 act_log:used:0/127 hits:0 misses        : 0 starving:0 dirty:0 changed:0

Just a moment, after the data is synchronized, check the DRBD status of G105-1:

[Email protected]/]# cat/proc/drbdversion:8.0.4 (api:86/proto:86) SVN revision:2947 build by [email protected], 2007-0 7-28 07:22:30 1:cs:connected st:primary/secondary ds:uptodate/uptodate C r---    ns:305152 nr:0 dw:0 dr:305152 al:0 bm:1 9 lo:0 pe:0 ua:0 ap:0        resync:used:0/31 hits:19053 misses:19 starving:0 dirty:0 changed:19        act_log:used:0/127 hit s:0 misses:0 starving:0 dirty:0 changed:0

The disk status is "Live", indicating that the data synchronization is complete.

4. Use DRBD

You can now mount the DRBD device on the host to a directory for use. The DRBD device for the standby machine cannot be mounted because it is
To receive the host data, the DRBD is responsible for the operation.
Execute on g105-1:

[Email protected]/]# mount/dev/drbd1/mnt/drbd1[[email protected]/]# df-hfilesystem            Size  used Avail use% Moun Ted On/dev/hda3             9.3G  6.5G  2.4G  73%//dev/hda1              99M  9.3M   85M  10%/bootnone                  249M     0  249M   0%/dev/shm/dev/drbd1            289M   11M  264M   4%/mnt/drbd1

Now, we create a 200M file in the DRBD1 directory:

[[email protected]/]# dd If=/dev/zero of=/mnt/drbd1/tempfile1.tmp bs=104857600 count=2

When the operation is complete, perform the following on the G105-2 (standby machine):
Let's stop DRBD first.

[[email protected]/]#/ETC/INIT.D/DRBD stop

Now, we can mount the HDB1

[[email protected]/]# mount/dev/hdb1/mnt/drbd1[[email protected]/]# ls/mnt/drbd1-hltotal 201Mdrwx------  2 root R  Oot  12K 23:44 lost+found-rw-r--r--  1 root root 200M Jul 00:20 tempfile1.tmp[[email protected]/]# umount /mnt/drbd1

As you can see, the file tmpfile1.tmp generated on the host g105-1 is also fully stored on the DRBD g105-2 of the standby machine.
This is the network RAID-1 function of DRBD. Any operation on the host computer will be synchronized to the corresponding disk partition on the standby machine to achieve the effect of data backup.

5.DRBD Primary and Standby switching

Sometimes you need to swap out the master and standby machine for DRBD. You can do the following:
On the host, first uninstall the DRBD device.

[Email protected]/]# UMOUNT/MNT/DRBD1

Demote the host to "standby".

[[email protected]/]# Drbdadm secondary r0[[email protected]/]# cat/proc/drbdversion:8.0.4 (api:86/proto:86) SVN Revisi on:2947 build by [email protected], 2007-07-28 07:13:14 1:cs:connected st:secondary/secondary ds:uptodate/uptodate C r-- -    ns:0 nr:5 dw:5 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

Now, both hosts are "standby".
On the standby g105-2, upgrade it to "host".

[[email protected]/]# Drbdadm primary r0[[email protected]/]# cat/proc/drbdversion:8.0.4 (api:86/proto:86) SVN Revision : 2947 build by [email protected], 2007-07-28 07:13:14 1:cs:connected st:primary/secondary ds:uptodate/uptodate C R---
   ns:0 nr:5 dw:5 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
   

Now, G105-2 becomes a "host". You can mount and use its/dev/drbd1. Again, the data is synchronized to
G105-1 above.

File system: DRBD Master standby Server file synchronization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.