Centos 6.5 NFS Server Suitable for Cloudstack

Centos​In the past I have had the odd bit of difficulty with getting Cloudstack to work with a freshly built NFS server as either primary or secondary storage.  Nothing that could not be solved but I am not a Linux 'expert' so I thought I would create a very quick article so that others with similar experiences to mine may extract some benefit.

Pre-requisites

  • A VM with the following configuration
    • 1 vCPU
    • 2GB or more RAM
    • 50GB or more of disk space
  • A freshly built minimal Centos 6.5 build

​​Preparations

  • Apply all system patches via a yum update
yum update -y
  • Install and start NTP (assumption connection and name resolution allow server to find named NTP servers on the Internet)
yum update ntp -y
service ntpd start
chkconfig ntpd on
  • Edit /etc/sysconfig/network and set the hostname

HOSTNAME = name.example.com

  • Edit /etc/hosts and add a line for the server hostname and fqdn
​192.168.15.10  name  name.example.com
  • set hostname in current terminal session
hostname name.example.com
  • Restart network service
Service network restart

Install Software

  • Install NFS and the utilities
yum install -y nfs nfs-utils

​Configure NFS

  • Edit /etc/sysconfig/nfs.  I have highlighted the lines you need to un-comment
​#
# Define which protocol versions mountd
# will advertise. The values are "no" or "yes"
# with yes being the default
#MOUNTD_NFS_V2="no"
#MOUNTD_NFS_V3="no"
#
#
# Path to remote quota server. See rquotad(8)
#RQUOTAD="/usr/sbin/rpc.rquotad"
# Port rquotad should listen on.
RQUOTAD_PORT=875
# Optinal options passed to rquotad
#RPCRQUOTADOPTS=""
#
#
# Optional arguments passed to in-kernel lockd
#LOCKDARG=
# TCP port rpc.lockd should listen on.
LOCKD_TCPPORT=32803
# UDP port rpc.lockd should listen on.
LOCKD_UDPPORT=32769
#
#
# Optional arguments passed to rpc.nfsd. See rpc.nfsd(8)
# Turn off v2 and v3 protocol support
#RPCNFSDARGS="-N 2 -N 3"
# Turn off v4 protocol support
#RPCNFSDARGS="-N 4"
# Number of nfs server processes to be started.
# The default is 8.
#RPCNFSDCOUNT=8
# Stop the nfsd module from being pre-loaded
#NFSD_MODULE="noload"
# Set V4 grace period in seconds
#NFSD_V4_GRACE=90
#
#
#
# Optional arguments passed to rpc.mountd. See rpc.mountd(8)
#RPCMOUNTDOPTS=""
# Port rpc.mountd should listen on.
MOUNTD_PORT=892
#
#
# Optional arguments passed to rpc.statd. See rpc.statd(8)
#STATDARG=""
# Port rpc.statd should listen on.
STATD_PORT=662
# Outgoing port statd should used. The default is port
# is random
STATD_OUTGOING_PORT=2020
# Specify callout program
#STATD_HA_CALLOUT="/usr/local/bin/foo"
#
#
# Optional arguments passed to rpc.idmapd. See rpc.idmapd(8)
#RPCIDMAPDARGS=""
#
# Set to turn on Secure NFS mounts.
#SECURE_NFS="yes"
# Optional arguments passed to rpc.gssd. See rpc.gssd(8)
#RPCGSSDARGS=""
# Optional arguments passed to rpc.svcgssd. See rpc.svcgssd(8)
#RPCSVCGSSDARGS=""
#
# To enable RDMA support on the server by setting this to
# the port the server should listen on
#RDMA_PORT=20049

 

start the required services in the correct order

  • Configure firewall
# non-standard additions

#NFSD
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT

#port mapper
-A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 111 -j ACCEPT

#lockd
-A INPUT -m state --state NEW -m tcp -p tcp --dport 32803 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 32769 -j ACCEPT

#mountd
-A INPUT -m state --state NEW -m tcp -p tcp --dport 892 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 892 -j ACCEPT

#rquotad
-A INPUT -m state --state NEW -m tcp -p tcp --dport 875 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 875 -j ACCEPT

#rpc.statd
-A INPUT -m state --state NEW -m tcp -p tcp --dport 662 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 662 -j ACCEPT
  • Create a directory structure
mkdir -p /data/primary_storage
  • Create an export entry in /etc/exports
/data/primary_storage  *(rw,async,no_root_squash,no_subtree_check)
  • Export the file system
export -a

Start And Configure Services

  • Start the services in this order
service rpcbind start
service nfslock start
service nfs start
  • Configure the services to start on server boot
chkconfig rpcbind on
chkconfig nfslock on
chkconfig nfs on

Confirm File System is Exported

showmount -e

Output should closely resemble this:

Export list for nfs.cloud.local:
/data/primary_storage *

 

​Remote Test

The file system is now exported.  Let's just confirm it is accessible.

From another Centos 6.5 minimal build perform the following steps:

  • Install nfs utilities
yum install -y nfs-utils
  • Create a mount point on the local file system
mkdir /mnt/remote_space
  • Mount the remote file system
mount 192.168.15.4:/data/primary_storage /mnt/remote_space
  • Confirm success
mount
/dev/mapper/vg_osclient01-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
192.168.15.4:/data/primary_storage on /mnt/remote_space type nfs (rw,vers=4,addr=192.168.15.4,clientaddr=192.168.15.254)
  • Confirm RW access
touch /mnt/remote_space/testing123
drwxr-xr-x. 2 root root 4096 Jun 11 17:31 .
drwxr-xr-x. 3 root root 4096 Jun 11 17:27 ..
-rw-r--r--. 1 root root    0 Jun 11 17:31 testing123

Complete

That's it.  The file server can now be added to Cloudstack via the UI for use as either primary or secondary storage

Add to Apache Cloudstack 4.3 Storage Resources

  • Login to Cloudstack via UI, in my case http://192.168.4.4:8080/client/
  • Click on LHS menu item 'Infrastructure'
  • Click on 'Primary Storage'
  • Click Add 'Primary Storage'
  • Fill in UI form and Click OK

Cloudstack - Infrastructure DisplayCloudstack - Primary Storage ListCloudstack - Add Storage UI Modal FormCloudstack - Successfully Completed Addition of Storage

The new storage should appear in the primary storage listing in front of you.  Clicking on the name allows you to see more detail about the storage resource as well as its current state.