(1).安装部署
服务端:
[[email protected] ~]# yum install nfs-utils
[[email protected] ~]# systemctl start nfs
[[email protected] ~]# firewall-cmd --permanent --add-service=nfs
[[email protected] ~]# firewall-cmd --permanent --add-service=rpc-bind
[[email protected] ~]# firewall-cmd --permanent --add-service=mountd

[[email protected] ~]# firewall-cmd --reload

[[email protected] ~]# firewall-cmd --list-all

NFS文件服务器

[[email protected] ~]# mkdir /westos/nfs -p

[[email protected] ~]# vim /etc/exports
/westo/nfs      *(sync)

[[email protected] ~]# exportfs -rv

NFS文件服务器


客户端:
[[email protected] ~]# showmount -e 172.25.254.126    #查看
Export list for 172.25.254.126:
/westos/nfs *
[NFS文件服务器

[[email protected] ~]# mount 172.25.254.126:/westos/nfs /mnt    #挂载
[[email protected] ~]# df
NFS文件服务器 

#2).客户端自动挂载

  在不使用是还把nfs文件系统挂载在本机中会占用资源,可每次使用前都挂载会造成无谓的浪费。而自动挂载可以很好的解决这一矛盾。在使用时自动挂载,不用是自动卸载。

客户端:
[[email protected] ~]# yum install autofs.x86_64
[[email protected] ~]# systemctl start autofs

[[email protected] ~]# rpm -qc autofs                             #查找配置文件,因为不同的版本,文件路径会有区别。

NFS文件服务器


vim /etc/sysconfig/autofs

vim /etc/autofs.conf                               #主配置文件

#
# Define default options for autofs.
#
# MASTER_MAP_NAME - default map name for the master map.
#
#MASTER_MAP_NAME="auto.master"
#
# TIMEOUT - set the default mount timeout in secons. The internal
#           program default is 10 minutes, but the default installed
#           configuration overrides this and sets the timeout to 5
#           minutes to be consistent with earlier autofs releases.
#
TIMEOUT=300            #300秒不用自动卸载
#

[[email protected] ~]# cd /net/172.25.254.126        #默认挂载目录
[[email protected] 172.25.254.126]# cd westos/nfs/    #挂载点

NFS文件服务器

NFS文件服务器


#300秒后查看
[[email protected] nfs]# cd
[[email protected] ~]# df
NFS文件服务器

#3).设置挂载点
[[email protected] ~]# vim /etc/auto.master
/westos/linux         /etc/auto.nfs

#挂载点的上层目录    #子配置文件

NFS文件服务器


[[email protected] ~]# vim /etc/auto.nfs
nfs         -rw         172.25.254.126:/westos/nfs

#挂载点        #挂载方式    #挂载设备

NFS文件服务器

[[email protected] ~]# systemctl restart autofs.service

[[email protected] ~]# cd /westos/linux/nfs
NFS文件服务器

充气autofs服务后,文件/westos/linux/nfs会自动建立。


#4).访问控制

权限控制:

[[email protected] nfs]# touch file
touch: cannot touch ‘file’: Read-only file system    #服务不允许
NFS文件服务器

[[email protected] /]# vim /etc/exports

/westos/nfs     *(sync,rw)

NFS文件服务器

修改为文件后不能充气nfs服务,否则客户端的挂载会出现问题。

[[email protected] /]# exportfs -rv

exporting *:/westos/nfs

NFS文件服务器


[[email protected] nfs]# touch file
touch: cannot touch ‘file’: Permission denied        #权限不够

NFS文件服务器

[[email protected] /]# chmod 777 /westos/nfs

NFS文件服务器

身份控制:

#服务端:
[[email protected] /]# id student
uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)
[[email protected] /]# vim /etc/exports

/westos/nfs     *(sync,rw,anonuid=1000,anongid=1004)    #匿名用户用1000,1004的身份

NFS文件服务器

[[email protected] /]# exportfs -rv
exporting *:/westos/nfs

#客户端:
[[email protected] nfs]# id kiosk
uid=1004(kiosk) gid=1004(kiosk) groups=1004(kiosk)
[[email protected] nfs]# ls -l
total 0

-rw-r--r-- 1 student kiosk 0 Dec  8 22:27 file

NFS文件服务器

#服务端:
[[email protected] nfs]# ls -l
total 0
-rw-r--r--. 1 student westos 0 Dec  8 22:27 file
NFS文件服务器


客户端和服务端存在的用户不同,所以文件文件属猪会以id的方式显示。


[[email protected] /]# vim /etc/exports

/westos/nfs     *(sync,rw,no_root_squash)          #客户端的root用户登陆时仍保持root权限
NFS文件服务器

[[email protected] nfs]# touch file

[[email protected] nfs]# ls -l
total 0
-rw-r--r-- 1 root root 0 Dec  8 22:17 file

NFS文件服务器


访问控制的设置方式有很多,可以man exportfs查看。会有很多范例。可以根据不同的需求自行设定。NFS文件服务器

相关文章:

  • 2021-11-11
  • 2022-03-07
  • 2021-11-09
  • 2021-11-29
  • 2021-09-08
  • 2021-09-08
猜你喜欢
  • 2021-08-20
  • 2022-12-23
  • 2021-10-07
  • 2021-12-13
  • 2021-08-30
  • 2021-11-30
  • 2021-12-29
相关资源
相似解决方案