NFS概念

网络文件系统(NFS)是Unix系统和网络附加存储文件管理器常用的网络文件系统,允许多个客户端通过网络共享文件访问。它可用于提供对共享二进制目录的访问,也可用于允许用户在同一工作组中从不同客户端访问其文件
NFS协议有多个版本:Linux支持版本4、版本3和版本2,而大多数系统管理员熟悉的是NFSv3.默认情况下,该协议并不安全,但是更新的版本(如NFSv4)提供了对更安全的身分验证的支持,甚至可以通过kerberos进行加密

NFS的配置

在服务端:

yum install nfs-utils -y
systemctl start nfs
systemctl start firewalld

nfs挂载显示nobody nfs挂载是什么意思_sed

firewall-cmd --permanent --add-service=nfs
 firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --permanent --add-service=mountd
firewall-cmd --reload

nfs挂载显示nobody nfs挂载是什么意思_sed_02

vim /etc/exports		##设置共享目录
/redhat 		*(ro,sync)
##共享目录		*(允许所有人使用) ro(只读) sync(同步更新)
exportfs -rv

nfs挂载显示nobody nfs挂载是什么意思_共享目录_03


nfs挂载显示nobody nfs挂载是什么意思_sed_04

在客户端

showmount -e 172.25.254.132		##查看
mount 172.25.254.132:/redhat /mnt/	##挂载共享目录
df

nfs挂载显示nobody nfs挂载是什么意思_sed_05

自动挂载

[root@xiian net]# systemctl restart autofs.service 
[root@xiian net]# ls
[root@xiian net]# cd 172.25.254.132
[root@xiian 172.25.254.132]# pwd
/net/172.25.254.132
[root@xiian 172.25.254.132]# cd 
[root@xiian ~]# cd /net
[root@xiian net]# ls
172.25.254.132
[root@xiian net]# systemctl restart autofs.service 
[root@xiian net]# ls

nfs挂载显示nobody nfs挂载是什么意思_vim_06


进入路径后,会自动挂载,默认退出目录后300秒内,不会卸载,300秒后自动卸载

[root@xiian net]# cd 172.25.254.132
[root@xiian 172.25.254.132]# pwd
/net/172.25.254.132
[root@xiian 172.25.254.132]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3269968   7203932  32% /
devtmpfs          469332       0    469332   0% /dev
tmpfs             484920      84    484836   1% /dev/shm
tmpfs             484920   12808    472112   3% /run
tmpfs             484920       0    484920   0% /sys/fs/cgroup
[root@xiian 172.25.254.132]# ls
redhat
[root@xiian 172.25.254.132]# cd redhat/
[root@xiian redhat]# df
Filesystem             1K-blocks    Used Available Use% Mounted on
/dev/vda1               10473900 3269968   7203932  32% /
devtmpfs                  469332       0    469332   0% /dev
tmpfs                     484920      84    484836   1% /dev/shm
tmpfs                     484920   12808    472112   3% /run
tmpfs                     484920       0    484920   0% /sys/fs/cgroup
172.25.254.132:/redhat  10473984 3545984   6928000  34% /net/172.25.254.132/redhat

nfs挂载显示nobody nfs挂载是什么意思_vim_07

vim /etc/sysconfig/autofs		##7.0版本,7.0以上为/etc/autofs
 13 TIMEOUT=3					##设置3秒后自动卸载
[root@xiian redhat]# systemctl restart autofs.service

nfs挂载显示nobody nfs挂载是什么意思_sed_08

修改默认的自动挂载位置

[root@xiian ~]# vim /etc/auto.master
/misc	/etc/auto.misc
/opt	/etc/auto.redhat		/opt为最终挂载点的父级目录,/etc/redhat为自己创建的子配置文件,名称可以任意

nfs挂载显示nobody nfs挂载是什么意思_vim_09

[root@xiian ~]# vim /etc/auto.redhat
redhat		172.25.254.132:/redhat		##redhat为最终的挂载点最后一级目录

nfs挂载显示nobody nfs挂载是什么意思_sed_10


测试:

cd /opt/
cd /redhat
[root@xiian redhat]# ls
file  file1  file3  file4  test1  test2
[root@xiian redhat]# pwd
/opt/redhat

nfs挂载显示nobody nfs挂载是什么意思_nfs挂载显示nobody_11

[root@xiian redhat]# df
Filesystem             1K-blocks    Used Available Use% Mounted on
/dev/vda1               10473900 3268972   7204928  32% /
devtmpfs                  469332       0    469332   0% /dev
tmpfs                     484920      84    484836   1% /dev/shm
tmpfs                     484920   12808    472112   3% /run
tmpfs                     484920       0    484920   0% /sys/fs/cgroup
172.25.254.132:/redhat  10473984 3545472   6928512  34% /opt/redhat			##成功挂载到/opt/redhat

nfs挂载显示nobody nfs挂载是什么意思_共享目录_12

设置特定对象可以读写

设定232可以读写

vim /etc/exports
  1 /redhat         *(ro,sync) 172.25.254.232(rw,sync)
exportfs -rv

nfs挂载显示nobody nfs挂载是什么意思_nfs挂载显示nobody_13


在232上

[root@xiian ~]# cd /opt/redhat
[root@xiian redhat]# ll
total 0
-rw-r--r--. 1 student   student   0 Feb 22 00:18 file
-rw-r--r--. 1 student   student   0 Feb 22 00:57 file1
-rw-r--r--. 1 westos    westos    0 Feb 22 01:03 file3
-rw-r--r--. 1 student   student   0 Feb 22 01:13 file4
-rw-r--r--. 1 nfsnobody nfsnobody 0 Feb 22 04:13 file5
-rw-r--r--. 1 student   student   0 Feb 22 01:44 test1
-rw-r--r--. 1 root      westos    0 Feb 22 01:55 test2
[root@xiian redhat]# touch file6
[root@xiian redhat]# ll
total 0
-rw-r--r--. 1 student   student   0 Feb 22 00:18 file
-rw-r--r--. 1 student   student   0 Feb 22 00:57 file1
-rw-r--r--. 1 westos    westos    0 Feb 22 01:03 file3
-rw-r--r--. 1 student   student   0 Feb 22 01:13 file4
-rw-r--r--. 1 nfsnobody nfsnobody 0 Feb 22 04:13 file5
-rw-r--r--. 1 nfsnobody nfsnobody 0 Feb 22  2019 file6
-rw-r--r--. 1 student   student   0 Feb 22 01:44 test1
-rw-r--r--. 1 root      westos    0 Feb 22 01:55 test2

nfs挂载显示nobody nfs挂载是什么意思_nfs挂载显示nobody_14

修改文件创建的所有人所有组为root

vim /etc/exports
  1 /redhat         *(ro,sync) 172.25.254.232(rw,sync,no_root_squash)
exportfs -rv

nfs挂载显示nobody nfs挂载是什么意思_nfs挂载显示nobody_15


232上

[root@xiian ~]# cd /opt/redhat
[root@xiian redhat]# touch file7
[root@xiian redhat]# ll
total 0
-rw-r--r--. 1 student   student   0 Feb 22 00:18 file
-rw-r--r--. 1 student   student   0 Feb 22 00:57 file1
-rw-r--r--. 1 westos    westos    0 Feb 22 01:03 file3
-rw-r--r--. 1 student   student   0 Feb 22 01:13 file4
-rw-r--r--. 1 nfsnobody nfsnobody 0 Feb 22 04:13 file5
-rw-r--r--. 1 nfsnobody nfsnobody 0 Feb 22 04:16 file6
-rw-r--r--. 1 root      root      0 Feb 22  2019 file7

nfs挂载显示nobody nfs挂载是什么意思_sed_16

修改所有组为其他

vim /etc/exports
  1 /redhat         *(ro,sync) 172.25.254.232(rw,sync,anonuid=1001,anongid=100    1)
exportfs -rv

nfs挂载显示nobody nfs挂载是什么意思_nfs挂载显示nobody_17


nfs挂载显示nobody nfs挂载是什么意思_nfs挂载显示nobody_18


232上

cd /opt/redhat
touch test3
[root@xiian redhat]# ll
total 0
-rw-r--r--. 1 student student 0 Feb 22 01:44 test1
-rw-r--r--. 1 root    westos  0 Feb 22 01:55 test2
-rw-r--r--. 1 westos  westos  0 Feb 22  2019 test3

修改兼容版本
修改前

mount
vers=4.0,

nfs挂载显示nobody nfs挂载是什么意思_共享目录_19


修改

vim /etc/auto.redhat
  1 redhat  -vers=3 172.25.254.132:/redhat

nfs挂载显示nobody nfs挂载是什么意思_sed_20