Network File System in Linux for Beginners

0
55

Network File System(NFS)

The Network File Systems (NFS) protocol works great when it comes to Linux systems because it allows for client flexibility, centralized management of files, and some other great features. To get NFS working properly, you need to set up the NFS server first and then set up the client to test access to the server. As with any other service, you need to install a few packages before doing anything else. The actual NFS  service is the same for both servers and clients, with the difference being found in the services running and the config files.

Installing an NFS Server

Follow these steps to install an NFS server.
Step 1. To begin the NFS server setup, install the required packages:
# yum install -y nfs-utils nfs4-acl-tools
Step 2. Verify the package installation:
# rpm -qa | grep nfs
nfs4-acl-tools-0.3.3-5.el6.x86_64
nfs-utils-1.2.2-7.el6.x86_64
nfs-utils-lib-1.1.5-1.el6.x86_64
Step 3. The NFS server uses three different services to function properly. You need to enable them all at boot for the NFS server to function the way it should:
# chkconfig nfs on
# chkconfig nfslock on
# chkconfig rpcbind on
Step 4. Verify that all three services are set to start on system boot:
# chkconfig –list nfs

nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off

# chkconfig –list nfslock

nfslock 0:off 1:off 2:on 3:on 4:on 5:on 6:off
 
# chkconfig –list rpcbind

netfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
You should also verify that the NFS service is currently stopped because you need to make some configuration changes before you can start it.
Step 5. Verify that the service is off:
# service nfs status
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped

Configuring NFS

The nfs and rpcbind services both control a number of daemons on the system when they are started. Let’s look at the different daemons these two services are composed of:
rpcbind  Forwards incoming requests to the appropriate subservice
rpc.idmapd  Maps the UID and GID to users and groups
rpc.lockd  Manages file locks and releases in case of client disconnect
rpc.nfsd  Responds to client requests for file access
rpc.rquotad  Provides statistics on disk quotas to clients
rpc.statd  Works with rpc.lockd to provide recovery services
 Let’s also look at the config files that you will be dealing with:
 /etc/sysconfig/nfs   Contains the main config files for the NFS service
/etc/exports  Contains a list of resources that will be exported (made available) to clients
 Configuring NFS Config files
 Step 1. Open the main config file for editing by using vi editor:
# vi /etc/sysconfig/nfs
 Step 2. Uncomment the following lines:
MOUNTD_NFS_V1=”no”
MOUNTD_NFS_V2=”no”
MOUNTD_NFS_V3=”no”
RPCNFSDARGS=”-N 2 -N 3”
The first three lines disable the mountd daemon from accepting anything below version 4. The last line  disables the NFS service from even advertising anything but version 4 as well.
 Step 3. Save the file and exit.
Next, let’s work with the /etc/exports file because this defines what resources will be available to your clients. If the file doesn’t exist already, you can create it.

The syntax of the /etc/exports file is

<mountpoint> <host><permissions/options>

 Mount Options:
rw Sets read/write permissions
ro Sets read-only permissions
insecure Allows the use of ports over 1024
sync Specifies that all changes must be written to disk before a command completes
no_wdelay Forces the writing of changes immediately (useful for logs if something crashes)
root_squash Prevents root users
 As an example, you can use the following location to export to the clients:
 /home The home directory containing your users’ data
 Step 4. Set up your exports in the /etc/exports files to be available to any client on the network:
# vi /etc/exports
/home *(ro,sync)
 Here, you define /home directory that you will make available. It defines the /home directory to be exported and allows read-only access to all clients.After you finish defining all the resources you want to export, save and close the file.
Step 5. Start the two NFS services (rpcbind should be running already by default):
# service nfslock start
Starting NFS statd: [ OK ]
# service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
Step 6. Verify that the services have started successfully:
# service rpcbind status
rpcbind (pid 25068) is running…
# service nfslock status
rpc.statd (pid 17726) is running…
# service nfs status
rpc.svcgssd is stopped
rpc.mountd (pid 17780) is running…
nfsd (pid 17777 17776 17775 17774 17773 17772 17771 17770) is
running…
rpc.rquotad (pid 17764) is running
 If you already started the services before creating an /etc/exports file, you can also use the exportfs command to manually export any new resources added to the /etc/exports file.
Troubleshooting NFS
There are three management commands that help with troubleshooting NFS from both the server and client sides:
mountstats Shows information about mounted NFS shares
nfsstat Shows statistics of exported resources
nfsiostat Shows statistics of NFS mounted shares
Connecting Clients
Setting up a client to use NFS is relatively simple when you have the NFS server in place. Let’s set up the Client01 system to use a share on the TECHBUDDIES NFS server.
 Step 1. To start, you need to install the required packages: 
# yum install -y nfs-utils nfs4-acl-tools
These two packages include the necessary files for you to connect to the NFS server and use the exported resources. On the client side, you need only the rpcbind service running to mount NFS resources on the server.

Step 2. Ensure that the required service is set to start on boot:
# chkconfig rpcbind on
You can now create some directories to hold the NFS shares on the local system.
Step 3. Create the local directory to mount the network share:
# mkdir /mnt/{home,temp}
Step 4. Mount the company_data NFS share:
# mount –t nfs 192.168.1.1:/opt/home /mnt/home

Comments

comments