首页 > 其他 > 详细

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

时间:2019-11-17 19:04:24      阅读:75      评论:0      收藏:0      [点我收藏+]

 

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

一、 NFSautofs的简介:

    NFS Network File System的缩写,即网络文件系统。一种使用于分散式 文件系统的协定,由Sun公司开发,于1984年向外公布。功能是通过网络让不同的机器、不同的操作系统能够彼此分享个别的数据,让应用程序在客户通过网络访问位于服务器磁盘中的数据是在类Unix系统间实现磁盘文件共享的一种法。

Autofsmount是用来挂载文件系统的,可以在系统启动的时候挂载也可以在系统启动后挂载。对于本地固定设备,如硬盘可以使用mount挂载;而光盘、软盘、NFSSMB等文件系统具有动态性,即需要的时候才有必要挂载。光驱和软盘我们一般知道什么时候需要挂载,但NFSSMB共享等就不一定知道了,即我们一般不能及时知道NFS共享和SMB什么时候可以挂载。而autofs服务就提供这种功能,好像windows中的光驱自动打开功能,能够及时挂载动态加载的文件系统。免去我们手动挂载的麻烦。要实现光驱,软盘等的动态自动挂载,需要进行相关的配置。

二.NFS文件详解

1. /data/            表示需要共享的目录。

2. IP                表示允许哪个客户端访问。

3. IP                后括号里的设置表示对该共享文件的权限。

4. ro                只读访问

5. rw                读写访问

6. sync              所有数据在请求时写入共享

7. all_squash         共享文件的UIDGID映射匿名用户anonymous,适合公用目录。

8. no_all_squash      保留共享文件的UIDGID(默认)

9. root_squash        root用户的所有请求映射成如anonymous用户一样的权限(默认)

10. no_root_squash    root用户具有根目录的完全管理访问权限

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

1.安装NFS服务器

1 yum install nfs-utils -y   #安装nfs

2 systemctl start nfs        #开启nfs服务

3 systemctl enable nfs       #开机自启动

2.配置NFS服务器

      1 mkdir /westos

2 echo ‘hello,world‘ > /westos/hello  # 建立目录 /westos, 在其中创建测试文件hello

3.通过修改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)

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.服务器测试

      1 showmount -e 192.168.1.152

2 Export list for 192.168.1.152:

3 /westos *

6.配置客户端自动挂载(autofsNFS服务端共享目录

   [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

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

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

[root@nfsclient ~]# cd /mnt/nfsdata

[root@nfsclient nfsdata]# ls - 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

Filesystem   /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

 

.以以上方式完成NFS服务器搭建与autofs自动挂载     

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

原文:https://www.cnblogs.com/xph111/p/11877206.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!