How to Setup DRBD to Replicate Storage on Two CentOS 7 Servers
The DRBD (stands for Distributed Replicated Block Device) is a dispensed, versatile and flexible replicated garage answer for Linux. It mirrors the content material of block gadgets comparable to laborious disks, walls, logical volumes and so forth. between servers. It comes to a replica of information on two garage gadgets, such that if one fails, the knowledge on the opposite can be utilized.
You can bring to mind it moderately like a community RAID 1 configuration with the disks reflected throughout servers. However, it operates in an overly other manner from RAID or even community RAID.
Originally, DRBD was once principally utilized in excessive availability (HA) pc clusters, on the other hand, beginning with model nine, it may be used to deploy cloud garage answers.
In this text, we will be able to display how to set up DRBD in CentOS and in short show how to use it to reflect garage (partition) on two servers. This is the easiest article to get your began with the use of DRBD in Linux.
For the aim of this text, we’re the use of two nodes cluster for this setup.
- Node1: 192.168.56.101 – tecmint.tecmint.lan
- Node2: 192.168.10.102 – server1.tecmint.lan
Step 1: Installing DRBD Packages
DRBD is carried out as a Linux kernel module. It exactly constitutes a motive force for a digital block instrument, so it’s established proper close to the ground of a gadget’s I/O stack.
DRBD will also be put in from the ELRepo or EPEL repositories. Let’s get started via uploading the ELRepo package deal signing key, and allow the repository as proven on each nodes.
# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org # rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
Then we will be able to set up the DRBD kernel module and utilities on each nodes via operating:
# yum set up -y kmod-drbd84 drbd84-utils
If you could have SELinux enabled, you wish to have to regulate the insurance policies to exempt DRBD processes from SELinux keep watch over.
# semanage permissive -a drbd_t
In addition, in case your gadget has a firewall enabled (firewalld), you wish to have to upload the DRBD port 7789 within the firewall to permit synchronization of information between the 2 nodes.
Run those instructions on the primary node:
# firewall-cmd --permanent --add-rich-rule='rule circle of relatives="ipv4" supply cope with="192.168.56.102" port port="7789" protocol="tcp" settle for' # firewall-cmd --reload
Then run those instructions on 2nd node:
# firewall-cmd --permanent --add-rich-rule='rule circle of relatives="ipv4" supply cope with="192.168.56.101" port port="7789" protocol="tcp" settle for' # firewall-cmd --reload
Step 2: Preparing Lower-level Storage
Now that we have got DRBD put in on the 2 cluster nodes, we will have to get ready a kind of identically sized garage space on each nodes. This is usually a laborious pressure partition (or a complete bodily laborious pressure), a tool RAID instrument, an LVM Logical Volume or a some other block instrument kind discovered on your gadget.
For the aim of this text, we will be able to create a dummy block instrument of dimension 2GB the use of the dd command.
# dd if=/dev/0 of=/dev/sdb1 bs=2024okay depend=1024
We will think that that is an unused partition (/dev/sdb1) on a 2nd block instrument (/dev/sdb) connected to each nodes.
Step three: Configuring DRBD
DRBD’s major configuration document is situated at /and so forth/drbd.conf and further config information will also be discovered within the /and so forth/drbd.d listing.
To reflect garage, we want to upload the important configurations within the /and so forth/drbd.d/global_common.conf document which incorporates the worldwide and commonplace sections of the DRBD configuration and we will be able to outline sources in .res information.
Let’s make a backup of the unique document on each nodes, then then open a brand new document for modifying (use a textual content editor of your liking).
# mv /and so forth/drbd.d/global_common.conf /and so forth/drbd.d/global_common.conf.orig # vim /and so forth/drbd.d/global_common.conf
Add the next strains in in each information:
Save the document, after which shut the editor.
Let’s in short color extra mild on the road protocol C. DRBD helps 3 distinct replication modes (thus 3 levels of replication synchronicity) which might be:
- protocol A: Asynchronous replication protocol; it’s maximum ceaselessly utilized in lengthy distance replication eventualities.
- protocol B: Semi-synchronous replication protocol aka Memory synchronous protocol.
- protocol C: recurrently used for nodes in brief distanced networks; it’s via some distance, essentially the most recurrently used replication protocol in DRBD setups.
Important: The selection of replication protocol influences two elements of your deployment: coverage and latency. And throughput, in contrast, is in large part impartial of the replication protocol decided on.
Step four: Adding a Resource
A useful resource is the collective time period that refers to all facets of a selected replicated information set. We will outline our useful resource in a document known as /and so forth/drbd.d/take a look at.res.
Add the next content material to the document, on each nodes (take note to substitute the variables within the content material with the true values to your surroundings).
Take be aware of the hostnames, we want to specify the community hostname which will also be acquired via operating the command uname -n.
useful resource take a look at }
- on hostname: the on segment states which host the enclosed configuration statements practice to.
- take a look at: is the title of the brand new useful resource.
- instrument /dev/drbd0: specifies the brand new digital block instrument controlled via DRBD.
- disk /dev/sdb1: is the block instrument partition which is the backing instrument for the DRBD instrument.
- meta-disk: Defines the place DRBD retail outlets its metadata. Using Internal implies that DRBD retail outlets its meta information on the similar bodily lower-level instrument as the true manufacturing information.
- cope with: specifies the IP cope with and port choice of the respective node.
Also be aware that if the choices have equivalent values on each hosts, you’ll be able to specify them immediately within the useful resource segment.
For instance the above configuration will also be restructured to:
useful resource take a look at
Step four: Initializing and Enabling Resource
To have interaction with DRBD, we will be able to use the next management gear which keep up a correspondence with the kernel module so as to configure and administer DRBD sources:
- drbdadm: a high-level management device of the DRBD.
- drbdsetup: a lower-level management device for to connect DRBD gadgets with their backing block gadgets, to arrange DRBD instrument pairs to reflect their backing block gadgets, and to investigate cross-check the configuration of operating DRBD gadgets.
- Drbdmeta:is the meta information control device.
After including the entire preliminary useful resource configurations, we will have to convey up the useful resource on each nodes.
# drbdadm create-md take a look at
Next, we must allow the useful resource, which can connect the useful resource with its backing instrument, then it units replication parameters, and connects the useful resource to its peer:
# drbdadm up take a look at
Now for those who run the lsblk command, you are going to realize that the DRBD instrument/quantity drbd0 is related to the backing instrument /dev/sdb1:
To disable the useful resource, run:
# drbdadm down take a look at
To test the useful resource standing, run the next command (be aware that the Inconsistent/Inconsistent disk state is predicted at this level):
# drbdadm standing take a look at OR # drbdsetup standing take a look at --verbose --statistics #for a extra detailed standing
Step five: Set Primary Resource/Source of Initial Device Synchronization
At this degree, DRBD is now able for operation. We now want to inform it which node must be used because the supply of the preliminary instrument synchronization.
Run the next command on just one node to get started the preliminary complete synchronization:
# drbdadm number one --force take a look at # drbdadm standing take a look at
Once the synchronization is entire, the standing of each disks must be UpToDate.
Step 6: Testing DRBD Setup
Finally, we want to take a look at if the DRBD instrument will paintings smartly for replicated information garage. Remember, we used an empty disk quantity, due to this fact we will have to create a filesystem on the instrument, and mount it, to take a look at if we will be able to use it for replicated information garage.
We can create a filesystem on the instrument with the next command, on the node the place we began the preliminary complete synchronization (which has the useful resource with number one function):
# mkfs -t ext4 /dev/drbd0
Then mount it as proven (you’ll be able to give the mount level a suitable title):
# mkdir -p /mnt/DRDB_PRI/ # mount /dev/drbd0 /mnt/DRDB_PRI/
Now reproduction or create some information within the above mount level and do a protracted checklist the use of ls command:
# cd /mnt/DRDB_PRI/ # ls -l
Next, unmount the the instrument (be sure that the mount isn’t open, trade listing after unmounting it to save you any mistakes) and alter the function of the node from number one to secondary:
# umount /mnt/DRDB_PRI/ # cd # drbdadm secondary take a look at
On the opposite node (which has the useful resource with a secondary function), make it number one, then mount the instrument on it and carry out a protracted checklist of the mount level. If the setup is operating effective, the entire information saved within the quantity must be there:
# drbdadm number one take a look at # mkdir -p /mnt/DRDB_SEC/ # mount /dev/drbd0 /mnt/DRDB_SEC/ # cd /mnt/DRDB_SEC/ # ls -l
For additional info, see the person pages of the consumer area management gear:
# guy drbdadm # guy drbdsetup # guy drbdmeta
Reference: The DRBD User’s Guide.
DRBD is terribly versatile and flexible, which makes it a garage replication answer appropriate for including HA to with reference to any software. In this text, we’ve proven how to set up DRBD in CentOS 7 and in short demonstrated how to use it to reflect garage. Feel loose to proportion your ideas with us by means of the comments shape beneath.