Friday 4 October 2013

Getting autofs working on a Centos NeCTAR vm


So I have to set up a web server on a NeCTAR vm to allow public access to some research data that is sitting on RDSI storage in the QCIF UQ node. The node support team requested that instead of just NFS mounting the data storage to the vm, it would be preferable to use autofs to mount the filesystem.

I'm not a sys-admin type - mostly my linux environments are all set up for me so this was a bit of an adventure. I had quite a few problems so, with the aim of helping out future non sys-admin types in the same position, I thought I should document what I had to do.



So, the VM I have set up is a NeCTAR CentOS 6.4 x86_64 image, so I looked up the CentOS autofs doc and got to work.

  1. Check that you can actually mount the storage using NFS
    • I didn't do this before I started and it took a while to discover that I didn't have all the NFS packages that I needed installed. In the end I had to install the nfs-utils-lib package:
      sudo yum install nfs-utils-lib
      
  2. Install autofs on the vm
    sudo yum install autofs
    
  3. This step installed a number of dependencies but I can't remember what they all were.
  4. Set up the /etc/auto.master file
    • An example file is installed as part of the installation of autofs. The file contains automounter maps and have the format of <mount-point> <map-name> [ <mount-options-separated-by-comma> ]. I deleted most of the contents and added the one line I required:
    • /data file:/etc/auto.rdsi
    • /data is the directory I want to use to mount the file system
    • /etc/auto.rdsi is the location of the file that contains the mount information
    • file indicates that the map name /etc/auto.rdsi refers to a regular file. This could be nis or nisplus instead. This is an optional field but better safe than sorry :)
  5. Set up the /etc/auto.rdsi file
    • This file holds the mount instructions and has the format:
    • <mount-point> [ <options> ] <location>
    • The mount point is relative to the mount point given in the master file, options are the mount options (more or less what you would put in an fstab file) and the location is the remote-machine:location. So for my case, this was:
    • climate    -rw,nfsvers=3,hard,intr,bg,nosuid,nolock,nodev,timeo=15,retrans=5    10.255.100.50:/collection/Q03/Q03
  6. Started the autofs service
  7. sudo service autofs start
  8. Test that it has actually worked:
    ls /data/climate
    • If at this point you get the error message:
      ls: cannot access /data/climate: No such file or directory
      then you have a problem!

What to do when it doesn't work

The problem with using the autofs service is of course the complete lack of error messages when things go wrong. An messages from the service go to /var/log/messages and will be prefixed with automount which is the underlying process that is being run by the autofs service. automount can be run from the command line with the --verbose argument but I found that rather messy. Instead, I edited the /etc/init.d/autofs script and added a new option:
....
case "$1" in
 start)
  start
  ;;
 forcestart)
  OPTIONS="$OPTIONS --force"
  start
  ;;
 debugstart)
  OPTIONS="$OPTIONS --verbose"
  start
  ;;
 stop)
  stop
  ;;
...

I then stopped the service and used the new debugstart option:
sudo service autofs debugstart
and tried to access the mounted area again:
ls /data/climate
and then looked in the logs
sudo tail -100 /var/log/messages | grep automount
The error messages are pretty good so once I could see what is going wrong it was pretty easy to fix. In my case, I orginally didn't have the nolock option in the mount options and this was the messages in the log:
automount[21307]: attempting to mount entry /data/climate
automount[21307]: >> mount.nfs: rpc.statd is not running but is required for remote locking.
automount[21307]: >> mount.nfs: Either use '-o nolock' to keep locks local, or start statd.
automount[21307]: >> mount.nfs: an incorrect mount option was specified
automount[21307]: mount(nfs): nfs: mount failure 10.255.100.50:/collection/Q03/Q03 on /data/climate
automount[21307]: failed to mount /data/climate

Don't forget to turn off the extra logging once you have got it all working - just stop the service and then start as per normal.

No comments: