NFS文件共享配合autofs自动挂载
一、配置网络yum源
[root@localhost yum.repos.d]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vim rhel.repo
[qinghua]
name=qinghua
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
enable=1
gpgcheck=0
二、首先安装并配置nfs
服务器端
1.安装nfs
[root@localhost yum.repos.d]# yum install -y nfs-utils
2.在/etc/exports中配置nfs共享目录及参数
[root@localhost yum.repos.d]# vim /etc/exports
共享/data/jfedu 让203段的IP都具有rw读写,和sync同步权限
/data/jfedu 192.168.111.0/24(rw,sync)
3.[root@localhost jfedu]# exportfs -r
客户端
1.挂载服务器端nfs目录
软连接挂载(当服务器端停止服务后不会一直请求,硬链接则会一直请求连接)
[root@localhost jfedu]# mount -t nfs -o nolock,nfsvers=3,vers=3 192.168.111.101:/dd/123 /dd/123
三、客服端安装自动挂载autofs服务
1.安装服务
[root@localhost /]# yum install -y autofs
[root@localhost /]# vim /etc/autofs.conf
timeout=60
添加自动挂载路径上一级目录以及对应的描述文件
[root@localhost /]# vim /etc/auto.master
/yu /etc/yu.misc
编辑描述文件将192.168.111.101:/aa/jfedu文件夹挂载到/yu/123下,类型为nfs,权限为rw,sync
[root@localhost /]# vim /etc/yu.misc
123 -fstype=nfs,rw,sync 192.168.111.101:/aa/123
[root@localhost /]# cd /yu/123
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 13G 4.4G 8.7G 34% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 13M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 1014M 166M 849M 17% /boot
/dev/mapper/centos-home 2.0G 37M 2.0G 2% /home
tmpfs 394M 32K 394M 1% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /media/cdrom
192.168.111.101:/aa/123 15G 4.7G 11G 32% /yu/123
四、错误
1.该错误注意防火墙和selinux,关闭后正常
[root@localhost jfedu]# showmount -e 192.168.111.101
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
2.注意配置文件的规格,IP和权限中间需要加空格(服务端/etc/exports)
[root@localhost data]# mount -t nfs -o nolock,nfsvers=3,vers=3 192.168.111.101:/aa/123 /aa/123
mount.nfs: access denied by server while mounting 192.168.111.101:/aa/123