【配置 NFS 服务器和客户端挂载】
1、准备两台虚拟机,安装启动NFS服务器,防火墙放行,两个都需要做
[root@localhost ~]# dnf install nfs-utils -y
[root@localhost ~]# systemctl start nfs-server
[root@localhost ~]# systemctl enable nfs-server
[root@localhost ~]# firewall-cmd --permanent --add-service=nfs
[root@localhost ~]# firewall-cmd --permanent --add-service=mountd
[root@localhost ~]# firewall-cmd --permanent --add-service=rpc-bind
[root@localhost ~]# firewall-cmd --reload
2、配置导出目录
[root@localhost ~]# mkdir /data
[root@localhost ~]# chmod 777 /data/
[root@localhost ~]# touch /data/testfile
[root@localhost ~]# cat /etc/exports
/data 192.168.159.131(rw)
[root@localhost ~]# exportfs -r
3、在客户端查看导出目录
[root@localhost ~]# showmount -e 192.168.159.129
Export list for 192.168.159.129:
/data 192.168.159.131
[root@localhost ~]# mkdir /haha
[root@localhost ~]# mount 192.168.159.129:/data /haha
[root@localhost ~]# df - h /haha
Filesystem Size Used Avail Use% Mounted on
192.168.159.129: /data 45G 4.5G 41G 11% /haha
[root@localhost ~]# cd /haha
[root@localhost haha]# touch testfile1
[root@localhost haha]#ll
total 0
rw- r - r - . 1 nobody nobody 0 Mar 17 17: 05 testfile1
rw- r - r - . 1 root root 0 Mar 17 16: 40 testfile
4、开机自动挂载
[root@localhost ~]# vim /etc/fstab
192.168.115.128: /data /nfsclient/client- data nfs defaults 0 0
保存配置后,重启主机
[root@localhost ~]# df - h /data
Filesystem Size Used Avail Use% Mounted on
192.168.159.129: /data 45G 4.5G 41G 11% /data
【autofs自动挂载】
1、客户端配置autofs
[root@localhost ~]# yum install autofs -y
[root@localhost ~]# cat /etc/auto.master
/haha /etc/auto.nfs
/misc /etc/auto.misc
2、本地端目录 具体挂载配置文件
[root@localhost ~]# cat /etc/auto.nfs
data 192.168.159.129:/data
4、触发自动挂载
[root@localhost ~]# systemctl restart autofs
[root@localhost ~]# cd /haha
[root@localhost haha]# ll
total 0
[root@localhost haha]# cd /haha/data (进入则成功)
[root@localhost data]# ll
total 0
-rw-r--r--. 1 nobody nobody 0 Jul 10 15:08 hahah1
-rw-r--r--. 1 nobody nobody 0 Jul 10 15:00 testfile
[root@localhost ~]# df -h /haha/
Filesystem Size Used Avail Use% Mounted on
/etc/auto.nfs 0 0 0 - /haha (出现则成功)