Configuring autofs for GlusterFS 3.5

GlusterFS 3.5 has not been released yet, but that should happen hopefully anytime soon (currently in beta). The RPM-packaging in this version has changed a little, and now offers a glusterfs-cli package. This package mainly contains the gluster commandline interface (and pulls in any dependencies).

On of the very useful things that is now made possible, is to list the available volumes on Gluster Storge Servers. This similar functionality is used by the /etc/auto.net script to list NFS-exports that are available for mounting. The auto.net script is by default enabled after installing and starting autofs:

# yum install autofs
# systemctl enable autofs.service
# systemctl start autofs.service

Checking, and mounting NFS-exports is made as easy as:

$ ls /net/nfs-server.example.net
archive media mock_cache olpc
$ ls /net/nfs-server.example.net/mock_cache/fedora-rawhide-armhfp/
yum_cache

Making this functionality available for Gluster Volumes is simple, just follow these steps:

  1. install the gluster command

    # yum install glusterfs-cli
  2. save the file below as /etc/auto.glfs

    #!/bin/bash
    # /etc/auto.glfs -- based on /etc/auto.net
    #
    # This file must be executable to work! chmod 755!
    #
    # Look at what a host is exporting to determine what we can mount.
    # This is very simple, but it appears to work surprisingly well
    #

    key="$1"

    # add "nosymlink" here if you want to suppress symlinking local filesystems
    # add "nonstrict" to make it OK for some filesystems to not mount
    opts="-fstype=glusterfs,nodev,nosuid"

    for P in /usr/local/bin /usr/local/sbin /usr/bin /usr/sbin /bin /sbin
    do
    if [ -x ${P}/gluster ]
    then
    GLUSTER_CLI=${P}/gluster
    break
    fi
    done

    [ -x ${GLUSTER_CLI} ] || exit 1

    ${GLUSTER_CLI} --remote-host="${key}" volume list | \
    awk -v key="$key" -v opts="$opts" -- '
    BEGIN { ORS=""; first=1 }
    { if (first) { print opts; first=0 }; print " \\\n\t/" $1, key ":/" $1 }
    END { if (!first) print "\n"; else exit 1 }' | \
    sed 's/#/\\#/g'
  3. make the script executable

    # chmod 0755 /etc/auto.glfs
  4. add an automount point to the autofs configuration

    # echo /glfs /etc/auto.glfs > /etc/auto.master.d/glfs.autofs
  5. reload the autofs configuration

    # systemctl reload autofs.service

After this, autofs should have created a new /glfs directory. The directory itself is empty, but a ls /glfs/gluster.example.net will show all the available volumes on the gluster.example.net server. These volumes can now be accessed through the autofs mountpoint. When the volumes are not used anymore, autofs will automatically unmount them after a timeout.

Share Comments
comments powered by Disqus