Mark this article as obsolete: This package is no longer available in current versions of Alpine. Minor formatting, spelling, and grammar improvements as well.
← Older revision | Revision as of 04:50, 6 September 2023 | ||
Line 1: | Line 1: | ||
{{Obsolete|drbd is no longer available for any supported versions of Alpine Linux}} | |||
This tutorial shows how to configure a Distributed Replicated Block Device (DRBD) device on Alpine Linux. It assumes you are familiar with what DRBD is and why you would want to use it. If this is not the case, see the [https://linbit.com/drbd/ DRBD home page]. | This tutorial shows how to configure a Distributed Replicated Block Device (DRBD) device on Alpine Linux. It assumes you are familiar with what DRBD is and why you would want to use it. If this is not the case, see the [https://linbit.com/drbd/ DRBD home page]. | ||
Line 6: | Line 8: | ||
= About the Configuration = | = About the Configuration = | ||
The examples in this tutorial use two hosts: ''alpine1.domain'' and ''alpine2.domain''. Both are virtual machines. Because the VMs need to communicate with each other, it's important to use a bridged adapter or internal network rather than Network | The examples in this tutorial use two hosts: ''alpine1.domain'' and ''alpine2.domain''. Both are virtual machines. Because the VMs need to communicate with each other, it's important to use a bridged adapter or internal network rather than Network Address Translation (NAT). | ||
== Virtual Hardware == | == Virtual Hardware == | ||
Line 14: | Line 16: | ||
== Alpine O.S. == | == Alpine O.S. == | ||
The hosts are sys installs onto /dev/sda. The ROOT_SIZE environment variable was used to constrain the partition size to 4G (e.g. export ROOT_SIZE=4096 ; setup-alpine) and leave some free space on the disk. The free space will be used to create a logical volume for DRBD. | The hosts are sys installs onto {{path|/dev/sda}}. The <code>ROOT_SIZE</code> environment variable was used to constrain the partition size to 4G (e.g. export ROOT_SIZE=4096 ; setup-alpine) and leave some free space on the disk. The free space will be used to create a logical volume for DRBD. | ||
= Creating a Device for DRBD = | = Creating a Device for DRBD = | ||
A DRBD device needs a block device at its foundation. In this tutorial, I'm using a logical volume (/dev/vg0/drbd0). You can also use a regular | A DRBD device needs a block device at its foundation. In this tutorial, I'm using a logical volume ({{path|/dev/vg0/drbd0}}). You can also use a partiton on a regular disk such as {{path|/dev/sda4}} if you want. | ||
The process to create the device requires you to perform these steps: | The process to create the device requires you to perform these steps: | ||
Line 23: | Line 25: | ||
# Install necessary packages | # Install necessary packages | ||
# Create a partition for LVM | # Create a partition for LVM | ||
# Create the | # Create the physical volume, volume group, and logical volume | ||
# Configure LVM to start when the system boots. | # Configure LVM to start when the system boots. | ||
The commands you'll run to install packages and create the partition look like this: | The commands you'll run to install packages and create the partition look like this: | ||
{{cmd|apk add cfdisk lvm2 | |||
cfdisk /dev/sda}} | |||
You'll need to create a partition in the free space area of the drive, change the type to Linux LVM, write, and quit. | You'll need to create a partition in the free space area of the drive, change the type to Linux LVM, write, and quit. | ||
Once that's done, you can go ahead with the logical volume. Assuming /dev/sda4 is the partition for LVM, the commands will look like this: | Once that's done, you can go ahead with the logical volume. Assuming {{path|/dev/sda4}} is the partition for LVM, the commands will look like this: | ||
{{cmd|pvcreate /dev/sda4 | |||
vgcreate vg0 /dev/sda4 | |||
lvcreate -n drbd0 -L 1G vg0 | |||
rc-update add lvm boot}} | |||
The logical volume /dev/vg0/drbd0 should be ready for use. Run <code>ls /dev/vg0/drbd0</code> to verify before moving on. | The logical volume {{path|/dev/vg0/drbd0}} should be ready for use. Run <code>ls /dev/vg0/drbd0</code> to verify before moving on. | ||
= DRBD Packages and Config Files = | = DRBD Packages and Config Files = | ||
Line 51: | Line 53: | ||
First, install the packages. | First, install the packages. | ||
{{cmd|apk add drbd lsblk}} | |||
Next, you'll need the hostname and IP address for both hosts. | Next, you'll need the hostname and IP address for both hosts. | ||
{{cmd|uname -n | |||
ifconfig eth0}} | |||
Finally, you can create the DRBD resource configuration file. In this example it's called drbd0.res and it resides in the /etc/drbd.d/ directory. This file needs to be created on both hosts. | Finally, you can create the DRBD resource configuration file. In this example it's called drbd0.res and it resides in the {{path|/etc/drbd.d/}} directory. This file needs to be created on both hosts. | ||
The contents will look similar to this example: | The contents will look similar to this example: | ||
{{cat|/etc/drbd.d/drbd0.res|<nowiki> | |||
resource drbd0 { | resource drbd0 { | ||
device minor 0; | device minor 0; | ||
Line 74: | Line 76: | ||
address 192.168.0.12:7789; | address 192.168.0.12:7789; | ||
} | } | ||
} | }</nowiki>}} | ||
The line <code>disk /dev/vg0/drbd0;</code> should reflect the name of the device you're using. If you're not using a logical volume, it might be something like <code>disk /dev/sda4;</code> | The line <code>disk /dev/vg0/drbd0;</code> should reflect the name of the device you're using. If you're not using a logical volume, it might be something like <code>disk /dev/sda4;</code> | ||
Line 85: | Line 87: | ||
Now that the config files are in place, drbdadm is used to create the DRBD device and make it available for use. It only takes two commands. | Now that the config files are in place, drbdadm is used to create the DRBD device and make it available for use. It only takes two commands. | ||
{{cmd|drbdadm create-md drbd0 | |||
drbdadm up drbd0}} | |||
You can use <code>lsblk</code> and <code>drbdadm status</code> to verify your success. | You can use <code>lsblk</code> and <code>drbdadm status</code> to verify your success. | ||
Line 151: | Line 153: | ||
# Mount drbd0's file system on alpine2. | # Mount drbd0's file system on alpine2. | ||
But before that, create a test file under /mnt on alpine1. Anything is fine, it's just to verify the process works. | But before that, create a test file under {{path|/mnt}} on alpine1. Anything is fine, it's just to verify the process works. | ||
Then, when alpine1 is powered off, run the drbdadm command to make alpine2 the primary: | Then, when alpine1 is powered off, run the drbdadm command to make alpine2 the primary: | ||
Line 164: | Line 166: | ||
peer connection:Connecting | peer connection:Connecting | ||
The real proof is in the file system and the test file you created. To verify, mount alpine2's /dev/drbd0 on /mnt and see what it contains. | The real proof is in the file system and the test file you created. To verify, mount alpine2's {{path|/dev/drbd0}} on {{path|/mnt}} and see what it contains. | ||
alpine2:~# e2fsck /dev/drbd0 | alpine2:~# e2fsck /dev/drbd0 |
Distro