The Network File System (NFS) was originally developed by Sun Microsystems. It allows a machine (NFS client) to mount a shared volume on a remote machine (NFS server) to a local folder. Once mounted, the remote share can be accessed as if it is a local disk. This user transparency is the main advantage of NFS
Setting up an NFS server
Make sure that nfs and portmap services are running.
[root@LinuxBox1 ~]#service nfs start
[root@LinuxBox1 ~]#service portmap start
The main configuration file for NFS is /etc/exports
In this file we will specify which directories should be shared for access from network along with a number of security and performance options. Each line of the file will list a folder to be shared and the details of how it is shared.
The syntax of the file is as follows:
directory machineX(optionA,optionB,.) machineY(optionC,optionD,..) . .
directory : The directory you want to share. All files and directories below this and is in the same file system will be automatically available.
machine : client machines that can access the directory via NFS. This can be either hostname, IP address or network.
Wild cards * and ? can be used in domain names. While a single '*' alone will indicate 'all machines', it is a little bit different with fully qualified domain names. *.example.com can substitute abc.example.com, xyz.example.com etc...but cant substitute pqr.abc.example.com. For this to work you will have to specify *.*.example.com. To represent sub1.example.com, sub2.example.com etc.. we can use sub?.example.com.
We can specify a whole network by using netmasks; for example, 192.168.0.0/25 allows hosts from 192.168.0.1 to 192.168.0.126 to access the share. Alternatively you can use 192.168.0.0/255.255.255.128
options : Options indicates what kind of access privileges are applicable for that particular client. Following is a list of most common options.
ro : Read Only- remote clients cant change the files in the share. (default)
rw : Read Write - clients and both read and write files in the share
sync : Writes the changes to the disk first and then only answers the access request . (default)
async : Allows access request to the share before the changes are written to the disk. This can cause undefined behaviours if the server is shutdown/stopped uncleanly.
root_squash: Prevents the client machine root user from having root privilege on the share. Instead the root user is mapped to user 'nfsnobdy' on the server. Generally this user will have a UID 65534. (default)
no_root_squash : turn off root squashing.
When NFS service is started, /etc/exports file is read by the command /usr/sbin/exportfs and passes the control to RPC services. When this file is changed, it is necessary to re-read it. This can be done by restarting or reloading the nfs service, or using the exportfs command.
[root@LinuxBox1 ~]#service nfs restart
OR
[root@LinuxBox1 ~]#service nfs reload
OR
[root@LinuxBox1 ~]#exporfs -r
of these three, exportfs -r is preferred.
Example:
/etc/exports
/fc5 *
/home/public 192.168.0.5(rw,sync)
/fedora/pub 192.168.0.0/24(rw,sync)
[root@LinuxBox1 ~]#exportfs -r
To list the exported directories
[root@LinuxBox1 ~]#exportfs
/home/public 192.168.0.5
/fedora/pub 192.168.0.0/24
/fc5
OR
[root@LinuxBox1 ~]#showmount -e
Export list for linuxbox1:
/fc5 *
/fedora/pub 192.168.0.0/24
/home/public 192.168.0.5
To view the nfs shares of a remote machine 'linuxbox3'
[root@LinuxBox1 ~]#showmount -e linuxbox3
Export list for linuxbox3:
/home/pub linuxbox1.linuxvalley.com
Setting up an NFS client
Mounting remote NFS shares- use mount command with the following syntax
mount [-o option1,[option2],.....] server:/path/to remote/share /path/to/local/mountpoint
[root@LinuxBox2 ~]#mount -o ro linuxbox1:/fedora/pub /mnt/remote1
[root@LinuxBox2 ~]#mount|grep /fedora/pub
linuxbox1:/fedora/pub on /mnt/remote1 type nfs (ro,addr=192.168.0.101)
To mount this share at boot time, edit /etc/fstab
#device/share mountpoint filesystem mount-options dump fsckorder
linuxbox1:/fedora/pub /mnt/remote1 nfs rw,soft 0 0
[root@LinuxBox2 ~]#mount -a
Common mount options applicable for nfs shares
hard/soft : if an nfs file/server is unavailable temporarily whether the client should stop and wait for the serer to come back online (hard) or report error (soft). The hard option will cause your client program to hang if the server is unavailable for long time. Soft is preferred normally.
intr : NFS requests can be interrupted (usually by pressing Ctrl+C). This option is recommended to be used with hard .
noexec : Binaries can't be executed on mounted filesystem.
nosuid : Disable SUID and SGID bits
rsize=NUM and wsize=NUM : Speed up NFS communication by reading(rwize) and writing(wsize) large data blocks
Now we can access the nfs share /fedora/pub on linuxbox1 through the local directory /mnt/remote1.
No comments:
Post a Comment