NFS File Sharing Configuration

Keywords: RPM yum firewall

To install the NFS service, you need to install nfs-utils and rpcbind, the RPC service of NFS, named portmap under Centos5.X and rcpbind under Centos6.X.


1. Query whether nfs service and rpc service are installed

[root@nfs-server ~]# rpm -qa|grep nfs 
[root@nfs-server ~]# rpm -qa|grep rpcbind

2. Using YUM to install nfs and rpcbind

[root@nfs-server ~]# yum -y install nfs*


3. Start nfs service. Before starting nfs service, you must start rpcbind first and then nfs

View rpc information

[root@nfs-server ~]# rpcinfo -p localhost 
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
[root@nfs-server ~]# /etc/init.d/nfs start 
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]

After starting the nfs service, check the rpcinfo information.

[root@nfs-server ~]# rpcinfo -p
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100011    1   udp    875  rquotad
    100011    2   udp    875  rquotad
    100011    1   tcp    875  rquotad
    100011    2   tcp    875  rquotad
    100005    1   udp  35606  mountd
    100005    1   tcp  38238  mountd
    100005    2   udp  33761  mountd
    100005    2   tcp  41083  mountd
    100005    3   udp  47608  mountd
    100005    3   tcp  35056  mountd
    100003    2   tcp   2049  nfs
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    2   tcp   2049  nfs_acl
    100227    3   tcp   2049  nfs_acl
    100003    2   udp   2049  nfs
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    2   udp   2049  nfs_acl
    100227    3   udp   2049  nfs_acl
    100021    1   udp  34627  nlockmgr
    100021    3   udp  34627  nlockmgr
    100021    4   udp  34627  nlockmgr
    100021    1   tcp  46375  nlockmgr
    100021    3   tcp  46375  nlockmgr
    100021    4   tcp  46375  nlockmgr

4. Configure shared directory / share to allow 192.168.10. * access

[root@nfs-server ~]# mkdir /share
[root@nfs-server ~]# cat /etc/exports 
/share 192.168.10.*(rw,sync)

5. View NFS Shared Directory Information

[root@nfs-server ~]# showmount -e 192.168.10.1
Export list for 192.168.10.1:
/share 192.168.10.*

6.NFS client mounts shared directory / share

[root@nfs-server ~]# mount -t nfs 192.168.10.1:/share /mnt
[root@nfs-server ~]# df -h 
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_software-lv_root
	                   18G  1.5G   15G   9% /
tmpfs                 491M     0  491M   0% /dev/shm
/dev/sda1             477M   28M  424M   7% /boot
192.168.10.1:/share/   18G  1.5G   15G   9% /mnt

7.NFS client debugging ideas

Testing whether the client and server networks are acceptable, such as using ping IP address on the client side

Mount it on the server to see if it can be mounted properly

Check the rules of server firewall, beginners can choose to close the firewall directly

8. Managing NFS shared directories

The exportfs command can export shared directories on NFS servers, display shared directories, or not export shared directories.

Command grammar:

exportfs [options] [directories]

option

Meaning

-a

Export or not export all directories

-v

Display the list of export options as well as the list of export options

-u

Do not export the specified directory. When combined with the - a option, all directories are not exported

-f

Specify a new export file instead of / etc/exports file

-r

Reexport all directories

- O < Options >

Specify a list of export options

View NFS Shared Directory Information

showmount [option] [NFS server]

option

Meaning

-a

Display the client's host name or IP address as well as the mounted directory

-e

Display the export list of NFS servers

-d

Display only NFS shared directory information that has been mounted

9. Description of permission parameters for NFS configuration files

Name of parameter

Parametric use

rw

Shared directories have read and write permissions

ro

Shared directories have read-only permissions

sync

When requesting or writing data, the data is synchronously written to the NFS Server hard disk.

Data security will not be lost, shortcomings, performance is worse than not enabling this parameter.

async

When requesting or writing data, it first returns the request, and then writes the data to the memory cache and hard disk.

That is to write data asynchronously. This parameter improves NFS performance, but reduces data security.

Therefore, it is generally not recommended if NFS is in a bottleneck state and data loss is allowed.

If lost, this parameter can be turned on to improve NFS performance.

When writing, the data will go to the memory buffer first, and then write to the disk when the hard disk is empty, so that it can be lifted.

Upgrade Writing Efficiency! The risk is that if the server goes down or shuts down abnormally, the buffer will be lost and not written.

Hard disk data (solution: server motherboard battery or UPS uninterruptible power supply)!

root_squash

All requests from root users are mapped to the same privileges as nfsnobody (anonymous) users

no_root_squash

Close root_squash

all_squash

Mapping all UID s and GID s to anonymous users

no_all_squash

Retain UID and GID for shared files (default)

anonuid

Specify UID for anonymous users in NFS server/etc/passwd file

anongid

Specify GID for anonymous users in NFS server/etc/passwd file

secure

NFS is sent through secure TCP/IP ports below 1024

insecure

NFS is sent over 1024 ports

wdelay

If multiple users want to write to the NFS directory, group write (default)

no_wdelay

If more than one user wants to write to the NFS directory, write immediately. When using async, no settings are required.

subtree_check

Force NFS to check the permissions of parent directories when sharing subdirectories such as / usr/bin

no_subtree_check

As opposed to subtree_check, parent directory permissions are not checked

hide

Do not share subdirectories in NFS shared directories

nohide

Subdirectories of shared NFS directories

mp

If it has been mounted successfully, make it export only one directory

fsid

NFS needs to be able to identify each file system it exports. Usually it will be used for file systems

A UUID, or the device holds the device number of the file system


Posted by tofi84 on Fri, 05 Jul 2019 17:04:39 -0700