首页 > 代码库 > Linux NFS自动挂载autofs配置

Linux NFS自动挂载autofs配置

一、基于Linux下NFS文件系统的自动挂载方式,

前期准备环境两台Linux服务器:

  1. 准备一台NFS服务器端(系统环境centos6.5,ip地址192.168.100.100)

  2. 准备需要挂载NFS服务端的NFS客户端(系统环境centos6.5,ip地址192.168.100.101)

实施:

  1. 现在server端安装NFS保证能正常访问,我们这里通过yum工具安装即可

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

  2. 通过修改NFS配置,共享/data/share/目录

    [root@nfsserver ~]# mkdir /data/share

    [root@nfsserver ~]# vim /etc/exports
    ##########shared data for bbs by oldboy at 20160825
    #/data/share           192.168.100.0/24(rw,sync,hide)
    /data/share           192.168.100.0/24(rw,sync,anonuid=555,anongid=555,all_squash)

  3. 检查NFS是否正常

    [root@nfsserver ~]# showmount -e 192.168.100.100
    Export list for 192.168.100.100:
    /data/share 192.168.100.0/24

  4. 客户端安装NFS客户端及autofs并启动相关服务

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

    [root@nfsclient ~]# yum install autofs -y

    [root@nfsclient ~]# /etc/init.d/rpcbind start

    [root@nfsclient ~]# /etc/init.d/autofs start

  5. 配置客户端自动挂载(autofs)NFS服务端共享目录

        [root@nfsclient ~]# vim /etc/auto.master
        #
        # Sample auto.master file
        # This is a ‘master‘ automounter map and it has the following format:
        # mount-point [map-type[,format]:]map [options]
        # For details of the format look at auto.master(5).
        #
        /misc   /etc/auto.misc
        /mnt    /etc/auto.misc  timeout=60#/mnt为挂载点   /etc/auto.misc为挂载动作

         [root@nfsclient ~]# vim /etc/auto.misc

         # This is an automounter map and it has the following format
         # key [ -mount-options-separated-by-comma ] location
         # Details may be found in the autofs(5) manpage

         cd              -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

         # the following entries are samples to pique your imagination
         #linux          -ro,soft,intr           ftp.example.org:/pub/linux
         #boot           -fstype=ext2            :/dev/hda1
         #floppy         -fstype=auto            :/dev/fd0
         #floppy         -fstype=ext2            :/dev/fd0
         #e2floppy       -fstype=ext2            :/dev/fd0
         #jaz            -fstype=ext2            :/dev/sdc1
         #removable      -fstype=ext2            :/dev/hdd
         nfsdata         -fstype=nfs             192.168.100.100:/data/share

     6.重新启动autofs服务,并检查自动挂载文件是否生效

         [root@nfsclient ~]# /etc/init.d/autofs restart      

         [root@nfsclient ~]# cd /mnt/nfsdata
         [root@nfsclient nfsdata]# ls -l
         total 0
         -rw-r--r-- 1 oldgirl oldgirl 0 Aug 27 00:14 andy
         -rw-r--r-- 1 oldgirl oldgirl 0 Aug 27 00:10 oldboy
         -rw-rw-r-- 1 oldgirl oldgirl 0 Aug 27 00:10 oldgirl
         [root@nfsclient nfsdata]# df -h
         Filesystem                       Size  Used Avail Use% Mounted on
         /dev/mapper/vg_muban-moban_root   38G  1.9G   34G   6% /
          tmpfs                            491M     0  491M   0% /dev/shm
         /dev/sda1                        194M   29M  155M  16% /boot

         192.168.100.100:/data/share       38G  1.9G   34G   6% /mnt/nfsdata

        

Linux NFS自动挂载autofs配置