I was always fascinated with distributed filesystems and wanted to learn more about Gluster since it is becoming more popular in larger open-source projects. Since I have a few Raspberry Pi’s, I thought that now is the best time to learn. This blog post will explain how to run Gluster on a two-node Raspberry Pi cluster from a Docker container.
- Two Raspberry Pi’s (rpi-1 and rpi-2)
- Running a Gluster image from a local Docker registry
- Hostnames are resolvable in /etc/hosts on both Pi’s
- Docker 1.12.x installed
1. Creating the Docker images
To start, I will create a file named Dockerfile on rpi-1 with the following contents:
Now I need to build the Docker file. For easier deployments, you can push it to a local Docker registry. If you are not using a local registry, build the image on each host.
2. Run the Docker image on the hosts
On rpi-1 and rpi-2:
Privileged mode is required for Gluster to work properly. I are using host networking for simplicity so I do not have to worry about exposing each Gluster port. The -v argument is for storing the data volume information outside of the container directly on the host.
3. Add the second node to the cluster
To add a node to the cluster, I need to probe rpi-2 from rpi-1 so that it will be added to the cluster.
Now I can check the status of the probe to make sure that rpi-2 has been added successfully:
Great, now I have a small cluster. Let’s proceed on creating a data volume.
4. Create a data volume
A replicated data volume will replicate data across all the hosts in the cluster. Before I can create the volume, I will need to create the data volume directories on each host:
rpi-1 and rpi-2:
Now I will create a replicated data volume.
5. Mount the data volume directly from a host
To access the Gluster volume outside of the Docker images, I will need to install the Gluster client software. The following commands will install the software, mount the Gluster volume, and create a test file.
I see the file called “test”. To conclude, I recommend to mount the volume locally on each host and the replication will be handled by Gluster. I will now explain how to add a node to the Gluster cluster. If that does not interest you, then this concludes the blog post and I hope you have a great day and learned something.
6. Adding a node
Now that I have a two node Gluster cluster up and running, I can add a node. I created a new node called rpi-3, installed Docker, and run the Gluster container. With the container running, I can create the data directory like I did for the other nodes.
Now I will go back to rpi-1 and add rpi-3 to the cluster by running the probe command.
Now I have three replicas of the data. Let’s verify this by checking the volume information.
I can see that all three nodes are good. Let’s check the status of the two peers:
Great, all nodes are online. I hope that you learned how to use Gluster on the Raspberry Pi.