Network File System

The NFS enables sharing of filesystems among computers. NFS is almost transparent to user and is stateless, meaning no information is lost when NFS server crashes.


Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984 allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed. NFS, like many other protocols, builds on the Open Network Computing Remote Procedure Call (ONC RPC) system. The Network File System is an open standard defined in RFCs, allowing anyone to implement the protocol.

The NFS protocol has been remarkably stable over time. Sun used V1 only for in house experimental purpose. When development team added substantial changes to V1, they release it as V2.

V2 of the protocol originally operated only over UDP.
V3 eliminates this bottleneck with a coherency scheme that permits asynchronous writes. V3 is always capable of interoperating with V2. 
V4 is becoming more stable and is shipping with some versions of Linux. It requires a 2.601 kernel or greater and needs to be manually turned on in the kernel.

Server Side NFS.
A server is said to export a directory when it makes the directory available for use by other machines. On a NFS server, both mountd and nfsd should start when the system boots and both should remain running as long as the system is up. mountd and nfsd share a single access control database that tells which filesystems should be exported and which clients may mount them. On most systems /etc/exports is the canonical human readable list of exported directories.
NFS server startup script.

#apt-get install nfs-kernel-server
         or
#apt-get install nfs-common
The /etc/exports file enumerates the filesystems export through NFS and the clients that may access each of them. Whitespace separates the filesystem from the list of clients and each client is followed immediately by a parenthesized list of comma seperated options.
#nano /etc/exports
On the last part add the client details with access privilege;  
/home                            *.growwithlinux.com (rw,sync)
/home/admin                  (noaccess)
(allow hosts in the growwithlinux.com domain to access all the contents of /home through mounting expect for /home/admin. The absence of a client name on the second line means that the option applies to all hosts).

Command export options;


ro
:
Read-only.
rw
:
Reading and writing.
rw=list
:
Read mostly. List enumerates the hosts allowed to mount for writing.
root_squash
:
Maps UID 0 and GID 0 to the values specified by anonuid and anongid.
no_root_squash
:
Allow normal access by root.
all_squash
:
Maps all UIDs and GIDs to their anonymous versions.
anonuid=xxx
:
Specifies the UID to which remote roots should squashed.
anongid=xxx
:
Specifies the GID to which remote roots should squashed.
secure
:
Requiers remote access to originate at a privileged port.
insecure
:
Allow remote access from any port.
noacess
:
Prevents access to this directory.
wdelay
:
Delays writes in hopes of coalescing multiple updates.
no_wdelay
:
Writes data to disk as soon as possible.
async
:
Makes server reply to write requests before actual disk write.
nohide
:
Reveals filesystems mounted within exported file tree.
hide
:
Hide filesystems mounted within exported file tree.
subtree_check
:
Verifies that each requested file is within an exported subtree.
no_subtree_check
:
Verifies only that file requests refer to an exported filesystem.
secure_locks
:
Requires authorization for all lock requests.
insecure_locks
:
Specifies less stringent locking criteria.
auth_nlm
:
Synonym for secure_locks.
no_auth_nlm
:
Synonym for insecure_locks.

#exportfs -a  For updating the exports file.

Client Side NFS.
NFS filesystems are mounted in much the same way as local disk filesystems. Before an NFS filesystem can be mounted, it must be properly exported. To verify that a server has properly exported its filesystems from the client's perspective,
#showmount -e {server name or ipaddress}
If the showmount returns an error or an empty list, check that all necessary processes are running in the server (portmap, mountd,nfsd,statd and lockd).

Example we configure a client side where mount point is /mntfldr, for server ip address 95.10.28.4
First create a mount point in client by;
#mkdir /mntfldr

Mount the filesystem in client side by editing fstab or by manual mount;
#mount -t nfs  rw,bg,intr,hard 95.10.28.4:/home /mntfldr
                     or
#nano /etc/fstab
Add the following details to the file;
<file system>            <mount point>      <type>            <options>                      <dump>  <pass>
95.10.28.4/home        /mntfldr                  nfs          user,auto,rw,bg,intr,hard          0              1

The flags like rw,bg are standard, but must makesure in server and client side must give same permissions;
Common flag options;

ro
:
Read-only.
rw
:
Reading and writing.
bg
:
If the mount fails keeps trying it in the background and continues with other mount requests.
hard
:
If a server goes down, causes operations that try to access it to block until the server comes backup.
soft
:
If a server goes down, causes operations that try to access it to fail and return an error.
intr
:
Allow users to interrupt blocked operations.
nointr
:
Doesnot allow user interrupts.
retrans=n
:
Specifies the number of times to repeat a request before returning.
timeo=n
:
Sets the timeout period (second) for requests.
rsize=n
:
Sets the read buffer size in bytes.
wsize=n
:
Sets the write buffer size in bytes.
tcp / udp
:
Select the transport protocol.

Statistic.
The nfsstat command displays various statistics kept by NFS system;
#nfsstat -s Shows statistics for NFS server process.
#nfsstat - c Shows information related to client side operations.

No comments:

Post a Comment