How to Replicate Storage Across Servers using GlusterFS on Ubuntu 16

Try it in our public cloud & Get $50 Credit

GlusterFS is a file system specifically for network-attached storage. It’s highly suitable for applications that involve the cloud and for content delivery, such as streaming music and video. GlusterFS is free and open source under the GNU General Public License version 3.

Getting started

To install GlusterFS, you will need the following:
• 1 Web Server (Cloud Server or Dedicated Server) (WAN + LAN)
• 2 Storage Server with the same configuration (LAN only)


This tutorial will guide you through setting up a shared document root for a web server. Even so, the principles are the same for setting up any other scenario where you wish to share storage between Linux boxes.

Our network setup for this example will look as follows:
• web1:
• gluster1:
• gluster2:

Open each GlusterFS node and web server hosts file in a text editor, so that you can set the hostname properly.

nano /etc/hosts gluster1 gluster2

Next, create the directory that will be used as storage. This directory will be mounted to the web server on each gluster node.

mkdir /data

Install GlusterFS on each gluster node. Enable it to load on server boot.

apt-get install glusterfs-server
systemctl enable glusterfs-server.service

On gluster1, peer the second node.

gluster peer probe gluster2

peer probe: success.

Still on gluster1, display the status of the trusted storage pool.

gluster peer status

Number of Peers: 1
Hostname: gluster2
Uuid: d8120e15-f91d-44ba-94bd-f808d4a75653
State: Peer in Cluster (Connected)

Create the brick directory on each gluster node.


mkdir /data/brick1


mkdir /data/brick2

On gluster1 again, create your storage volume and the replication

gluster volume create glustervol1 replica 2 transport tcp gluster1:/data/brick1 gluster2:/data/brick2 force

Caveat: You must use “force” at the end of the command if the volume is created on the same disk as the system disk (sda). If you are using a second disk for the volume (sdb) you will not need to force the creation of the storage volume.

volume create: glustervol1: success: please start the volume to access data

Start the storage volume on gluster1.

gluster volume start glustervol1

volume start: glustervol1: success

Now grant volume access to the local IP range.

gluster volume set glustervol1 auth.allow 10.0.0.*

volume set: success

You should be done with storage volume setup. Display the status of the storage volume.

gluster volume info

Volume Name: glustervol1
Type: Replicate
Volume ID: 2841e01a-8548-4009-86c2-c67ed3bc67da
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Brick1: gluster1:/data/brick1
Brick2: gluster2:/data/brick2
Options Reconfigured:
auth.allow: 10.0.0.*

You can also now enable some fine tuning of the GlusterFS.

gluster volume set glustervol1 performance.write-behind off
gluster volume set glustervol1 64
gluster volume set glustervol1 "5"
gluster volume set glustervol1 performance.write-behind-window-size 524288
gluster volume set glustervol1 performance.cache-refresh-timeout 1

Now it’s time to set up the web server. Install the basic web server package on your web1 and glusterfs-client.

apt-get install apache2 -y
apt-get install glusterfs-client -y
apt-get install attr -y

Mount the GlusterFS filesystem on your Web1, which is /var/www/html/ in this case.

mount.glusterfs gluster1:/glustervol1 /var/www/html/

Confirm that the GlusterFS filesystem is mounted on your web1.

mount | grep glusterfs

gluster1:/glustervol1 on /var/www/html type fuse.glusterfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,max_read=131072)

Add the mount entry to /etc/fstab on your webserver.

nano /etc/fstab

add this line at the end :

gluster1:/glustervol1 /var/www/html glusterfs defaults,_netdev,direct-io-mode=disable 0 0

Let’s test the replication. Create a file on your webserver (web1) in the document root directory.

cd /var/www/html
touch index.html

Check in both gluster node if the file exist.


ls /data/brick1


ls /data/brick2


You should have GlusterFS successfully installed now. Experiment to see how it can best help your workflow and projects. If you found this article helpful, feel free to share it with your friends and let us know in the comments below!