GlusterFS, developed by RedHat, is a free and open-source distributed file system that provides scalability and high availability for managing large amounts of data. In this tutorial, we will guide you through the process of installing GlusterFS on Debian 11 servers, setting up a replicated volume, and testing the replication and high availability.
Prerequisites
Before we begin, make sure you have the following requirements:
- Two or three Debian 11 servers.
- A non-root user with sudo/administrator root privileges.
This tutorial will use three Debian 11 servers with the following details:
Hostname |
IP Address |
---|---|
node1 |
192.168.5.50 |
node2 |
192.168.5.56 |
node3 |
192.168.5.57 |
Setup Hostname and FQDN
The first step is to set up the hostname and fully qualified domain name (FQDN) for each Debian server that will be used by GlusterFS. You can set up the hostname using the hostnamectl
command and the FQDN via the /etc/hosts
file.
To set up the hostname, run the following command on each server:
# run on node1 sudo hostnamectl set-hostname node1.home.lan # run on node2 sudo hostnamectl set-hostname node2.home.lan # run on node3 sudo hostnamectl set-hostname node3.home.lan
Next, open the /etc/hosts
file on each server using your preferred text editor. In this tutorial, we will use the nano editor:
sudo nano /etc/hosts
Add the following lines to the file, replacing the IP addresses and hostnames with the correct values:
192.168.5.50 node1.home.lan node1 192.168.5.56 node2.home.lan node2 192.168.5.57 node3.home.lan node3
Save the file and exit the editor. Finally, verify the FQDN on each server by running the following command:
hostname -f
You should see the correct FQDN for each server.
Setting up Disk Partition
It is recommended to use a separate disk for the GlusterFS deployment. In this example, each Debian server has an additional disk /dev/vdb
that will be used for GlusterFS. We will show you how to set up a new disk on a Linux system using the fdisk
command.
To start, verify the list of available disks on your Debian server by running the following command:
sudo fdisk -l
You should see a list of disks, including the /dev/vdb
disk.
Next, run the fdisk
command to configure the /dev/vdb
disk:
sudo fdisk /dev/vdb
Follow these steps to create a new partition:
- Enter the
n
command to create a new partition. - Choose the partition type. For a primary partition, enter
p
. - Specify the number of partitions. In this example, we will create one partition, so enter
1
. - Accept the default values for the first and last sectors.
- Set the size of the partition. For a 5GB partition, enter
+5GB
. - Finally, enter
w
to save the changes.
Verify that the new partition /dev/vdb1
has been created by running the following command:
sudo fdisk -l
You should see the new partition listed.
Now, format the new partition with the ext4 filesystem format using the following command:
sudo mkfs -t ext4 /dev/vdb1
Once the formatting is complete, the new partition is ready for use.
Setup Auto-Mount Partition
In this step, we will set up auto-mount for the new partition /dev/vdb1
using the /etc/fstab
file. We will also create a new directory that will be used to store data in GlusterFS.
First, create a target directory for each server by running the following commands:
# run on node1 sudo mkdir -p /data/node1 # run on node2 sudo mkdir -p /data/node2 # run on node3 sudo mkdir -p /data/node3
Next, open the /etc/fstab
file using the nano editor:
sudo nano /etc/fstab
Add the following lines to the file to automatically mount the new partition:
#for node1 /dev/vdb1 /data/node1 ext4 defaults 0 1 #for node2 /dev/vdb1 /data/node2 ext4 defaults 0 1 #for node3 /dev/vdb1 /data/node3 ext4 defaults 0 1
Save the file and exit the editor.
To mount the new partition, run the following command:
sudo mount -a
Finally, create a new directory brick0
on the newly mounted partition for each server:
# run on node1 sudo mkdir -p /data/node1/brick0 # run on node2 sudo mkdir -p /data/node2/brick0 # run on node3 sudo mkdir -p /data/node3/brick0
The new partition is now mounted and ready to be used by GlusterFS.
Installing GlusterFS Server
Now that we have set up the disk partition, we can proceed with installing the GlusterFS server package on the Debian servers.
First, install the basic dependencies by running the following command:
sudo apt install gnupg2 apt-transport-https software-properties-common
Next, download the GPG key for the GlusterFS repository and convert it to the file /usr/share/keyrings/glusterfs-archive-keyring.gpg
:
curl https://download.gluster.org/pub/gluster/glusterfs/10/rsa.pub | gpg --dearmor > /usr/share/keyrings/glusterfs-archive-keyring.gpg
Create new environment variables and add the GlusterFS repository to your system by running the following command:
DEBID=$(grep 'VERSION_ID=' /etc/os-release | cut -d '=' -f 2 | tr -d '"')
DEBVER=$(grep 'VERSION=' /etc/os-release | grep -Eo '[a-z]+')
DEBARCH=$(dpkg --print-architecture)
echo "deb [signed-by=/usr/share/keyrings/glusterfs-archive-keyring.gpg] https://download.gluster.org/pub/gluster/glusterfs/LATEST/Debian/${DEBID}/${DEBARCH}/apt ${DEBVER} main" | sudo tee /etc/apt/sources.list.d/gluster.list
Update and refresh your package index by running the following command:
sudo apt update
Finally, install the GlusterFS server package by running the following command:
sudo apt install glusterfs-server
Start and enable the GlusterFS service by running the following commands:
sudo systemctl start glusterd sudo systemctl enable glusterd
Verify the status of the GlusterFS service by running the following command:
sudo systemctl status glusterd
If the service is running and enabled, you will see the output active (running)
.
Initializing Storage Pool
In this step, we will initialize the GlusterFS cluster with three Debian servers: node1, node2, and node3. We will initialize the cluster from node1
and add the other nodes to the cluster.
Before proceeding, make sure that each server is accessible via the hostname or FQDN. You can verify this by running the ping
command to each server.
On the node1
terminal, run the following commands to initialize the GlusterFS cluster:
sudo gluster peer probe node2.home.lan sudo gluster peer probe node3.home.lan
If successful, you will see the output peer probe: success
.
On the node2
terminal, run the following command to verify the cluster status:
sudo gluster peer status
You should see the status Connected
for node1
and node3
.
Repeat the same step on the node3
terminal to verify the cluster status:
sudo gluster peer status
Again, you should see the status Connected
for node1
and node2
.
You can also verify the list of pools on the GlusterFS cluster by running the following command on any server:
sudo gluster pool list
At this point, you have successfully initialized the GlusterFS cluster with three Debian servers.
Creating Replicated Volume
In GlusterFS, you can create different types of volumes, such as Distributed, Replicated, Distributed Replicated, Dispersed, and Distributed Dispersed volumes. In this step, we will create a Replicated volume with three servers: node1, node2, and node3. This will automatically replicate data across the servers in the storage pool.
Run the following command to create a new Replicated volume named testVolume
:
sudo gluster volume create testVolume replica 3 node1.home.lan:/data/node1/brick0 node2.home.lan:/data/node2/brick0 node3.home.lan:/data/node3/brick0
If successful, you will see the output volume create: testVolume: success
.
Start the testVolume
by running the following command:
sudo gluster volume start testVolume
You should see the output volume start: testVolume: success
.
To get detailed information about the testVolume
, run the following command:
sudo gluster volume info
You will see information such as the volume type, default transfer protocol, and the servers involved in the replication.
Congratulations! You have now created a Replicated volume on top of the GlusterFS cluster.
Mount GlusterFS Volume on Client
In this step, we will show you how to mount the GlusterFS volume on a client machine. For this example, we will use an Ubuntu/Debian-based machine with the hostname client
.
Before proceeding, make sure that the client machine can access the GlusterFS cluster. Open the /etc/hosts
file on the client machine using the nano editor:
sudo nano /etc/hosts
Add the following lines to the file, replacing the IP addresses and hostnames with the correct values:
192.168.5.50 node1.home.lan node1 192.168.5.56 node2.home.lan node2 192.168.5.57 node3.home.lan node3
Save the file and exit the editor.
Install the glusterfs-client
package on the client machine by running the following command:
sudo apt install glusterfs-client
Create a target directory for mounting the GlusterFS volume by running the following command:
sudo mkdir /data
Mount the GlusterFS volume testVolume
to the /data
directory by running the following command:
sudo mount.glusterfs node1.home.lan:/testVolume /data
Verify that the volume is successfully mounted by running the following command:
sudo df -h
You should see the GlusterFS volume testVolume
mounted to the /data
directory.
To set up auto-mount for the GlusterFS volume, open the /etc/fstab
file using the nano editor:
sudo nano /etc/fstab
Add the following line to the file:
node1.home.lan:/testVolume /data glusterfs defaults,_netdev 0 0
Save the file and exit the editor.
Congratulations! You have successfully mounted the GlusterFS volume on the client machine and set up auto-mount.
Test Replication and High-Availability
Now, let’s test the replication and high availability of the GlusterFS cluster.
On the client machine, navigate to the /data
directory and create some files:
cd /data touch file{1..15}.md
To verify the replication, go to the node1
terminal and navigate to the /data/node1/brick0
directory. Run the ls
command to check the list of files and directories:
cd /data/node1/brick0 ls
You should see the files file1.md
to file15.md
in the directory.
Repeat the same steps on the node2
and node3
terminals to check the files in their respective directories.
To test the high availability, you can turn off or shut down the node1
server. On the node1
terminal, run the following command to shut down the server:
sudo poweroff
On the node2
terminal, run the following command to check the status of the GlusterFS cluster:
sudo gluster peer status
You should see that node1
is now disconnected.
On the client machine, navigate to the /data
directory and run the ls
command:
cd /data
ls
You should still see the files file1.md
to file15.md
.
Congratulations! The replication and high availability of the GlusterFS cluster are working as expected.
Conclusion
In this tutorial, we have covered the installation and configuration of GlusterFS on Debian 11 servers. We have set up a replicated volume and tested the replication and high availability of the GlusterFS cluster. You can now leverage your GlusterFS cluster by adding more disks and servers to create a scalable and reliable network file system.
For more information on GlusterFS administration, refer to the official GlusterFS documentation.
Remember, if you need reliable and scalable cloud hosting solutions, consider Shape.host services. Shape.host offers Linux SSD VPS, providing fast and secure virtual private servers for your business needs. Visit Shape.host for more information.
Now, you are ready to take advantage of GlusterFS and empower your business with efficient data management and storage capabilities.