Small c to learn Linux (31)--NFS service configuration

NFS : Network File System

Network File System (NFS) is a distributed file system protocol, originally developed by Sun Microsystems in 1984,[1] which allows users on client computers to access files over a computer network as if they were accessing local storage. Like many other protocols, NFS is built on the Open Network Computing Remote Procedure Call (ONC RPC) system. NFS is an open standard defined in Request for Comments (RFC) that allows anyone to implement the protocol.

The nfs-utils is installed by default on centos, and the service can be started directly.

Three key processes:

  • moutnd mounts the daemon, responsible for the client origin authentication process
  • nfsd: file read and write
  • idmapd: id mapping process

NFS configuration file/etc/exports

#文件系统         #客户端{ip | 网段}     #导出属性
/nfsfile       192.168.2.0/24(rw,no_root_squash)

Filesystem export properties:

export properties
rw read and write
async Synchronize
sync asynchronous
root_squash Compress user, convert root user to nfsnobody over network
no_root_squash No compressed users, any client root can access, not secure
all_squash Compress all users, no one is allowed to access as their own, the most secure
anonuid, anongid designated user

show malt

#全部 在nfs服务器端显示所有的挂载会话
showmount -a SERVER_IP

#文件 在服务器端执行,显示那个导出的文件系统被那些客户端挂载过
showmount -d SERVER_IP

#共享,在客户端执行,探查某主机所导出的nfs文件系统
showmount -e SERVER_IP

exportfs export nfs file

#操作所有操作系统
exportfs -a 

#重新导出所有文件系统
exportfs -ra 

#取消导出的所有文件系统
exportfs -ua

#显示详细信息
exportfs -v

The auxiliary process of nfs, such as mountd, listens on fixed ports, which can be achieved by editing parameters such as /etc/sysconfig/nfs

Operation example

The client accesses NFS as a specific user

1) Server

#编辑/etc/exports,压缩所有用户
/nfsfile      172.16.0.0/16(rw,all_squash)

#创建一个新的目录,挂载新的分区sda#,然后使某个UID能够访问
fdisk /dev/sda
mkdir /nfsfile

#开机自动挂载,编辑/etc/fstab并有acl特性,
/dev/sda3     /nfsfile    default,acl  0 0

#生效
mount -a

#创建一个UID=1000的用户
useradd -u 1000 testuser

#设置UID=1000的用户对/nfsfile有rwx权限
setfacl -m u:1000:rwx  /nfsfile

2) Client

#将NFS共享的文件挂载至本地某个目录/mnt/nfs
mkdir /mnt/nfs 
mount -t nfs 172.16.36.215:/nfsfile /mnt/nfs

#编辑/etc/fstab设置为开机自动挂载,_netdev特性可检测挂载网络
172.16.36.215:/nfsfile  /mnt/nfs  default,_netdev 0 0

#创建NFS服务端设置的UID=1000的用户
useradd -u 1000 testuser

#su到testuser
su - testuser

#访问/mnt/nfs目录,测试
cd /mnt/nfs
cp /etc/fstab ./

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325730837&siteId=291194637