How to mount Glusterfs volumes inside LXC/LXD (Linux containers)

Posted on in Categories , , last updated July 21, 2017

How do I install and configure the Gluster Native Client on a Debian or Ubuntu Linux? How do I mount Gluster volumes to access data from LXC/LXD (Linux containers)?

GlusterFS is an open source network distributed storage file system. Network distributed storage file systems are very popular amoung high trafficked websites, cloud computing servers, streaming media services, CDN (content delivery networks) and more. This tutorial shows you how to install GlusterFS client on Ubuntu Linux 16.04 LTS server and mount Glusterfs volumes inside LXC/LXD.
GlusterFS aggregates various storage servers over Ethernet or Infiniband RDMA interconnect into one large parallel network file system
GlusterFS aggregates various storage servers over Ethernet or Infiniband RDMA interconnect into one large parallel network file system. You can use network file system to store Apache/Nginx files or your application files.

Step 1 – Allow LXD/LXC to mount Glusterfs from the host

Type the following command on your host:
$ sudo -i
Type the following two command:
# echo Y > /sys/module/fuse/parameters/userns_mounts
# echo Y > /sys/module/ext4/parameters/userns_mounts

Edit the /etc/rc.local file:
# vi /etc/rc.local
Edit/Update it as follow before exit 0 line:

echo Y > /sys/module/fuse/parameters/userns_mounts  
echo Y > /sys/module/ext4/parameters/userns_mounts

Step 2 – Update /etc/hosts file inside lxc/lxd VM

Login to your lxc/lxd machine:
$ lxc exec www-vm bash
# vi /etc/hosts

Append the following lines to point to your gfs servers: gfs01 gfs02 gfs03 gfs04

Save and close the file. Test it with the ping command. Run the following command to make sure you can reach to Glusterfs servers from the LXD/LXC VM:
# ping -c 2 gfs01
# ping -c 2 gfs02
# ping -c 2 gfs03
# ping -c 2 gfs04

Step 3 – Install Glusterfs client on lxc/lxd VM

Type the following add-apt-repository command:
$ sudo add-apt-repository ppa:gluster/glusterfs-3.11
Sample outputs:

 More info:
Press [ENTER] to continue or ctrl-c to cancel adding it
.gpg: keyring `/tmp/tmpzf35_hah/secring.gpg' created
gpg: keyring `/tmp/tmpzf35_hah/pubring.gpg' created
gpg: requesting key 3FE869A9 from hkp server
gpg: /tmp/tmpzf35_hah/trustdb.gpg: trustdb created
gpg: key 3FE869A9: public key "Launchpad PPA for Gluster" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

Use the apt-get command/apt command to update it:
$ sudo apt-get update
$ sudo apt-get install glusterfs-client -y

Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  glusterfs-common libibverbs1 librdmacm1 liburcu4
The following NEW packages will be installed:
  glusterfs-client glusterfs-common libibverbs1 librdmacm1 liburcu4
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 3271 kB of archives.
After this operation, 15.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 xenial/main amd64 libibverbs1 amd64 1.1.8-1.1ubuntu2 [25.0 kB]
Get:2 xenial/main amd64 glusterfs-common amd64 3.11.1-ubuntu1~xenial2 [3129 kB]
Get:3 xenial/main amd64 librdmacm1 amd64 1.0.21-1 [49.1 kB]
Get:4 xenial/universe amd64 liburcu4 amd64 0.9.1-3 [47.3 kB]
Processing triggers for ureadahead (0.100.0-19) ...
Setting up libibverbs1 (1.1.8-1.1ubuntu2) ...
Setting up librdmacm1 (1.0.21-1) ...
Setting up liburcu4:amd64 (0.9.1-3) ...
Setting up glusterfs-common (3.11.1-ubuntu1~xenial2) ...
Setting up glusterfs-client (3.11.1-ubuntu1~xenial2) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
Processing triggers for ureadahead (0.100.0-19) ...

Step 4 – Mount Glusterfs client on lxc/lxd VM

You need to create a mount point using the mkdir command:
$ sudo mkdir /data/
Mount it as follows:
$ sudo mount -t glusterfs gfs01:/gvol0 /data/
Update /etc/fstab as follows:
$ echo 'gfs01:/gvol0 /data glusterfs defaults,_netdev 0 0' >> /etc/fstab
Save and close the file. You can now store data at /data/ location and it will get replicated across the cluster:
$ cd /data/
$ ls -l

Sample outputs (I am storing my site on glusterfs):

total 4
drwxr-xr-x 5 root root 4096 Jul 17 22:19
This entry is 2 of 4 in the GlusterFS Tutorial series. Keep reading the rest of the series:
  1. How to install GlusterFS on a Ubuntu Linux
  2. How to mount Glusterfs volumes inside LXC/LXD
  3. How to enable TLS/SSL encryption with Glusterfs storage
  4. How to add a new brick to an existing replicated GlusterFS volume on Linux

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Leave a Comment