How to Setup for NFS (Network File System) on Rhel/centos/fedora and Debian/ubuntu

Source: Internet
Author: User
Tags nfsd

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
    1. NFS allows local access to remote files.

    2. It uses standard client/server architecture for file sharing between all *Nix based machines.

    3. With NFS It isn't necessary that both machines run on the same OS.

    4. With the help of NFS We can configure centralized storage solutions.

    5. Users get their data irrespective of physical location.

    6. No manual Refresh needed for new files.

    7. Newer version of NFS also supports ACL, pseudo root mounts.

    8. 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.

    1. portmap : It maps calls made from and machines to the correct RPC service (not required with NFSV4 ).

    2. NFS: It translates remote file sharing requests into requests the local file system.

    3. rpc.mountd: This service was responsible for mounting and unmounting of file systems.

Important Files for NFS Configuration
    1. /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.

    2. /etc/fstab : To-mount a NFS directory on your system across the reboots, we need-make an ENT Ry in /etc/fstab.

    3. /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.

    1. NFS Server: nfsserver.example.com with ip-192.168.0.100

    2. 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.

  1. ro: With the "This" option we can provide read only access to the shared files i.e client 'll is able to read.

  2. rw: This option allows the client server to both read and write access within The shared directory.

  3. sync: Sync confirms requests to the shared directory is only once the changes has been committed.

  4. 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.

  5. 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.

    1. showmount-e : Shows the available shares on Your local machine

    2. showmount-e <server-ip or Hostname> : Lists The available shares at the remote server

    3. p> showmount-d : Lists all the sub directories

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

    5. exportfs-a : Exports all shares listed in /etc/exports , or given name

    6. exportfs-u : Unexports all shares listed in /etc/exports , or given name

    7. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.