How to Set Up a Distributed Filesystem (e.g., GlusterFS) on FreeBSD

This article explains how to set up a distributed filesystem (e.g., GlusterFS) on FreeBSD.

A distributed filesystem is a crucial solution for organizations that require high availability, redundancy, and scalability in their storage infrastructure. GlusterFS is a widely used open-source distributed filesystem that aggregates storage resources across multiple nodes into a single global namespace. This guide walks you through setting up GlusterFS on the FreeBSD operating system.

Prerequisites

Before setting up GlusterFS, ensure you have the following:

  • FreeBSD installed on at least two nodes: Each participating machine should run FreeBSD 12 or later.
  • Root or sudo privileges: Administrative access is necessary for installation and configuration.
  • Network connectivity: All nodes must communicate with each other over a stable network.
  • Sufficient disk space: Ensure adequate storage for your distributed volume.

Step 1: Preparing FreeBSD Nodes

1.1 Update the System

Before installing any new software, update your FreeBSD system to the latest available version.

sudo freebsd-update fetch install
sudo pkg update && sudo pkg upgrade

1.2 Configure Hostnames and Networking

Set up a proper hostname and ensure each node can resolve the others.

sudo hostnamectl set-hostname node1.example.com

Add entries to /etc/hosts for easy hostname resolution:

192.168.1.10 node1.example.com node1
192.168.1.11 node2.example.com node2

Ensure SSH access is enabled for remote administration:

sudo service sshd enable
sudo service sshd start

1.3 Install Required Packages

Install the necessary dependencies for GlusterFS.

sudo pkg install -y fusefs-libs fusefs-kmod

Load the FUSE kernel module:

sudo kldload fusefs

To make this persistent across reboots, add it to /etc/rc.conf:

echo 'fusefs_load="YES"' | sudo tee -a /boot/loader.conf

Step 2: Install GlusterFS on FreeBSD

GlusterFS is not included in the default FreeBSD repositories, so it needs to be compiled from source.

2.1 Install Build Dependencies

Install the necessary packages for building GlusterFS:

sudo pkg install -y autoconf automake bison flex gmake libtool pkgconf python py39-setuptools readline

2.2 Clone and Compile GlusterFS

Download and compile GlusterFS from its source repository.

git clone https://github.com/gluster/glusterfs.git
cd glusterfs
./autogen.sh
./configure --prefix=/usr/local --disable-tiering --disable-debug --disable-linux-io_uring
make -j$(sysctl -n hw.ncpu)
sudo make install

2.3 Verify Installation

Check that GlusterFS binaries are installed correctly:

glusterfsd --version

Step 3: Configure GlusterFS Storage Pool

3.1 Start the GlusterFS Service

Enable and start the GlusterFS service on all nodes:

sudo service glusterd enable
sudo service glusterd start

Verify that the service is running:

sudo service glusterd status

3.2 Add Nodes to the Trusted Pool

Run the following command on the first node to add the second node to the GlusterFS pool:

gluster peer probe node2.example.com

Confirm that all nodes are in the trusted pool:

gluster peer status

Step 4: Create and Mount a GlusterFS Volume

4.1 Create a Storage Directory on Each Node

sudo mkdir -p /data/gluster

4.2 Create the Distributed Volume

On the first node, create the GlusterFS volume:

gluster volume create gv0 replica 2 node1:/data/gluster node2:/data/gluster force

Start the volume:

gluster volume start gv0

Verify volume status:

gluster volume info

4.3 Mount the GlusterFS Volume

Ensure the glusterfs mount helper is available:

sudo pkg install -y fusefs-glusterfs

On each client machine, mount the volume:

sudo mkdir -p /mnt/glusterfs
sudo mount_glusterfs node1:/gv0 /mnt/glusterfs

To make the mount persistent, add the following to /etc/fstab:

node1:/gv0 /mnt/glusterfs glusterfs defaults,_netdev 0 0

Step 5: Test and Verify the Setup

5.1 Check Data Replication

Create a test file on the mounted volume:

echo "GlusterFS Test" | sudo tee /mnt/glusterfs/testfile.txt

Check if the file is replicated across nodes:

ls /data/gluster/

5.2 Check GlusterFS Health

gluster volume status

If any issues arise, check logs in /var/log/glusterfs/.

Step 6: Enable High Availability (Optional)

For high availability, you can set up an NFS or SMB front end or use a load balancer.

Enable NFS support:

gluster volume set gv0 nfs.disable off

Mount using NFS:

sudo mount -t nfs -o vers=3 node1:/gv0 /mnt/nfs_gluster

Conclusion

Setting up a distributed filesystem like GlusterFS on FreeBSD provides scalability, redundancy, and ease of management. By following this guide, you have successfully installed, configured, and tested GlusterFS on multiple FreeBSD nodes. You can now expand the storage cluster as needed by adding more nodes and configuring advanced features like geo-replication and automated failover.

For further optimizations, consider fine-tuning performance parameters, implementing a backup strategy, and securing access to your storage cluster.