Sunteți pe pagina 1din 5

What’s NFS

Network File System (NFS) is a protocol which allows file systems on one system to
be made available on a remote system on the network. NFS works on the server-client
model with server sharing the resource and client mounting it.

NFS versions
The 3 major versions of NFS are :
NFSv2 (very rarely used today. Allows maximum file size of 2GB)
NFSv3 (used in solaris 8 and 9)
NFSv4 (was introduced in solaris 10

All three versions utilizes a collection of RPC protocols and daemons as specified
below.

Solaris Daemons RPC Service Name S10/S11 SMF service Description


rpcbind rpcbind / portmap svc:/network/rpc/bind:default RPC “portmapper”
mountd mountd svc:/network/nfs/server:default MOUNT protocol server
nfsd nfs svc:/network/nfs/server:default NFS server
lockd nlockmgr svc:/network/nfs/nlockmgr:default network lock manager (aka
NLM)
statd status svc:/network/nfs/status:default RPC status monitor
nfs4cbd N/A svc:/network/nfs/cbd:default NFSv4 callback daemon
nfsmapid N/A svc:/network/nfs/mapid:default NFs4v user/group id mapping

NFS sharing
There are many different ways to share a file system or directory on remote system.
Below are few basic examples of sharing a file system as NFS.

1. The general way


The general syntax for solaris 8, 9 and 10 is :

share -F nfs -o [options] [pathname]


For example : sharing /data mount point as read/write to hosts system1 and system2
only. Here rw=options is a Access control list. (IPs can be specified instead of
hostnames here)

# share -F nfs -o rw=system1:system2 /data


2. Solaris 10 ZFS way
Similar example as above for solaris 10 ZFS file system would be :

# zfs set sharenfs='rw=system1:system2' datapool/data


To un-share the file system we shared :

# zfs unshare datapool/data


3. Solaris 11 ZFS way

In case of solaris 11 the syntax differs completely from solaris 10. Here we need
to name the share while sharing it.

# zfs set sharenfs=on datapool/data


# zfs set share=name=datashare,path=/data,prot=nfs,rw=system1,system1 datapool/data
– The old solaris 8,9,10 way is still supported in solaris 11, but we need to add
and entry to /etc/dfs/sharetab to make the NFS share persist across reboots.
Remember its not dfstab in solaris 11.
– For ZFS as NFS shares we do not need to add any entry to any file as SMF services
will take care of sharing it across reboots.

Mounting NFS share at NFS client


Manual Mount
To mount the NFS share manually at the NFS client, the syntax is :

mount -F nfs -o [options] [NFS_server]:[mountpoint]


For the NFS mount point to mount automatically across reboots, use the /etc/vfstab
and add below entry :

#device device mount FS fsck mount


mount
#to mount to fsck point type pass at boot
options
192.168.10.23:/data - /mnt nfs - yes
ro,bg,vers=3
Note the bg option in the last column. It stands for background and allow the boot
process to proceed should the NFS server not be available at boot time.

Gathering info
There are many commands to get information of NFS shares.

1. share
Use the share command on NFS server to display the current shares with all the
options :

# share
- /data rw=system1 ""
- /home/john rw=system1,system2 ""

2. showmount -e
The showmount -e command contacts the mountd daemon and lists all the shares with
options.

# showmount -e
3. dfshares
The dfshare command displays the same information as showmount -e but in a
different format.

#dfshares

Sharing using dfstab


The NFS shares, shared using the share command won’t persist across reboots. The
solution to this is using the /etc/dfs/dfstab file. The general format of a NFS
entry in dfstab file is:

share -F nfs -o rw=system1 -d "Home Dir" /export/home


After adding the entries to the dfstab we need to use the shareall command to share
the entities mentioned in the dfstab

# shareall
Now, similar to shareall, to un-share all the NFS shares in one go use :

# unshareall
Now, similar to /etc/vfstab, all the NFS shares that are currently shares are
listed in the /etd/dfs/sharetab file.

NFS server/client Start/Stop


Before you can start sharing NFS shares and mounting them on remote server, you
must start the NFS server and NFS client.
For Solaris 8,9 :

# /etc/init.d/nfs.server start
# /etc/init.d/nfs.server stop
For Solaris 10 :

# svcadm enable svc:/network/nfs/server:default


# svcadm disable svc:/network/nfs/server:default

CentOS / RHEL 7 : Configuring an NFS server and NFS client

NFS allows a linux server to share directories with other UNIX clients over
network. NFS server exports a directory and NFS client mounts this directory.
RHEL 7 supports two version of NFS – NFSv3 and NFSv4.

NFS server and RPC processes


starting the nfs-server process starts the NFS server and other RPC processes. RPC
processes includes:
– rpc.statd : implements monitoring protocol (NSM) between NFS client and NFS
server
– rpc.mountd : NFS mount daemon that implements the server side of the mount
requests from NFSv3 clients.
– rpc.idmapd : Maps NFSv4 names and local UIDs and GIDs
– rpc.rquotad : provides user quota information for remote users.

Configuring NFS server


1. Install the required nfs packages if not already installed on the server :

# rpm -qa | grep nfs-utils


# yum install nfs-utils rpcbind
2. Enable the services at boot time:

# systemctl enable nfs-server


# systemctl enable rpcbind
# systemctl enable nfs-lock
In RHEL7.1 (nfs-utils-1.3.0-8.el7) enabling nfs-lock does not work (No such file or
directory). it does not need to be enabled since rpc-statd.service is static.

# systemctl enable nfs-idmap


In RHEL7.1 (nfs-utils-1.3.0-8.el7) this does not work (No such file or directory).
it does not need to be enabled since nfs-idmapd.service is static.

3. Start the NFS services:

# systemctl start rpcbind


# systemctl start nfs-server
# systemctl start nfs-lock
# systemctl start nfs-idmap
4. Check the status of NFS service:

# systemctl status nfs


5. Create a shared directory:

# mkdir /test
6. Export the directory. The format of the /etc/exports file is :

dir client1 (options) [client2(options)...]


Client options include (defaults are listed first) :
ro / rw :
a) ro : allow clients read only access to the share.
b) rw : allow clients read write access to the share.
sync / async :
a) sync : NFS server replies to request only after changes made by previous request
are written to disk.
b) async : specifies that the server does not have to wait.
wdelay / no_wdelay
a) wdelay : NFS server delays committing write requests when it suspects another
write request is imminent.
b) no_wdelay : use this option to disable to the delay. no_wdelay option can only
be enabled if default sync option is enabled.
no_all_squash / all_squash :
a) no_all_squash : does not change the mapping of remote users.
b) all_squash : to squash all remote users including root.
root_squash / no_root_squash :
a) root_squash : prevent root users connected remotely from having root access.
Effectively squashing remote root privileges.
b) no_root_squash : disable root squashing.

Example :

# vi /etc/exports
/test *(rw)
7. Exporting the share :

# exportfs -r
-r re-exports entries in /etc/exports and sync /var/lib/nfs/etab with /etc/exports.
The /var/lib/nfs/etab is the master export table. Other options that can be used
with exportfs command are :

-a : exports entries in /etc/exports but do not synchronize with /var/lib/nfs/etab


-i : ignore entries in /etc/exports and uses command line arguments.
-u : un-export one or more directories
-o : specify client options on command line
8. Restart the NFS service:

# systemctl restart nfs-server


Configuring NFS client
1. Install the required nfs packages if not already installed on the server :

# rpm -qa | grep nfs-utils


# yum install nfs-utils
2. Use the mount command to mount exported file systems. Syntax for the command:

mount -t nfs -o options host:/remote/export /local/directory


Eample :

# mount -t nfs -o ro,nosuid remote_host:/home /remote_home


This example does the following:
– It mounts /home from remote host (remote_host) on local mount point /remote_home.
– File system is mounted read-only and users are prevented from running a setuid
program (-o ro,nosuid options).

3. Update /etc/fstab to mount NFS shares at boot time.

# vi /etc/fstab
remote_host:/home /remote_home nfs ro,nosuid 0 0
Firewalld services to be active on NFS server
For the NFS server to work, enable the nfs, mountd, and rpc-bind services in the
relevant zone in the firewall-config application or using firewall-cmd :

# firewall-cmd --add-service=nfs --zone=internal --permanent


# firewall-cmd --add-service=mountd --zone=internal --permanent
# firewall-cmd --add-service=rpc-bind --zone=internal --permanent

exportfs -v : Displays a list of shares files and export options on a server


exportfs -a : Exports all directories listed in /etc/exports
exportfs -u : Unexport one or more directories
exportfs -r : Reexport all directories after modifying /etc/exports

S-ar putea să vă placă și