Tuesday, September 21, 2010

NFS: Network File System

Introduction

Network File System (NFS) is a network file system protocol originally developed by Sun Microsystems in 1984, allowing an user on a client computer to access files over a network in a manner similar to how local storage is accessed.

Installation

yum install nfs-utils

To check nfs version:

[root@example]# cat /proc/fs/nfsd/versions
+2 +3 +4 +4.1

Default Property

  1. Server instance name: nfs
  2. Configuration file:
    1. /etc/sysconfig/nfs
    2. /etc/exports
  3. Services:
    1. portmapper (port: 111 tcp/udp)
    2. nlockmgr (port: dynamic)
    3. nfs (port: 2049 tcp/udp)
    4. mountd (port: dynamic)
  4. Log file: /var/log/messages

Configuration

Configuration: /etc/sysconfig/nfs

/etc/sysconfig/nfs consist the configuration parameters for various NFS services.  Unlike other TCP/IP service, NFS service consist of several services.  Some services’ TCP and UDP ports are dynamic allocated.  You may want to fix the port numbers or else you will in trouble when configure firewall in later stage:

# TCP port rpc.lockd should listen on.
LOCKD_TCPPORT=32803
# UDP port rpc.lockd should listen on.
LOCKD_UDPPORT=32769

MOUNTD_PORT=892

Restart the NFS service for the changes to take effect:

service nfs restart

You may use rpcinfo –p to check if NFS services are working:

[root@example ~]# rpcinfo -p
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100024    1   udp  47618  status
    100024    1   tcp  55823  status
    100011    1   udp    875  rquotad
    100011    2   udp    875  rquotad
    100011    1   tcp    875  rquotad
    100011    2   tcp    875  rquotad
    100021    1   udp  32769  nlockmgr
    100021    3   udp  32769  nlockmgr
    100021    4   udp  32769  nlockmgr
    100021    1   tcp  32803  nlockmgr
    100021    3   tcp  32803  nlockmgr
    100021    4   tcp  32803  nlockmgr
    100003    2   tcp   2049  nfs
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    2   tcp   2049  nfs_acl
    100227    3   tcp   2049  nfs_acl
    100003    2   udp   2049  nfs
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    2   udp   2049  nfs_acl
    100227    3   udp   2049  nfs_acl
    100005    1   udp    892  mountd
    100005    1   tcp    892  mountd
    100005    2   udp    892  mountd
    100005    2   tcp    892  mountd
    100005    3   udp    892  mountd
    100005    3   tcp    892  mountd

Configuration: Firewall

You may need to allow the following ports for client access:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 2049 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 32803 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p udp --dport 32769 -j ACCEPT -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 -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

Configuration: /etc/exports

You may specify the folder you want to export in /etc/exports:

/data   example.com(ro)
/home   example.com(ro)

To check what the server exports:

exportfs -v

To re-export modification done in /etc/exports:

exportfs -r

NFS Client

Client: mount

The following example show how to use mount to mount the NFS export file system:

# mount example.com:/data /mnt/data
# mount example.com:/home /home

Client: /etc/fstab

You may also add the NFS mount in file system table: /etc/fstab:

example.com:/data   /mnt/data  nfs rw 0 0
example.com:/home   /home nfs rw 0 0

Client: autofs or automount

An example using /etc/auto.indirect to serve autofs mount:

/mnt/data         -rw example.com:/data
/home -rw example.com:/home

An example of using LDAP to serve autofs mount:

dn: cn=/mnt/data,ou=auto.indirect,ou=autofs,dc=example,dc=com
objectClass: automount
objectClass: top
automountInformation: -rw example.com:/data
cn: /mnt/data
dn: cn=/home,ou=auto.indirect,ou=autofs,dc=example,dc=com
objectClass: automount
objectClass: top
automountInformation: -rw example.com:/home
cn: /home

Reference

  1. Linux NFS. url: http://www.linux-nfs.org/
  2. Linux NFS-HOWTO. url: http://nfs.sourceforge.net/nfs-howto/

No comments: