NFS (Network File System) is basically developed for sharing of files and folders between Linux /Unix Systems by Sun Microsystems in 1980. It allows to mount your local file systems over a network and remote hosts to interact with them as they is mounted l Ocally on the same system. With the help of NFS, we can set up file sharing between Unix to Linux system and linux< /c11> to Unix system.
650) this.width=650; "class=" Size-full wp-image-4238 "alt=" Install NFS Server in Linux "src=" http://www.tecmint.com/ Wp-content/uploads/2013/09/nfs-server-setup.png "height=" 321 "width=" 435 "/>
Setup NFS Server and NFS Client in Linux
Benefits of NFS
NFS allows local access to remote files.
It uses standard client/server architecture for file sharing between all *Nix based machines.
With NFS It isn't necessary that both machines run on the same OS.
With the help of NFS We can configure centralized storage solutions.
Users get their data irrespective of physical location.
No manual Refresh needed for new files.
Newer version of NFS also supports ACL, pseudo root mounts.
Can is secured with firewalls and Kerberos.
NFS Services
Its a System v-launched service. The NFS Server package includes three facilities, included in the Portmap and nfs-utils Package S.
portmap : It maps calls made from and machines to the correct RPC service (not required with NFSV4 ).
NFS: It translates remote file sharing requests into requests the local file system.
rpc.mountd: This service was responsible for mounting and unmounting of file systems.
Important Files for NFS Configuration
/etc/exports : Its-a main configuration file of NFS, all exported files and directories is defined in this file at the Server end of NFS.
/etc/fstab : To-mount a NFS directory on your system across the reboots, we need-make an ENT Ry in /etc/fstab.
/etc/sysconfig/nfs : Configuration file of NFS to control on which port RPC and other Ser Vices is listening.
Setup and Configure NFS Mounts on Linux Server
To setup NFS mounts, we'll be needing at least Linux/Unix machines. Here in this tutorial, I'll be using the servers.
NFS Server: nfsserver.example.com with ip-192.168.0.100
NFS Client : nfsclient.example.com with ip-192.168.0.101
Installing NFS Server and NFS Client
We need to install the NFS packages on the NFS Server as well as on the NFS Client machine. We can install it via "yum" (Red Hat Linux) and "apt-get" (Debian and ubuntu< /c12>) package installers.
[[email protected] ~]# Yum install nfs-utils nfs-utils-lib[[email protected] ~]# yum install Portmap (not required with NF SV4)
[Email protected] ~]# apt-get install nfs-utils nfs-utils-lib
Now start, the services on both machines.
[[email protected] ~]#/etc/init.d/portmap start[[email protected] ~]#/etc/init.d/nfs start[[email protected] ~]# Chkcon Fig--level portmap on[[email protected] ~]# Chkconfig--level NFS on
After installing packages and starting services on both the machines, we need to configure both the machines for file Shar Ing.
Setting up the NFS Server
First we'll be configuring the NFS server.
Configure Export Directory
For sharing a directory with NFS, we need to make an entry in "/etc/exports" configuration file. Here I'll be creating a new directory named "nfsshare" on "/" Partition to share with client server< /c4>, you can also share a already existing directory with NFS.
[Email protected] ~]# Mkdir/nfsshare
Now we need to make a entry in "/etc/exports" and restart the services to make our directory shareable In the network.
[Email protected] ~]# vi/etc/exports/nfsshare 192.168.0.101 (Rw,sync,no_root_squash)
In the above example, there are a directory in / partition named "nfsshare" are being shared with client I P "192.168.0.101" with read and write (rw) privilege, where can also use hostname of the client in the "the" IP in above example.
Options for NFS
Some Other options we can use the "/etc/exports" file for file sharing is as follows.
ro: With the "This" option we can provide read only access to the shared files i.e client 'll is able to read.
rw: This option allows the client server to both read and write access within The shared directory.
sync: Sync confirms requests to the shared directory is only once the changes has been committed.
no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger file system, NFS performs scans of every directory above It, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
No_root_squash: This phrase allows root to connect to the designated directory.
For more options with '/etc/exports', you is recommended to read the mans pages for export.
Setting up the NFS Client
After configuring the server for NFS , we need to Mount this shared directory or partition in the client< /c2> server.
Mount Shared directories on NFS Client
Now at the client end for NFS, we need to Mount This directory in our servers to access it locally. To doing so, first we need to find out that shares available on the remote server or NFS server.
[[email protected] ~]# showmount-e 192.168.0.100Export list for 192.168.0.100:/nfsshare 192.168.0.101
Above command shows that a directory named 'nfsshare' is available at '192.168.0.100' to share with your Server.
Mount Shared NFS Directory
To Mount this shared NFS directory We can use following Mount command.
[Email protected] ~]# mount-t NFS 192.168.0.100:/nfsshare/mnt/nfsshare
The above command would mount that shared directory '/mnt/nfsshare' on the client server. You can verify it following command.
[email protected] ~]# Mount | grep nfssunrpc on/var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) nfsd ON/PROC/FS/NFSD type NFSD (rw) 192.168.0.100:/nfsshare ON/MNT type NFS (RW,ADDR=192.168.0.100)
The above Mount command mounted the NFS shared directory on to NFS client temporarily, to mount a NFS D Irectory permanently on your system across the reboots, we need to make a entry in "/etc/fstab “.
[Email protected] ~]# Vi/etc/fstab
ADD the following new line as shown below.
192.168.0.100:/nfsshare/mnt NFS Defauls 0 0
Test the working of NFS Setup
We can test our NFS Server Setup by creating a test file on the server end and check it availability at NFS Client side or Vice-versa.
At the NFSServer end
I have created a new text file named "nfstest.txt' in that shared directory.
[email protected] ~]# cat >/nfsshare/nfstest.txtthis is a test file to test the working of NFS Server Setup.
At the NFSClient end
Go to this shared directory in client server and you'll find that shared file without any manual refresh or servi Ce restart.
[[Email protected]]# ll/mnt/nfssharetotal 4-rw-r--r--1 root root-Sep 21:44 nfstest.txt[email protected] ~]# cat/m Nt/nfsshare/nfstest.txtthis is a test file to test the working of NFS Server Setup.
Removing the NFS Mount
If you want to unmount This shared directory from your server after you is done with the file sharing, you can s imply Unmount that particular directory with "umount" command. See this example below.
[Email protected] ~]# Umount/mnt/nfsshare
You can see the mounts were removed and then looking at the filesystem again.
[[email protected] ~]# df-h-F NFS
You'll see that those gkfx directories is not the available any more.
Important commands for NFS
Some more important commands for NFS.
-
showmount-e : Shows the available shares on Your local machine
-
showmount-e <server-ip or Hostname> : Lists The available shares at the remote server
- p> showmount-d : Lists all the sub directories
-
exportfs-v : Displays a list of shares files and options on a server
-
exportfs-a : Exports all shares listed in /etc/exports , or given name
-
exportfs-u : Unexports all shares listed in /etc/exports , or given name
-
exportfs-r : Refresh The server ' s list after modifying /etc/exports
This is the it with NFS mounts for now, this is just a start, I'll come up with more option and features of nfs< /c1> the future articles. Till then, the stay connected with the tecmint.com for more exciting and interesting tutorials in the future. Do leave your comments and suggestions below in the comment box.
This article is from the "Little Bird Your Mother" blog, please make sure to keep this source http://xiaoxiaoniao.blog.51cto.com/8727225/1433082