NFS:网络文件系统,是Unix系统和网络附加存储文件管理常用的文件系统,允许多个客户端通过网络共享文件访问;
二、NFS管理
1.服务端安装nfs
yum install nfs-utils
2.打开nfs,进行配置
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# mkdir /nfsdir
[root@localhost ~]# vim /etc/exports
/nfsdir *(sync) ##所有人同步数据,只读挂载
[root@localhost ~]# exportfs -rv
exporting *:/nfsdir
客户端安装nfs
查看可使用的挂载点
[root@foundation ~]# showmount -e 172.25.254.148
Export list for 172.25.254.148:
/nfsdir *
[root@foundation48 ~]# mount 172.25.254.148:/nfsdir /mnt
touch: cannot touch ‘/mnt/file’: Read-only file system
3.服务端给指定主机权限
[root@localhost ~]# vim /etc/exports
/nfsdir *(sync) 172.25.254.48(rw,sync)
##允许所有人同步,48主机具有读写权限
(注意:字符格式,否则语法报错syntax:error)
exporting 172.25.254.48:/nfsdir
exporting *:/nfsdir
客户端挂载并编辑
[root@foundation48 ~]# mount 172.25.254.148:/nfsdir /mnt
touch: cannot touch ‘/mnt/file’: Permission denied
##权限拒绝,跟/nfsdir目录权限有关
三、配置自动挂载/卸载 ##客户端
1.安装autofs服务
2.开启autofs服务,自动生成/net
3.实现自动挂载
切换到cd /net/172.25.254.148/nfsdir即可
[root@foundation48 net]# ls
[root@foundation48 net]# cd 172.25.254.148
[root@foundation48 nfsdir]# df
4.当挂载点不使用时,会自动卸载,默认时间为300S
编辑配置文件,变更自动卸载时间
[root@foundation8 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.设置自动挂载目录
[root@foundation48 ]# vim /etc/auto.master
7 /misc /etc/auto.misc
8 /mnt /etc/auto.mnt (挂载的上级目录)
[root@foundation48 mnt]# cat /etc/auto.mnt
nfsdir -ro,vers=3 172.25.254.148:/nfsdir
重启后,自动以配置参数挂载
[root@foundation8 ]# cd /mnt[root@foundation8 mnt]# ls
[root@foundation8 mnt]# cd nfsdir
[root@foundation8 nfsdir]# df
切出/mnt/nfsdir目录10s后,/mnt/nfsdir会自动卸载
6.自动挂载的权限设置
服务端修改配置文件,指定root用户挂载
[root@localhost ~]# vim /etc/exports
客户端配置
[root@localhost ~]# vim /etc/exports
[root@localhost ~]# exportfs -rv
exporting 172.25.254.8:/nfsdir
exporting *:/nfsdir
[root@localhost ~]# cat /etc/exports
设定权限 chmod 777 /nfsdir/
客户端配置