Configuring NFS:
NFS(Network File System):
This file system is implemented by most unix type OS(SOLARIS/LINUX/FreeBSD). NFS seamlessly mounts remote file systems locally.
NFS major versions:
2 → Original
3 → improved upon version 2
4 → Current & default version
Note: NFS versions 3 & higher supports large files (>2GB)
NFS Benefits:
1. It enables file system sharing on network across different systems.
2. It can be implemented across different OS.
3. The working of the nfs file system is as easy as the locally mounted file system.
NFS component include:
1. NFS Client: It mounts the file resource shared across the network by the NFS server.
2. NFS Server: It contains the file system that has to be shared across the network.
3. Auto FS
Managing NFS Server:
We use NFS server files, NFS server daemons & NFS server commands to configure and manage an NFS server.
To support NFS server activities we need following files:
file | Description |
/etc/dfs/dfstab | Lists the local resource to share at boot time. This file contains the commands that share local directories. Each line of dfstab file consists of a share command. E.g: share [-F fstype] [-o options] [-d "test"] <file system to be shared> |
/etc/dfs/sharetab | Lists the local resource currently being shared by the NFS server. Do not edit this file. |
/etc/dfs/fstypes | Lists the default file system types for the remote file systems. |
/etc/rmtab | Lists the file systems remotely mounted by the NFS Client. Do not edit this file. E.g:system1:/export/sharedir1 |
/etc/nfs/nfslog.conf | Lists the information defining the local configuration logs used for NFS server logging. |
/etc/default/nfslogd | Lists the configuration information describing the behavior of the nfslogd daemon for NFSv2/3. |
/etc/default/nfs | Contains parameter values for NFS protocols and NFS daemons. |
Note: If the svc:/network/nfs/server service does not find any share command in the /etc/dfs/dfstab file, it does not start the NFS server daemons.
NFS server Daemons:
To start NFS server daemon enable the daemon svc:/network/nfs/server :
#svcadm enable nfs/server
Note: The nfsd and mountd daemons are started if there is an uncommented share statement in the system's /etc/dfs/dfstab file.
Following are the NFS server daemon required to provide NFS server service:
mountd:
- Handles file system mount request from remote systems & provide access control.
- It determines whether a particular directory is being shared and if the requesting client has permission to access it.
- It is only required for NFSv2 & 3.
nfsd:
Handles client file system requests to access remote file system request.
statd:
Works with lockd daemon to provide crash recovery function for lock manager.
lockd:
Supports record locking function for NFS files.
nfslogd:
Provides operational logging for NFSv2 & 3.
nfsmapid:
- It is implemented in NFSv4.
- The nfsmapid daemon maps owner & group identification that both the NFSv4 client and server use.
- It is started by: svc:/network/nfs/mapid service.
Note: The features provided by mountd & lockd daemons are integrated in NFSv4 protocol.
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. It writes information for all shared resource into /etc/dfs/sharetab file.
Syntax:
share [-F fstype] [-o options] [-d "text"] [Path Name]
-o options: Controls a client's access to an NFS shared resource.
The options lists are as follows:
ro: read only request
rw: read & write request
root=access-list: Informs client that the root user on the specified client systems cna perform superuser-privileged requests on the shared resource.
ro=acess-list: Allows read requests from specified access list.
rw=acess-list: Allows read & write requests from specified access list.
anon=n: Sets n to be the effective user ID for anonymous users. By default it is 6001. If it is set to -1, the access is denied.
access-list=client:client : Allows access based on a colon-separated list of one or more clients.
access-list=@network : Allows access based on a network name. The network name must be defined in the /etc/networks file.
access-list=.domain : Allows access based on DNS domain. The (.) dot identifies the value as a DNS domain.
access-list=netgroup_name: Allows access based on a configured net group(NIS or NIS+ only)
-d description: Describes the shared file resource.
Path name: Absolute path of the resource for sharing.
Example:
#share -o ro /export/share1
The above command provides read only permission to /export/share1.
#share -F nfs -o ro,rw=client1 directory
This command restricts access to read only, but accept read and and write request from client1.
Note: If no argument is specified share command displays list of all shared file resource.
unshare:
Makes a previously available directory unavailable for the client side mount operations.
#unshare [ -F nfs ] pathname
#unshare <resource name>
shareall:
Reads and executes share statements in the /etc/dfs/dfstab file.
This shares all resources listed in the /etc/dfs/dfstab file.
shareall [-F nfs]
unshareall:
Makes previously share resource unavailable which is listed /etc/dfs/sharetab.
shareall [-F nfs]
dfshares:
Lists available shared resources from a remote or local server.
Displaying currently shared all resources when used without argument:
#dfshares
RESOURCE SERVER ACCESS TRANSPORT
dfshares command with host name as argument, lists the resources shared by the host.
#dfshares system1
dfmounts:
Displays a list of NFS server directories that are currently mounted.
#dfmounts
RESOURCE SERVER PATHNAME CLIENTS
Note: The dfmount command uses mountd daemon to display currently shared NFS resources, it will not display NFSv4 shares.
Managing NFS client:
NFS client files, NFS client daemon and NFS client commands work together to manage NFS Client.
NFS client Files:
/etc/vfstab : Defines file system to be mounted. A sample entry in this file for nfs file system is shown below:
system1:/export/local_share1 - /export/remote_share1 nfs - yes soft,bg
Here the /export/remote_share1 is the file system at the NFS server and is shared by nfs client locally on /export/local_share1.
/etc/mnttab : Lists currently mounted file system, including automounted directories. This file is maintained by kernel and cannot be edited. It provides read only access to the mounted file system.
/etc/dfs/fstypes: Lists the default file system types for remote file systems.
#cat /etc/dfs/fstypes
nfs NFS Utilities
autofs AUTOFS Utilities
cachefs CACHEFS Utilities
/etc/default/nfs : Contains parameters used by NFS protocols & daemons.
NFS client Daemons:
The nfs daemons are started by using the svc:/network/nfs/client service. The nfs client daemons are:
statd : Works with lockd daemon to provide crash recovery functions for lock manager.
#svcadm -v enable nfs/status
svc:/network/nfs/status:default enabled
lockd : Supportd recording locks on nfs shared files.
#svcadm -v enable nfs/lockmgr
svcs:/network/nfs/nlockmgr:default enabled
nfs4cbd : It is an NFSv4 call back daemon. Following is the FMRI for the nfs4cbd service:
svc:/network/nfs/cbd:default
NFS client commands:
dfshares:
Lists available shared resources from a remote/local NFS server.
mount:
Attaches a file resource(local/remote) to a specified local mount point.
Syntax:
mount [ -F nfs] [-o options] server:pathname mount_point
where:
-F nfs: Specifies NFS as the file system type. It is default option and not necessary.
-o options: Specifies a comma-separated list of file system specific options such as rw, ro. The default is rw.
server:pathname: Specifies the name of the server and path name of the remote file resource. The name of the server and the path name are separated by colon(:).
mount_point: Specifies the path name of the mount point on the local system.
Example:
#mount remotesystem1:/share1 /share1
#mount -o ro remotesystem1:/share1 /share1
unmount:
Unmounts a currently mounted file resource.
#unmount /server1
mountall:
Mounts all file resource or a specified group of file resource listed in /etc/vfstab file with a mount at boot value as yes. To limit the action to remote files only use option r:
#mountall -r
unmountall:
Unmounts all noncritical local and remote file resource listed in client's /etc/vfstab file.To limit the action to remote files only use option r:
#unmountall -r
/etc/vfstab file entries:
device to mount: This specifies the name of server and path name of the remote file resource. The server host name and share name are separated by a colon(:).
device to fsck: NFS resource are not checked by the client as the file system is remote.
Mount point: Mount point for the resource.
FS type: Type of file system to be mounted.
fsck pass: The field is (-) for NFS file system.
mount at boot: This field is set to yes.
Mount options:
Various mount options are as follows:
rw|ro : Specifies resource to be mounted as read/write or read-only.
bg|fg: If the first mount attempt fails this option specifies to retry mount in background|foreground.
soft|hard: When the number of retransmission has reached the number specified in the retrans=n option, a file system mounted with 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 hard mount.
intr|nointr: This enables or disables the use of keyboard interrupts to kill a process that hangs while waiting for a response on a hard-mounted file system. The default is intr.
suid|nosuid: Indicated whether to enable setuid execution. The default enables setuid execution.
timeo=n: Sets timout to n-tenths of a second.
retry=n: Sets the number of retries to the mount operation. The default is 10,000.
retrans=n: Sets the number of NFS re-transmissions to n.
Configuring NFS log paths:
The /etc/nfs/nfslog.conf file defines the path, file names and type of logging that nfslogd daemon must use.
Configuring an NFS server:
Step1 :
Make following entry to /etc/default/nfs file on server machine:
NFS_SERVER_VERSMAX=n
NFS_SERVER_VERSMIN=n
Here n is the version of NFS and takes values:2,3 & 4. By default these values are unspecified. For client's machine the default minimum is version 2 and maximum is version 4.
Step2:
If needed, make the following entry:
NFS_SERVER_DELEGATION=off
By default this variable is commented and nfs does not provides delegation to the clients.
Step3:
If needed, make the following entry:
NFSMAPID_DOMAIN=<domain name>
By default nfsmapid daemon uses DNS domain of the system.
Determine if NFS server is running:
#svcs network/nfs/server
To enable the service;
#svcadm enable network/nfs/server
Configuring an NFS Client:
Step1 :
Make following entry to /etc/default/nfs file on client machine:
NFS_SERVER_VERSMAX=n
NFS_SERVER_VERSMIN=n
Here n is the version of NFS and takes values:2,3 & 4. By default these values are unspecified. For client's machine the default minimum is version 2 and maximum is version 4.
Step2:
Mount a file system:
#mount server_name:share_resource local_directory
server_name: Name of NFS server
share_resource: Path of the shared remote directory
local_directory: Path of local mount point
#svcadm enable network/nfs/client
NFS File Sharing:
At server side:
1. Create following entry in /etc/dfs/dfstab :
#share -F nfs <resource path name>
2. Share the file system:
#exportfs -a
-a: Exports all directories listed in the dfstab file.
3. List all shared file system:
#showmount -e
4. Export the shared file system to kernel:
To share all file system: #shareall
To share specific file system: #share <resource path name>
5. Start the nfs server daemon:
#svcadm enable nfs/server
At Client side:
1. Create a directory to mount the file system.
2. Mount the file system:
#mount -F nfs <Server Name/IP>:<Path name> <Local mount point>
3. Start the nfs client daemon:
#svcadm enable nfs/client
4. To make the file sharing permanent make an entry to vfstab.
Different File Sharing options:
The common NFS errors and troubleshooting:
The "rpcbind failure" error
Cause:
1. There is a combination of an incorrect Internet address and a correct host or node name in the hosts database file that supports the client node.
2. The hosts database file that supports the client has the correct server node, but the server node temporarily stops due to an overload.
Resolution:
Check if the server is out of critical resources as memory, swap, disk space etc.
The "server not responding" error
Cause: An accessible server is not running NFS daemon.
Resolution:
1. The network between the local system and server is down. To verify the network, ping the server.
2. The server is down.
The "NFS client fails a reboot" error
Cause: Client is requesting an NFS mount from a non-operational NFS srver.
Resolution:
1. Press stop+A
2. edit /etc/vfstab and comment out the entry for NFS mount.
3. Press Ctrl+D to continue normal boot.
4. Check if the NFS server is operational and functioning properly.
5. After resolving the issue, uncomment the entry in step 2.
The "service not responding" error
Cause: NFS server daemon is not running.
Resolution:
1. Check the run level on server and verify if it is 3:
#who -r
2. check the status of the nfs server daemon:
#svcs svc:/network/nfs/server
#svcadm enable svc:/network/nfs/server
The "program not registered" error
Cause: The server is not running the mountd daemon
Resolution:
1. Check the run level on server and verify if it is 3:
#who -r
2. Check the mountd daemon;
#pgre -fl mountd
If the mountd daemon is not running, start it using:
#svcadm enable svc:/network/nfs/server command.
3. Check the /etc/dfs/dfstab file entries.
The "stale file handle" error
Cause: The file resource on server is moved.
Resolution: Unmount and re-mount the resource again on client.
The "unkown host" error
Cause: The host name of the server on the client is missing from the hosts table.
Resolution: verify the host name in the hosts database that supports the client node.
The "mount point" error
Cause: Non existence of mount point on client.
Resolution:
1. Verify the mount point on client.
2. Check the entry in /etc/vfstab and ensure that the spelling for the directory is correct.
The "no such file" error
Cause: Unknown file resource on server.
Resolution:
1. Verify the directory on server.
2. Check the entry in /etc/vfstab and ensure that the spelling for the directory is correct.
Share to all clients | share -F nfs [path name] |
Share to client1 & client2 with read only permission | share -F nfs -o ro=client1:client2 [path name] |
Share to client1 with read & write permission and for others read only | share -F nfs -o ro,rw=client1[path name] |
Share to client1 with root permission | share -F nfs -o root=client1 [path name] |
Share with anonymous client with root user privilege | share -F nfs anon=0 [path name] |
Share to a domain | share -F nfs -o ro=DomainName [path name] |
The common NFS errors and troubleshooting:
The "rpcbind failure" error
Cause:
1. There is a combination of an incorrect Internet address and a correct host or node name in the hosts database file that supports the client node.
2. The hosts database file that supports the client has the correct server node, but the server node temporarily stops due to an overload.
Resolution:
Check if the server is out of critical resources as memory, swap, disk space etc.
The "server not responding" error
Cause: An accessible server is not running NFS daemon.
Resolution:
1. The network between the local system and server is down. To verify the network, ping the server.
2. The server is down.
The "NFS client fails a reboot" error
Cause: Client is requesting an NFS mount from a non-operational NFS srver.
Resolution:
1. Press stop+A
2. edit /etc/vfstab and comment out the entry for NFS mount.
3. Press Ctrl+D to continue normal boot.
4. Check if the NFS server is operational and functioning properly.
5. After resolving the issue, uncomment the entry in step 2.
The "service not responding" error
Cause: NFS server daemon is not running.
Resolution:
1. Check the run level on server and verify if it is 3:
#who -r
2. check the status of the nfs server daemon:
#svcs svc:/network/nfs/server
#svcadm enable svc:/network/nfs/server
The "program not registered" error
Cause: The server is not running the mountd daemon
Resolution:
1. Check the run level on server and verify if it is 3:
#who -r
2. Check the mountd daemon;
#pgre -fl mountd
If the mountd daemon is not running, start it using:
#svcadm enable svc:/network/nfs/server command.
3. Check the /etc/dfs/dfstab file entries.
The "stale file handle" error
Cause: The file resource on server is moved.
Resolution: Unmount and re-mount the resource again on client.
The "unkown host" error
Cause: The host name of the server on the client is missing from the hosts table.
Resolution: verify the host name in the hosts database that supports the client node.
The "mount point" error
Cause: Non existence of mount point on client.
Resolution:
1. Verify the mount point on client.
2. Check the entry in /etc/vfstab and ensure that the spelling for the directory is correct.
The "no such file" error
Cause: Unknown file resource on server.
Resolution:
1. Verify the directory on server.
2. Check the entry in /etc/vfstab and ensure that the spelling for the directory is correct.
AutoFS:
AutoFS is a file system mechanism that provides automatic mounting the NFS protocol. It is a client side service. AutoFS service mounts and unmounts file systems as required without any user intervention.
AutoMount service: svc:/system/filesystem/autofs:default
Whenever a client machine running automountd daemon tries to access a remote file or directory, the daemon mounts the remote file system to which that file or directory belongs. If the remote file system is not accessed for a defined period of time, it is unmounted by automountd daemon.
If automount starts up and has nothing to mount or unmount, the following is reported when we use automount command:
# automount
automount: no mounts
automount: no unmounts
The automount facility contains three components:
The AutoFS file system:
An AutoFS file system's mount points are defined in the automount maps on the client system.
The automountd daemon:
The script /lib/svc/method/svc-autofs script starts the automountd daemon. It mounts file system on demand and unmount idle mount points.
The automount command:
This command is called at system startup and reads master map to create the intial sets of AutoFS mounts. These AutoFS mounts are not automatically mounted at startup time and they are mounted on demand.
Automount Maps:
The behavior of the automount is determined by a set of files called automount maps. There are four types of maps:
• Master Map: It contains the list of other maps that are used to establish AutoFS system.
-sh-3.00$ cat /etc/auto_master
#
# Copyright 2003 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "@(#)auto_master 1.8 03/04/28 SMI"
#
# Master map for automounter
#
+auto_master
/net -hosts -nosuid,nobrowse
/home auto_home -nobrowse
-sh-3.00$
An entry into /etc/auto_master contains:
mount point: The full path name of a directory.
map name: The direct or indirect map name. If a relative path name is mentioned, then AutoFS checks /etc/nsswitch.conf for the location of map.
mount options: The general options for the map. The mount options are similar to those used to standard NFS mounts.
-nobrowse option prevents all potential mount points from being visible. Only the mounted resources are visible.
-browse option allows all potential mount points to be visible. This is the default option if no option is specified.
Note: The '+' symbol at the beginning of the lines directs automountd to look for NIS, NIS+ or LDAP before it reads rest of the map.
• Direct map: It is used to mount file systems where each mount point does not share a common prefix with other mount points in the map.
A /- entry in the master map(/etc/auto_master) defines a mount point for a direct map.
Sample entry: /- auto_direct -ro
The /etc/auto_direct file contains the absolute path name of the mount point, mount options & shared resource to mount.
Sample entry:
/usr/share/man -ro,soft server1, server2:/usr/share/man
Here server1 and server2 are multiple location from where the resource can be shared depending upon proximity and administrator defined weights
.
• Indirect map: It is useful when we are mounting several file systems that will share a common pathname prefix.
Let us see how an indirect map can be used to manage the directory tree in /home?
We have seen before the following entry into /etc/auto_master:
/home auto_home -nobrowse
The /etc/auto_home lists only relative path names. Indirect maps obtain intial path of the mount point from the master map (/etc/auto_master).
Here in our example, /home is the initial path of the mount point.
Lets see few few sample entries in /etc/auto_home file:
user1 server1:/export/home/user1
user2 server2:/export/home/user2
Here the mount points are /home/user1 & /home/user2. The server1 & server2 are the servers sharing resource /export/home/user1 & /export/home/user2 respectively.
Reducing the auto_home map into single line:
Lets take a scenario where we want : for every login ID, the client remotely mounts the /export/home/loginID directory from the NFS server server1 onto the local mount point /home/loginID.
* server1:/export/home/&
• Special: It provides access to NFS server by using their host names. The two special maps listed in example for /etc/auto_master file are:
The -hosts map: This provides access to all the resources shared by NFS server. The shared resources are mounted below the /net/server_name or /net/server_ip_address directory.
The auto_home map: This provides mechanism to allow users to access their centrally located $HOME directories.
The /net directory:
The shared resources associated with the hosts map entry are mounted below the /net/server_name or /net/server_ip_address directory. Lets say we have a shared resources Shared_Dir1 on Server1. This shared resource can be found under /net/Server1/Shared_Dir1 directory. When we use cd command to this directory, the resource is auto-mounted.
Updating Automount Maps:
After making changes to master map or creation of a direct map, execute the autmount command to make the changes effective.
#automount [-t duration] [-v]
-t : Specifies time in seconds for which file system remains mounted when not in use. The default is 600s.
-v: Verbose mode
Note:
1. There is no need to restart automountd daemon after making the changes to existing entries in a direct map. The new information is used when the automountd daemon next access the map entry to perform a mount.
2. If mount point(first field) of the direct map is changed, automountd should be restarted.
Following Table should be referred to run automount command:
Automount Map | Run if entry is added/deleted | Is Modified |
Master Map | yes | Yes |
Direct Map | yes | No |
Indirect Map | No | No |
Note: The mounted AutoFS file systems can also be verified from /etc/mnttab.
Enabling Automount system:
#svcadm enable svcs:/system/filesystem/autofs
Disabling Automount system:
#svcadm disable svcs:/system/filesystem/autofs
Very nice article.. Appreciate your efforts.
ReplyDeleteREALLY GOOD
ReplyDeleteVery helpful
ReplyDelete