Linux 中NFS 文件共享服务的部署
一、NFS服务
NFS:网络文件系统,是Unix系统和网络附加存储文件管理常用的文件系统,允许多个客户端通过网络共享文件访问;
二、NFS管理
1.服务端安装nfs
yum install nfs-utils
2.打开nfs,进行配置
[[email protected] ~]# systemctl start nfs
[[email protected] ~]# mkdir /nfsdir
[[email protected] ~]# vim /etc/exports
/nfsdir *(sync) ##所有人同步数据,只读挂载
刷新nfs配置
[[email protected] ~]# exportfs -rv
exporting *:/nfsdir
客户端安装nfs
查看可使用的挂载点
[[email protected] ~]# showmount -e 172.25.254.148
Export list for 172.25.254.148:
/nfsdir *
挂载并编辑
[[email protected] ~]# mount 172.25.254.148:/nfsdir /mnt
[[email protected] ~]# touch /mnt/file
touch: cannot touch ‘/mnt/file’: Read-only file system
3.服务端给指定主机权限
[[email protected] ~]# vim /etc/exports
/nfsdir *(sync) 172.25.254.48(rw,sync)
##允许所有人同步,48主机具有读写权限
(注意:字符格式,否则语法报错syntax:error)
[[email protected] ~]# exportfs -rv (更新)
exporting 172.25.254.48:/nfsdir
exporting *:/nfsdir
客户端挂载并编辑
[[email protected] ~]# mount 172.25.254.148:/nfsdir /mnt
[[email protected] ~]# touch /mnt/file
touch: cannot touch ‘/mnt/file’: Permission denied
##权限拒绝,跟/nfsdir目录权限有关
三、配置自动挂载/卸载 ##客户端
1.安装autofs服务
2.开启autofs服务,自动生成/net
3.实现自动挂载
切换到cd /net/172.25.254.148/nfsdir即可
[[email protected] ~]# cd /net/
[[email protected] net]# ls
[[email protected] net]# cd 172.25.254.148
[[email protected] 172.25.254.108]# cd nfsdir/
[[email protected] nfsdir]# df
4.当挂载点不使用时,会自动卸载,默认时间为300S
编辑配置文件,变更自动卸载时间
[[email protected] 172.25.254.148]# vim /etc/autofs.conf
10 # timeout - set the default mount timeout in secons. The internal
11 # program default is 10 minutes, but the default installed
12 # configuration overrides this and sets the timeout to 5
13 # minutes to be consistent with earlier autofs releases.
14 #
15 timeout = 10
5.设置自动挂载目录
[[email protected] ]# vim /etc/auto.master
7 /misc /etc/auto.misc
8 /mnt /etc/auto.mnt (挂载的上级目录)
[[email protected] ]# vim /etc/auto.mnt
[[email protected] mnt]# cat /etc/auto.mnt
nfsdir -ro,vers=3 172.25.254.148:/nfsdir
重启后,自动以配置参数挂载
[[email protected] ]# cd /mnt
[[email protected] mnt]# ls
[[email protected] mnt]# cd nfsdir
[[email protected] nfsdir]# df
切出/mnt/nfsdir目录10s后,/mnt/nfsdir会自动卸载
6.自动挂载的权限设置
服务端修改配置文件,指定root用户挂载
[[email protected] ~]# vim /etc/exports
客户端配置
服务端修改配置文件,指定用户user和组group
[[email protected] ~]# vim /etc/exports
[[email protected] ~]# exportfs -rv
exporting 172.25.254.8:/nfsdir
exporting *:/nfsdir
[[email protected] ~]# cat /etc/exports
设定权限 chmod 777 /nfsdir/
客户端配置