Configuring Network File System in detail

The Network File System (NFS) is a client-server service that lets users view, store, and update files on a remote computer as though they were on their own local computer.


# vi /etc/dfs/dfstab        ==> to share local resources

# share [-F fstype] [ -o options] [-d "<text>"] <pathname> [resource]
# .e.g,
# share -F nfs -o rw=engineering -d "home dirs" /export/home2

share -F nfs -o ro              -d "Shared data files"  /usr/local/data
share -F nfs -o rw,root=sys-01  -d "Database files"     /rdbms_files


Note – If svc:/network/nfs/server service does not find any share commands in the /etc/dfs/dfstab file, it does not start the NFS server daemons.


# cat /etc/dfs/sharetab        ==> to view local resources currently shared

# cat /etc/dfs/fstypes        ==> to view a system’s distributed file
                    system types

# cat /etc/rmtab        ==> to view file systems remotely mounted by
                    NFS clients
sys-03:/usr/local/data
sys-02:/export/config
#ys-02:/export/config



Managing the NFS Server Daemons


# svcadm enable svc:/network/nfs/server        ==> to start the NFS server
                            daemons

Note – If the svc:/network/nfs/server service does not find any share commands in the /etc/dfs/dfstab file, it does not start the NFS server daemons.


# svcadm disable svc:/network/nfs/server    ==> to stop the NFS server
                            daemons



NFS Server Commands


share    Makes a local directory on an NFS server available for mounting. It         also displays the contents of the /etc/dfs/sharetab file.

unshare        Makes a previously available directory unavailable for             client side mount operations.

shareall    Reads and executes share statements in the /etc/dfs/dfstab             file.

unshareall    Makes previously shared resources unavailable.

dfshares    Lists available shared resources from a remote or local NFS             server.

dfmounts    Displays a list of NFS server directories that are currently             mounted.



Configuringthe NFS Server for Sharing Resources


syntax: share [ -F nfs ] [ -o options ] [ -d description ] [ pathname ]


# share -o ro /usr/local/data    ==> to share a file resource


# share -F nfs -o ro directory    ==> restricts access to NFS-mounted
                    resources to read-only access


# share -F nfs -o ro,rw=client1 directory   ==> Restricts access to NFS
                        mounted resources to read-only
                        access; however, the NFS server
                        accepts read & write requests
                        from client named client1.

# share -F nfs -o root=client2 directory    ==> Allows the root user on the
                        client named client2 to have
                        superuser access to the NFS
                        mounted resources

This command shares the directory to the four named hosts only. The hosts, client1 and client2, have read-only access. The hosts client3 and client4 have read-write access. The root user from host client4 has root privilege access to the shared directory and its contents.

# share -F nfs -o ro=client1:client2,rw=client3:client4,root=client4 directory


# share        ==> to display a list of all currently shared file resources



Making File Resources Unavailable for Mounting


syntax: unshare [ -F nfs ] pathname

# unshare /usr/local/data    ==> to make the /usr/local/data directory
                    unavailable for client-side mount
                    operations



Sharing and Unsharing All NFS Resources

shareall [ -F nfs ]

unshareall [ -F nfs ]


# shareall    ==> to share all resources listed in /etc/dfs/dfstab file

# unshareall    ==> to unshare currently shared file resources listed in
            /etc/dfs/sharetab file



Displaying Currently Shared NFS Resources


dfshares [ -F nfs ] [ host ]

# dfshares    ==> to display the resources currently being shared by the
            local server

# dfshares sys-01    ==> to display resources shared by another server

# share        ==> to display a list of all currently shared file resources


Displaying NFS Mounted Resources

dfmounts [ -F nfs ] [ server ]


# dfmounts    ==> to display remotely mounted NFS resource information

RESOURCE   SERVER PATHNAME         CLIENTS
  -        sys-02 /usr/local/data sys-03



Managing the NFS Client

Managing the NFS Client Daemons

# svcadm restart svc:/network/nfs/client    ==> to start NFS client
                            daemons

NFS Client Commands


# dfshares servername

# mount

# umount

# mountall

# umountall


Configuring the NFS Client for Mounting Resources

# dfshares sys-01    ==> to list the resources of an NFS server


Mounting a remote file resource


mount [ -F nfs ] [ -o options ] server:pathname mount_point

# mount sys-02:/rdbms_files /mnt    ==> to mount a remote file resource

# mount -o ro sys-45,sys-43,sys-41:/multi_homed_data /remote_shared_data


In the above example, if sys-45 server is unavailable, the request passes to
the next server on the list, sys-43, and then to the sys-41 server. This process works if the resource mounted from all of the servers is the same.



Unmounting a remote file resource


umount server:pathname or mount_point

# umount /rdbms_files        ==> to unmount a remote file resource



Mounting & Unmounting remote file resources only (resources listed in the
/etc/vfstab file with a mount at boot value of yes)

mountall -r [ -F nfs ]

umountall -r [ -F nfs ]

# mountall -r        ==> to mount all remote file resources only

# umountall -r        ==> to unmount all remote file resuources only


Note – Use the -F FSType with the mountall and umountall commands to specify FSType as the file system type. You do not have to specify the -F nfs option, because NFS is listed as the default remote file system type.


Mounting Remote Resources at Boot Time


Enter appropriate entries in the client’s /etc/vfstab file to mount remote file resources at boot time

# vi /etc/vfstab

#device              device       mount         FS   fsck mount   mount
#to mount            to fsck      point         type pass at boot options
#
sys-02:/usr/local/data       - /usr/remote_data  nfs   -   yes    soft,bg


bg|fg        During an NFS mount request, if the first mount attempt             fails, retry in the background or foreground.
             
        The default is to retry in the foreground.

soft|hard    When the number of retransmissions has reached the number             specified in the retrans=n option, a file system mounted with             the soft option reports an error on the request, and stops             trying. A file system mounted with the hard option prints a             warning message and continues to try to process the request.

        The default is a hard mount.
       
        Although the soft option and the bg option are not the             default settings, combining them usually results in the         fastest client boot when NFS mounting problems occur.



Enabling NFS Server Logging



Note – Server logging is not supported in NFS version 4.


Create tag entries for each of the server’s shared resources.
The global tag defines the default values.


# cat /etc/nfs/nfslog.conf        ==> to configure NFS log paths

# NFS server log configuration file.
#
# <tag> [ defaultdir=<dir_path> ] \
#       [ log=<logfile_path> ] [ fhtable=<table_path> ] \
#       [ buffer=<bufferfile_path> ] [ logformat=basic|extended ]
#
global  defaultdir=/var/nfs \
        log=nfslog fhtable=fhtable buffer=nfslog_workbuffer


To easily identify the log files for different shared resources, place them in
separate directories. For example:

# cat /etc/nfs/nfslog.conf

# NFS server log configuration file.
#
global defaultdir=/var/nfs \
         log=nfslog fhtable=fhtable buffer=nfslog_workbuffer
public defaultdir=/var/nfs/public \
         log=nfslog fhtable=fhtable buffer=nfslog_workbuffer


Note – Create /var/nfs/public directory before starting NFS server logging.


Initiating NFS Logging


1. Become superuser.


2. Optional: Change the file system configuration settings.
In the /etc/nfs/nfslog.conf file, either:

        Edit the default settings for all file systems by changing the data
        corresponding to the global tag.
   
        Add a new tag for the specific file system.
  
If you do not need these changes, do not edit this file.


3. Edit the /etc/dfs/dfstab file to add an entry for file systems for which
   you want to enable NFS server logging.

   Either:
    
        Use log option without specifying a tag - to use the global tag as
    default.

        Specify a tag - with the log=tag option

share -F nfs -olog /export/sys44_data
share -F nfs -olog=public /export/sys44_data


4. Check that the NFS service is running on the server, if not start it.

# svcadm enable svc:/network/nfs/server


5. Run the share command to verify that the correct options are listed.

# share


6. If you add additional entries to /etc/dfs/dfstab file, share the file
   system by rebooting the system or entering the shareall command.

# shareall