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

 

一.NFS文件详解

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

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

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

4. ro                只读访问

5. rw                读写访问

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

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

8. no_all_squash      保留共享文件的UID和GID(默认)

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).配置客户端自动挂载(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

(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自动挂载    

posted @ 2019-11-19 22:22  曾毅ls  阅读(91)  评论(0编辑  收藏  举报