NFS服务器搭建与autofs自动挂载

ε祈祈猫儿з 提交于 2019-12-05 01:15:35

                                                              NFS服务器搭建与autofs自动挂载

一, NFS服务器搭建

  1. NFS简介

NFS(Network File System)网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。

 

         2. 搭建环境

VMware 的两台centos7虚拟机

模式: C/S 模式

服务器:192.168.117.10

客户端:192.168.117.11

 

         3. 步骤

服务器端

(1) 安装nfs服务

[root@localhost ~]# yum install -y  nfs-utils                                     

 

(2)   启动rpc服务和设置开机自启动

 [root@localhost ~]# systemctl start rpcbind                                      

[root@localhost ~]# systemctl enable rpcbind                                    

 

(3)   启动nfs服务和nfs安全传输服务

[root@localhost ~]# systemctl start nfs-server nfs-secure-server                    

[root@localhost ~]# systemctl enable nfs-server nfs-secure-server                  

 

(4)    配置防火墙放行nfs服务

[root@localhost /]# firewall-cmd --permanent --add-service=nfs                   

success                                                                      

[root@localhost /]# firewall-cmd  --reload                                       

Success                                                                      

     

(5)    配置共享文件目录,编辑配置文件:

[root@localhost /]# mkdir /public         #创建public共享目录                    

[root@localhost /]# vi /etc/exports                                               

 /data    192.168.1.0/24(rw,async)                                              

[root@localhost /]# systemctl reload nfs                                           

#重新加载NFS服务,使配置文件生效                                            

 

(6)     使用showmount -e localhost                                                  

             

(7)     创建/data目录添加文件,更改权限    

mkdir /data                                                                    

touch /data/1.txt                                                                

echo "hello nfs" >> /data/1.txt                                                    

chown -R nfsnobody.nfsnobody /data                                              

 

客户端

1)使用showmount工具

yum -y intall nfs-utils                                                            

    

2)挂载至本地/mnt目录                 

[root@localhost ~]# mount -t nfs 192.168.1.188:/data /mnt                        

[root@localhost ~]# ls/mnt/                                                   

1.txt                                                                       

[root@localhost ~]# echo "2222" >> /mnt/1.txt                                  

 

 

 

二, Autofs自动挂载

  1. 简介

mount 是用来挂载文件系统的,可以在系统启动时挂载(/etc/fstab),也可以在系统启动后挂载(使用 mount 命令)。而光盘、软盘、NFS、SMB 等文件系统具有动态性,即需要的时候才有必要挂载。光驱和软盘一般知道什么时候需要挂载,但是 NFS 和 SMB 就不一定能确定挂载时间。而且 NFS 、 SMB 是基于网络的,不管使用或者不使用,都会造成资源浪费(多少情况下,不用到这些的时候,这些挂载其实是不需要一直存在的)。 而autofs恰好提供了一种功能:如果长时间不用一个文件系统,autofs会把这个文件系统卸载;当你需要用到的时候,只需要cd到挂载点或者ls下挂载点,autofs自动挂接。

 

      2.安装

服务端

1)在客户机安装autofs服务

yum -y install autofs                                                     

         

2)安装服务

 [root@server ftp]# yum install autofs -y                                      

[root@server ftp]# systemctl start autofs                                     

[root@server ftp]# cd /net/                                                 

[root@server net]# ls                                                      

[root@server net]# cd 192.168.117.11                                        

[root@server 192.168.117.11]# ls                                            

ftp                                                                      

[root@server 192.168.117.11]# pwd                                          

/net/192.168.117.11                                                       

 

 

 

3)编辑autofs的主映射文件

  [root@server ~]# vim /etc/auto.master                                       

7 /misc   /etc/auto.misc                                                     

8 /ftp    /etc/auto.mnt                                                            

 

4)配置子配置文件

  [root@server /]# echo "* 192.168.117.11:ftp/&" > /etc/auto.mnt                   

 

5)设置更新挂载时间

 [root@server ~]# vim /etc/sysconfig/autofs                                            

 13 TIMEOUT=10                                                                  

[root@server ftp]# df | grep ftp                                                       

172.25.254.141:/ftp  10473984 3519232   6954752  34% /net/192.168.117.11/ftp          

[root@server ftp]# cd ~                                                             

[root@server ~]# df | grep ftp         ##10秒后取消挂载                              

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!