Configure the NFS Network File System and client usage on CentOS Linux

Source: Internet
Author: User

Configure the NFS Network File System and client usage on CentOS Linux

NFS is short for Network FileSystem and is implemented based on RPC (Remote Procedure Call Protocol Remote process Call Protocol. It was first developed by Sun. The main function is to allow different hosts, different operating systems, and shared files through the network. Therefore, you can simply regard it as a file server! The NFS server allows your PC to mount the directory shared by the NFS server to a local machine. The local machine looks like, the Directory of the remote host is like a disk partition, which is quite convenient to use!
 
NFS server
 
Installing an NFS server is very simple:
 
Yum install nfs-utils protmap

In this way, the nfs-utils provides the NFS server program and corresponding management tools. Protmap is a program for managing RPC connections.

Some NFS server configuration files and commands:
Main configuration file:/etc/exports

NFS file system maintenance command:/usr/sbin/exportfs

Shared Resource logon file:/var/lib/nfs/* tab

Command for querying server shared resources on the client:/usr/sbin/showmount

 
Main configuration file:/etc/exports
The configuration file is in the format of [shared directory] [host name or IP address (parameter, parameter)]
 
Shared Directory: directory path to be shared on the server;

Host Name or IP Address: if the host name or IP address is empty, it indicates that it is shared to all clients;

Parameters: Common NFS share parameters are as follows:
Ro: Read-Only

Rw: read/write

Sync: synchronize data written to memory and Hard Disk

Async: The data is saved in the memory first, rather than directly written to the hard disk.

Secure: NFS is sent through the secure TCP/IP ports below 1024

Insecure: NFS is sent over port 1024.

Wdelay: if multiple users want to write data to the NFS Directory, group write (default)

No_wdelay: if multiple users want to write data to the NFS Directory, write the data immediately. This setting is not required when async is used.

Hide: do not share its subdirectories in the NFS shared directory.

No_hide: a subdirectory that shares the NFS Directory

Subtree_check: If sub-directories such as/usr/bin are shared, force NFS to check the permissions of the parent directory (default)

No_subtree_check: Same as above, but does not check parent directory permissions

All_squash: The UID and GID of the shared file are mapped to the anonymous user anonymous, which is suitable for public directories.

No_all_squash: reserve the UID and GID of the shared file (default)

Root_squash: all requests of the root user are mapped to the same permissions as those of the anonymous user (default)

No_root_squash: the root user has full management access permissions to the root directory.

Anonuid = xxx: Specify the UID of an anonymous user in the NFS server/etc/passwd file

Anongid = xxx: Specify the GID of anonymous users in the NFS server/etc/passwd file

 
If you share the same directory with multiple clients but have different permissions for each client, you can:
[Shared directory] [host name 1 or IP1 (parameter 1, parameter 2)] [host name 2 or IP2 (parameter 3, parameter 4)] example
 
Cat/etc/exports

/Share 192.168.1.6 (rw, no_root_squash) * (ro)

The shared directory/share allows the 192.168.1.6 client to read and write, and the root user has administrative permissions. Other machines only have the read permission.
 
Start NFS-related services:
 
Service portmap start
Service nfs start

Chkconfig -- level 35 nfs on
Chkconfig -- level 35 portmap on

If you do not need to reactivate nfs after modifying the/etc/exports file, use the exportfs command to re-scan the/etc/exports file and re-load the settings.
 
Exportfs-arv

Exportfs command usage:
 
Exportfs [-aruv]

Parameters are described as follows:
-A: All mounting (or unmounting) settings in the/etc/exports file.

-R: Remount the settings in/etc/exports, and synchronously update the content in/etc/exports and/var/lib/nfs/xtab.

-U: unmount a directory.

-V: displays the shared directory on the screen during the export operation.

 
Verify that NFS runs successfully:
 
Rpcinfo-p | grep nfs
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs

NFS client
 
Install software package
 
Yum install nfs-utils protmap

Start necessary services
 
Service portmap start

Display the shared directory of the NFS server
 
Showmount-e 192.168.1.5

Export list for 192.168.1.5:
/Share 192.168.1.0/24
/Nishome 192.168.1.0/24

Create a local directory and mount the remote shared directory
 
Mkdir/share
Mkdir/nishome

Mount-t nfs 192.168.1.5:/sharee/share
Mount-t nfs 192.168.1.5:/nishome

View mounting status on the client
 
Mount

/Dev/sda3 on/type ext3 (rw)
Proc on/proc type proc (rw)
Sysfs on/sys type sysfs (rw)
Devpts on/dev/pts type devpts (rw, gid = 5, mode = 620)
/Dev/sda2 on/data type ext3 (rw)
/Dev/sda1 on/boot type ext3 (rw)
Tmpfs on/dev/shm type tmpfs (rw)
None on/proc/sys/fs/binfmt_misc type binfmt_misc (rw)
Sunrpc on/var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.1.5:/nishome on/nishome type nfs (rw, addr = 192.168.1.5)
192.168.1.5:/share on/share type nfs (rw, addr = 192.168.1.5)

Or
 
Df-h

Filesystem Size Used Avail Use % Mounted on
/Dev/sda3 9.7 GB 1.6G 7.7G 18%/
/Dev/sda2 38G 177 M 36G 1%/data
/Dev/sda1 190 M 19 M 163 M 11%/boot
Tmpfs 59 M 0 59m 0%/dev/shm
192.168.1.5:/nishome 9.7G 1.8G 7.4G 20%/nishome
192.168.1.5:/share 9.7G 1.8G 7.4G 20%/share

Command for uninstalling NFS files on the client
 
Umount/share
Umount/nishome

Automatic mounting at client startup
 
The client can set the NFS file to be automatically mounted when the system starts. You need to write the NFS shared directory mounting information to the/etc/fstab/file to automatically mount the NFS shared directory.
 
Edit the/etc/fstab file:
 
Vi/etc/fstab

Add the following information at the end:
 
192.168.1.5:/home/share nfs ults 0 0

-------------------------------------- Split line --------------------------------------

Install NFS server in Ubuntu 12.04

Install and configure the NFS server to share the Ubuntu 12.04 and ARM files.

Build an nfs server in Ubuntu

File Server NFS configuration details

Build an NFS Network File System server in Ubuntu

Heartbeat_ldirector + LB + NFS for HA, LB, and file sharing

How to Configure NFS server in CentOS 5.5

Install and use NFS in Ubuntu 12.10

-------------------------------------- Split line --------------------------------------

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.