Drbd introduction:
Drbd stands for Distributed replicated block (Distributed replication block device). It belongs to the device company but is completely open-source. It is a block-based file replication solution that is much faster than file-level software such as NFS and samba. It is the preferred solution for shared storage for many small and medium enterprises.
Drbd needs to prepare an identical partition on both nodes to form an image. This is why drbd is called a distributed replication block device. It mainly implements file synchronization (Backup) by copying data ), it is mainly used for cluster file sharing. We use its working principle to understand the differences between block replication and file replication, such:
First, you need to know that drbd is working in the system kernel space, not the user space. It directly copies binary data, which is the root cause of its fast speed.
Secondly, drbd requires at least two nodes to work, one master at a time.
The file synchronization process of drbd is different from that of normal replication:
When data enters the buffer cache, drbd first passes through the drbd layer, copies a copy of the data, which is encapsulated by the TCP/IP protocol and sent to another node, the other node accepts the copied data through the TCP/IP protocol and synchronizes the data to the drbd device of the secondary node.
The following is the prerequisite for configuring drbd:
1) The host name is the same as that output by the uname-N command, preferably in the FQDN format.
2) The two shards of drbd are of the same size. Do not format them first.
3) Prepare a 2 GB partition/dev/sda5 for both nodes.
Prepare two virtual machines. I am using vm6.5 + redhat5.4. The host name and IP address are as follows:
Node1.a.org 172.16.14.11
Node2.a.org 172.16.14.12
1. Install and modify the configuration file
1) install the drbd software package. The required software package is as follows:
[Root @ node1 ~] # Ls drbd/
Drbd83-8.3.8-1.el5.centos.i386.rpm kmod-drbd83-8.3.8-1.el5.centos.i686.rpm
# Use rpm-I to install these two software packages without any dependency
[Root @ node1 drbd] # rpm-IVH *. rpm
[Root @ node2 drbd] # rpm-IVH *. rpm
2) copy the configuration file to/etc.
[Root @ node2 drbd] # cp/usr/share/doc/drbd83-8.3.8/drbd. CONF/etc/
CP: overwrite '/etc/drbd. conf '? Y # directly overwrite, the original file does not have any content
[Root @ node2 drbd] # Cat/etc/drbd. conf
# You can find an example in/usr/share/doc/drbd.../drbd. conf. Example
# The configuration file contains only the following two lines, which tell us to define the file ending with. Res under drbd. d as the resource of drbd.
Include "drbd. d/global_common.conf"; # real master configuration file
Include "drbd. d/*. Res ";
# Modify global_common.conf with the following content:
[Root @ node2 drbd] # Vim/etc/drbd. d/global_common.conf global {usage-count no;} common {protocol C; # C refers to synchronizing a asynchronous B semi-synchronous handlers {pri-on-Incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh;/usr/lib/drbd/notify-emergency-reboot.sh; echo B>/proc/sysrq-trigger; reboot-F "; pri-lost-after-Sb"/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo B>/proc/sysrq-trigger; reboot-F "; local-io-error"/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o>/proc/sysrq-trigger; halt-F ";}startup {WFC-Timeout 120; degr-WFC-Timeout 120 ;} disk {ON-io-error detach; fencing resource-only;} net {Cram-HMAC-Alg "sha1"; shared-secret "mydrbdlab";} syncer {rate 100 m; # Your Nic speed }}
3) define a Resource Web to store webpage files and provide file services to clusters.
Resource Web {ON node1.a.org {# note the host name device/dev/drbd0; Disk/dev/sda5; # partition address 172.16.14.11: 7789; # Note IP meta-disk internal ;} on node2.a.org {# note the host name device/dev/drbd0; Disk/dev/sda5; # partition address 172.16.14.12: 7789; # Note IP meta-disk internal ;}}
4) copy the configuration file to node1.
[Root @ node2 drbd] # SCP/etc/drbd. conf node1:/etc/
[Root @ node2 drbd] # SCP/etc/drbd. d/* node1:/etc/drbd. d/
2. initialize existing resources and start the drbd Service
1) initialize Resources
[Root @ node1 drbd] # drbdadm create-MD Web
[Root @ node2 drbd] # drbdadm create-MD Web
2) start the service. It must be noted that after a node starts the service, if the other node does not start, it will remain stuck in the waiting state.
[Root @ node1 drbd] # service drbd start
[Root @ node2 drbd] # service drbd start
3) view synchronization status
[Root @ node1 drbd] # Watch-N 1 'cat/proc/drbd'
You can also use the following command to view
[Root @ node1 drbd] # drbd-Overview
0: Web connected secondary/secondary inconsistent/inconsistent C r ----
3. Set node1 as the master node to start data synchronization.
1) set the master node
[Root @ node1 drbd] # drbdsetup/dev/drbd0 primary-o
Or drbdadm -- overwrite-data-of-peer primary Web
Viewing the node information status has become primiary. There is a data synchronization process in the middle.
[Root @ node1 drbd] # drbd-Overview
0: Web connected primary/secondary uptodate/uptodate C r ----
2) create a file system and mount it
[Root @ node1 drbd] # mke2fs-J-l drbd/dev/drbd0
[Root @ node1 drbd] # mkdir/mnt/drbd
[Root @ node1 drbd] # Mount/dev/drbd0/mnt/drbd/
Create several empty files
[Root @ node1 drbd] # cd/mnt/drbd/
[Root @ node1 drbd] # Touch a B c
4. Switch the master node
# Unmount the node first and change node1 to the next node
[Root @ node1 ~] # Umount/mnt/drbd/
[Root @ node1 ~] # Drbdadm secondary Web
# Set the master node on node2
[Root @ node2 ~] # Mkdir/mnt/drbd # Wear mount point
[Root @ node2 ~] # Drbdadm primary Web
[Root @ node2 ~] # Drbd-Overview
0: Web connected secondary/primary uptodate/uptodate C r ----
[Root @ node2 ~] # Drbdadm primary Web
Check whether the created file exists.
[Root @ node2 ~] # Mount/dev/drbd0/mnt/drbd/
[Root @ node2 ~] # Ls/mnt/drbd/
A B C lost + found