(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
[[email protected] ~]# mkdir /westos/nfs -p
[[email protected] ~]# vim /etc/exports
/westo/nfs *(sync)
[[email protected] ~]# exportfs -rv
客户端:
[[email protected] ~]# showmount -e 172.25.254.126 #查看
Export list for 172.25.254.126:
/westos/nfs *
[
[[email protected] ~]# mount 172.25.254.126:/westos/nfs /mnt #挂载
[[email protected] ~]# df
#2).客户端自动挂载
在不使用是还把nfs文件系统挂载在本机中会占用资源,可每次使用前都挂载会造成无谓的浪费。而自动挂载可以很好的解决这一矛盾。在使用时自动挂载,不用是自动卸载。
[[email protected] ~]# yum install autofs.x86_64
[[email protected] ~]# systemctl start autofs
[[email protected] ~]# rpm -qc autofs #查找配置文件,因为不同的版本,文件路径会有区别。
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/ #挂载点
#300秒后查看
[[email protected] nfs]# cd
[[email protected] ~]# df
#3).设置挂载点
[[email protected] ~]# vim /etc/auto.master
/westos/linux /etc/auto.nfs
#挂载点的上层目录 #子配置文件
[[email protected] ~]# vim /etc/auto.nfs
nfs -rw 172.25.254.126:/westos/nfs
#挂载点 #挂载方式 #挂载设备
[[email protected] ~]# cd /westos/linux/nfs
充气autofs服务后,文件/westos/linux/nfs会自动建立。
#4).访问控制
权限控制:
touch: cannot touch ‘file’: Read-only file system #服务不允许
[[email protected] /]# vim /etc/exports
/westos/nfs *(sync,rw)
修改为文件后不能充气nfs服务,否则客户端的挂载会出现问题。
[[email protected] /]# exportfs -rv
exporting *:/westos/nfstouch: cannot touch ‘file’: Permission denied #权限不够
[[email protected] /]# chmod 777 /westos/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的身份
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
[[email protected] nfs]# ls -l
total 0
-rw-r--r--. 1 student westos 0 Dec 8 22:27 file
客户端和服务端存在的用户不同,所以文件文件属猪会以id的方式显示。
[[email protected] /]# vim /etc/exports
/westos/nfs *(sync,rw,no_root_squash) #客户端的root用户登陆时仍保持root权限[[email protected] nfs]# touch file
[[email protected] nfs]# ls -ltotal 0
-rw-r--r-- 1 root root 0 Dec 8 22:17 file
访问控制的设置方式有很多,可以man exportfs查看。会有很多范例。可以根据不同的需求自行设定。