Two Pi R

Although many people are excited about the hardware-hacking possibilities with the Raspberry Pi, one of the things that interests me most is the fact that it is essentially a small low-power Linux server I can use to replace other Linux servers I already have around the house. In previous columns, I've talked about using the Raspberry Pi to replace the server that controls my beer fridge and colocating a Raspberry Pi in Austria. After I colocated a Raspberry Pi in Austria, I started thinking about the advantages and disadvantages of using something with so many single points of failure as a server I relied on, so I started thinking about ways to handle that single point of failure. When you see "Two Pi R", you probably think the R stands for the radius for a circle. To me, it stands for redundancy. I came to the conclusion that although one Pi isn't redundant, two Pi are.

So, in this article, I'm building the foundation for setting up redundant services with a pair of Raspberry Pis. I start with setting up a basic clustered network filesystem using GlusterFS. In later articles, I'll follow up with how to take advantage of this shared storage to set up other redundant services. Of course, although I'm using a Raspberry Pi for this article, these same steps should work with other hardware as well.

Configure the Raspberry Pis

To begin, I got two SD cards and loaded them with the latest version of the default Raspberry Pi distribution from the official Raspberry Pi downloads page, the Debian-based Raspbian. I followed the documentation to set up the image and then booted in to both Raspberry Pis while they were connected to a TV to make sure that the OS booted and that SSH was set to start by default (it should be). You probably also will want to use the raspi-config tool to expand the root partition to fill the SD card, since you will want all that extra space for your redundant storage. After I confirmed I could access the Raspberry Pis remotely, I moved them away from the TV and over to a switch and rebooted them without a display connected.

By default, Raspbian will get its network information via DHCP; however, if you want to set up redundant services, you will want your Raspberry Pis to keep the same IP every time they boot. In my case, I updated my DHCP server so that it handed out the same IP to my Raspberry Pis every time they booted, but you also could edit the /etc/network/interfaces file on your Raspberry Pi and change:

iface eth0 inet dhcp


auto eth0
iface eth0 inet static

Of course, modify the networking information to match your personal network, and make sure that each Raspberry Pi uses a different IP. I also changed the hostnames of each Raspberry Pi, so I could tell them apart when I logged in. To do this, just edit /etc/hostname as root and change the hostname to what you want. Then, reboot to make sure that each Raspberry Pi comes up with the proper network settings and hostname.

Configure the GlusterFS Server

GlusterFS is a userspace clustered filesystem that I chose for this project because of how simple it makes configuring shared network filesystems. To start, choose a Raspberry Pi that will act as your master. What little initial setup you need to do will be done from the master node, even though once things are set up, nodes should fail over automatically. Here is the information about my environment:

Master hostname: pi1
Master IP:
Master brick path: /srv/gv0
Secondary hostname: pi2
Secondary IP:
Secondary brick path: /srv/gv0

Before you do anything else, log in to each Raspberry Pi, and install the glusterfs-server package:

$ sudo apt-get install glusterfs-server

GlusterFS stores its files in what it calls bricks. A brick is a directory path on the server that you set aside for gluster to use. GlusterFS then combines bricks to create volumes that are accessible to clients. GlusterFS potentially can stripe data for a volume across bricks, so although a brick may look like a standard directory full of files, once you start using it with GlusterFS, you will want to modify it only via clients, not directly on the filesystem itself. In the case of the Raspberry Pi, I decided just to create a new directory called /srv/gv0 for my first brick on both Raspberry Pis:

$ sudo mkdir /srv/gv0

In this case, I will be sharing my standard SD card root filesystem, but in your case, you may want more storage. In that situation, connect a USB hard drive to each Raspberry Pi, make sure the disks are formatted, and then mount them under /srv/gv0. Just make sure that you update /etc/fstab so that it mounts your external drive at boot time. It's not required that the bricks are on the same directory path or have the same name, but the consistency doesn't hurt.


Kyle Rankin is Chief Security Officer at Purism, a company focused on computers that respect your privacy, security, and freedom. He is the author of many books including Linux Hardening in Hostile Networks, DevOps Troubleshooting and The Official Ubuntu


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Thank you for teaching this

Cellular Specs's picture

Thank you for teaching this configuration
I just started to learn about the Raspberry Pi
Cellular Specs

It is Canada’s largest online

sollen's picture

It is Canada’s largest online auto parts store and offers hundreds of thousands of vehicle applications in everything from brake parts 27W Forklift driving lamps LED to transfer cases. Parts are purchased over the company’s secure website and delivered to your home or business within one to three business days.

It is Canada’s largest online

sollen's picture

It is Canada’s largest online auto parts store and offers hundreds of thousands of vehicle applications in everything from brake parts to transfer 27W Forklift driving lamps LED cases. Parts are purchased over the company’s secure website and delivered to your home or business within one to three business days.

Services on GlusterFS

Tha-Fox's picture

I believe it's not possible to put your root to GlusterFS but I'm planning to install ownCloud on GlusterFS. Have you any idea how fast connection it need for replication to work? I would have one server at the office and another one at home and the connection is 60 / 10 Mbit/s between them.

Geo-Replication Feature in GlusterFS - Asynchronous Replication

JMW's picture

The geo-replication feature was created specifically for those cases where you have a WAN link or some other unreliable network connection. It's eventually consistent, as opposed to the default replication that's synchronous and strongly consistent.

Here's the required command:

Unfortunately, LJ comments bot doesn't allow me to post links here :( but if you google for "geo-replication glusterfs" you'll find some good recipes.

GlusterFS will not work good

Anonymous's picture

GlusterFS will not work good over WAN.

Reply to comment | Linux Journal

moving company Texas's picture

Wonderful items from you, man. I have understand your stuff previous to and you are simply extremely magnificent.
I actually like what you've obtained here, really like
what you are saying and the way during which you are
saying it. You're making it enjoyable and
you continue to take care of to keep it wise. I cant wait to read far more from you.
This is really a tremendous website.