Skip to navigation

Set up GlusterFS on two nodes

What is GlusterFS?

GlusterFS is a distributed file system which can be used to build volumes that span several hosts. It's used in a variety large scale cloud and web hosting applications.

A GlusterFS volume is a virtual disk which can be read and written from across a network. GlusterFS can be used to build high perfomance storage clusters that hold large volumes of data.

The data in GlusterFS volumes is divided into bricks, where each brick is a portion of a pysical drive that's used to store volume data.  In practice a brick is just a directory whose contents are shared over the network.

Bricks can be replicated for improved fault tolerance.  If one of the disks in a GlusterFS node dies, all the data in that drive's brick will be lost.  If the cluster has been configured for replication, then any brick that is lost when a disk fails is available on another node.  The broken disk just needs to be replaced and GlusterFS will automatically rebuild the lost brick from the contents of the other bricks.

Bricks can be distributed across more than one server to improve performance.  This means that individual files may be written to different servers, even if those files are in the same directory.  Distributing files helps to balance the load on the servers.  If a volume contains a lot of files, spreading them across more than one server helps to spread the load when they are accessed.

GlusterFS supports striping where parts of a file can be written to different disks. Usually this is only recommended for very large files.

Setting up two GlusterFS nodes

I installed Raspbian on three Banana Pis - one client, and two nodes for a simple storage cluster.

GlusterFS on Banana Pi servers

The client Banana Pi gets its IP address from the local DHCP server, and the Gluster nodes have static IP addresses - 192.168.0.30 and 192.168.0.31.

Connect to each node using ssh in different terminal windows:

ssh bananapi@192.168.0.30

And in another terminal:

ssh bananapi@192.168.0.31

I ran the bpi-config program on both Gluster nodes to expand the SD card's partition and change some basic settings like host names and passwords:

sudo bpi-config

Next, I opened /etc/resolv.conf in nano, and entered DNS  server IP addresses:

sudo nano /etc/resolv.conf

You can use Google's DNS servers for convenience:

nameserver 8.8.8.8
nameserver 8.8.4.4

Update Linux and install glusterfs-server:

sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install glusterfs-server -y

Open /etc/hosts in a text editor on each node so that you can add the host names of the nodes:

sudo nano /etc/hosts

In the hosts file on the first node, add these entries:

127.0.1.1  glus1.storage glus1
192.168.0.31  glus2.storage glus2

Add these entries to the host file on the second node:

127.0.1.1  glus2.storage glus2
192.168.0.30  glus1.storage glus1

You also need to open the hosts file on the client, and add both names:

192.168.0.30  glus1.storage glus1
192.168.0.31  glus2.storage glus2

On both nodes, you need to create directories to store the volume's contents:

sudo mkdir --parents /srv/brick/glusv0

Create a GlusterFS trusted storage pool

In the ssh session for the first node, run this command to tell Gluster to form a server pool with the other node:

sudo gluster peer probe glus2
Probe successful

sudo gluster peer status
Number of Peers: 1

Hostname: glus2
Uuid: 186a69a4-423a-49bb-9061-b2e695328ffb
State: Peer in Cluster (Connected)

On the second node, use the gluster peer probe command to probe the first node:

sudo gluster peer probe glus1

sudo gluster peer status
Number of Peers: 1

Hostname: glus1
Uuid: 0d6dcbcb-e277-444e-b2df-3187330160e3
State: Peer in Cluster (Connected)

Create the volume

You can run the next commands on either node.  First you need to create the volume:

sudo gluster volume create glusv0 replica 2 glus1:/srv/brick/glusv0 glus2:/srv/brick/glusv0
Creation of volume glusv0 has been successful. Please start the volume to access data.

This tells gluster to create a volume called glusv0 with two bricks, where the contents of the brick on glus1 are replicated on glus2.  Start the volume

sudo gluster volume start glusv0
Starting volume glusv0 has been successful

You can get information about the volume with this command:

sudo gluster volume info 

Volume Name: glusv0
Type: Replicate
Status: Started
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: glus1:/srv/brick/glusv0
Brick2: glus2:/srv/brick/glusv0

Mount the volume locally

In order to check that everything is working, mount the volume from the command line of the first node:

sudo mount -t glusterfs glus1:/glusv0 /mnt

Now create a file in the volume:

sudo echo "Hello World" > /mnt/hello.txt

If you also mount the volume on the second node, the file should be accessible:

sudo mount -t glusterfs glus2:/glusv0 /mnt
cat /mnt/hello.txt 
Hello World

Access the volume from the client

I set up another Banana Pi running Raspbian.  Again I used bpi-config to set the hostname and password. 

Update Linux and install glusterfs-client

sudo bpi-config

sudo apt-get update && sudo apt-get upgrade -y

sudo apt-get install glusterfs-client -y

You may need to restart the client Pi.  To mount the volume from the client, run this command:

sudo mount -t glusterfs glus1:/glusv0 /gluster -o backupvolfile-server=glus2

The -o option is used to pass the backupvolfile parameter which sets an alternate host name to access the volume in case the first server goes down.  The client will automatically re-mount the volume via glus2.

In theory adding the following line to the client's fstab file should make the client mount the GlusterFS share at boot:

glus1:/glusv0 /mnt glusterfs defaults,_netdev 0 0

This didn't work because the GlusterFS client wasn't running when the fstab file was processed. Instead, I opened root's crontab file so that I could add a command to mount the share at reboot. This command opens the crontab file:

sudo crontab -u root -e

Add this line, and press control-o and return to save changes, and control-x to quit from nano:

@reboot sleep 10;mount -t glusterfs glus1:/glusv0 /gluster -o backupvolfile-server=glus2

This will execute two commands when the server boots up: the first is just a 10 second delay to allow the GlusterFS daemon to boot, and the second command mounts the volume.

You may need to make your Pi wait longer before running mount. If your Pi doesn't mount the volume when it boots, try using 'sleep 15' instead.  This isn't an ideal way to fix this problem, but it's ok for most uses.

Change the owner of the volume so that it can be accessed by user bananapi:

sudo chown bananapi -R /gluster/

Now your Banana Pi powered storage cluster should be up and running.

Share this page:

comments powered by Disqus