NFS:使用autofs实现自动挂载

题目:共享/stu4目录,所有人具有读写权限,但当用户使用该共享目录的时候将帐号映射为匿名用户,指定匿名用户的uid/gid为600,自动挂载nfs服务器上/stu4到本地的/home/nfsfile/stu4目录。

1.网络规划:

服务器端:10.10.54.59

客户端:10.10.54.58

2.客户端和服务器端安装nfs,rpc

##centos5.x中portmap就是指centos6.x中的rpcbind

yum install nfs-utils.x86_64 rpcbind.x86_64 

3.服务器端

1)配置配置文件

vim /etc/exports

=========================

/stu4   *(rw,all_squash,anonuid=600,anongid=600)

==========================

2)新建目录并修改权限

[root@xiao59 ~]# mkdir /stu4

[root@xiao59 ~]# chmod 757 /stu4

3)重启服务

[root@xiao59 ~]# /etc/init.d/rpcbind restart

[root@xiao59 ~]# /etc/init.d/nfs restart

4.客户端:

1)安装autofs

[root@xiao58 ~]# yum install autofs.x86_64  

2)修改主配置文件

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

===========================

/home/nfsfile /etc/auto.nfs

===========================

##注意:/home/nfsfile不需要事先存在

3)建立数据对应文件内的挂载信息与服务器对应的资源

[root@xiao58 ~]# vim /etc/auto.nfs

================================

stu4   -rw  10.10.54.59:/stu4

=================================

4)启动服务

[root@xiao58 ~]# /etc/init.d/autofs stop

Stopping automount:                                        [  OK  ]

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

Loading autofs4:                                           [  OK  ]

Starting automount:                                       [  OK  ]

5.测试

客户端:

##查看主动创建的目录                                      

[root@xiao58 ~]# ll -d /home/nfsfile/

drwxr-xr-x 2 root root 0 Mar  6 20:28 /home/nfsfile/

##切换到要自动挂载的目录

[root@xiao58 ~]# cd /home/nfsfile/stu4

[root@xiao58 ~]# mount |grep nfsfile

10.10.54.59:/stu4 on /home/nfsfile/stu4 type nfs (rw,sloppy,vers=4,addr=10.10.54.59,clientaddr=10.10.54.58)

##查看挂载

[root@xiao58 ~]# Filesystem            Size  Used Avail Use% Mounted on

/dev/sda2             6.0G  3.7G  2.0G  66% /

tmpfs                 246M     0  246M   0% /dev/shm

/dev/sda1             194M   26M  159M  14% /boot

/dev/sda3             5.0G  4.4G  337M  93% /usr

10.10.54.59:/stu4     6.0G  3.1G  2.6G  55% /home/nfsfile/stu4

##切换到挂载目录

[root@xiao58 ~]# cd /home/nfsfile/stu4/

[root@xiao58 stu4]# touch aa

[root@xiao58 stu4]# ll

total 0

-rw-r--r-- 1 nobody nobody 0 Mar  6 21:14 aa

服务器端:

[root@xiao59 stu4]# ll

total 0

-rw-r--r-- 1 600 600 0 Mar  6 21:14 aa

-----映射成功----------------------------

转载于:https://my.oschina.net/xiaoq6427/blog/205829

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值