autofs自动挂载

autofs自动挂载

autofs使用起来的作用其实和nfs差异不大,关键点在于实现了自动挂载,而且还是在你使用的时候自动挂载,当你不使用的时候自动卸载,比如说你切换当前目录到挂载点目录中,就算在使用了。
server端配置:

server端其实可以沿用nfs的配置,因为它主要是提供一个共享到client,所以能实现这个功能就好。

------------------------ server --------------------------
# 创建共享目录
[root@liuyunfei-rhel-82 ~]# mkdir /nfs-share
# 将目录的权限全部放开
[root@liuyunfei-rhel-82 ~]# chmod 777 /nfs-share/
# nfs-server需要共享的目录的配置文件
[root@liuyunfei-rhel-82 ~]# vim /etc/exports
------------------------------
# ro,rw,sync,async --- 只读,可读写,同步,异步
# hostname         ------ 可以指定主机名,ip地址,或“*”
/nfs-share/ 192.168.159.133(ro,rw,sync,async) 
            hostname
            *
------------------------------
# 防火墙放行服务
[root@liuyunfei-rhel-82 ~]# firewall-cmd --set-default-zone=trusted
success
# 重启服务,开机自启动
[root@liuyunfei-rhel-82 ~]# systemctl restart nfs-server.service 
[root@liuyunfei-rhel-82 ~]# systemctl enable nfs-server.service 

------------------------ 此为实验内容 --------------------------
[root@rhel-liuyunfei-82 ~]# vim /nfs-share/server.txt
this is the server file
Client端配置:
autofs主目录可以自己创建,子目录不用创建,也可以主目录和子目录都不创建,当重启autofs服务的时候会自动创建。
当server和client都配置好服务,且重启服务以后,当在client中cd进入主目录以后发现什么都没有,不用慌张,这是正常的,你的真正的挂载点在子目录上,cd进入设置的子目录,就可以看到server共享过来的目录下的文件了。
[root@liuyunfei-CentOS-7 ~]# yum install autofs -y
# autofs配置文件
[root@liuyunfei-CentOS-7 ~]# vim /etc/auto.master
# 挂载点的父目录   /etc/auto.misc
/nfs-share       /etc/auto.misc

# autofs约束文件
[root@liuyunfei-CentOS-7 ~]# vim /etc/auto.misc
#c 挂载点的真实目录     -fstype=nfs,rw   server:/nfs-share
storage     -fstype=nfs,rw   server:/nfs-share

# 启动服务
[root@liuyunfei-CentOS-7 ~]# systemctl restart autofs
[root@liuyunfei-CentOS-7 ~]# systemctl enable autofs

# 此目录之前未手动创建,式服务启动自动生成的。切换到本地挂载点查看是否挂载成功(注意,当使用的时候才会显示)
[root@liuyunfei-CentOS-7 ~]# cd /nfs-share/
[root@liuyunfei-CentOS-7 nfs-share]# ls
# 结果为空,什么都没有

# 但是你仍然可以cd进入你设置的真实的挂载点目录,也就是/etc/auto.misc中的子目录
[root@liuyunfei-CentOS-7 nfs-share]# cd storage
[root@liuyunfei-CentOS-7 storage]# ls
server.txt
[root@liuyunfei-CentOS-7 storage]# cat server.txt
this is the server file

# 检查文件系统挂载情况,也是正确的
[root@liuyunfei-CentOS-7 storage]# df -Th
192.168.159.137:/nfs-share nfs4       19G  4.4G   15G  24% /nfs-share/storage
当你手动卸载掉client的挂载点之后,文件系统的挂载条目就会消失,但是当你在此时用的时候,autofs就会自动挂载,不需要像nfs一样刷新/etc/fstab或者是手动进行挂载操作。
[root@liuyunfei-CentOS-7 ~]# df -Th
192.168.159.137:/nfs-share nfs4       19G  4.4G   15G  24% /nfs-share/storage

# 手动卸载autofs的挂载点
[root@liuyunfei-CentOS-7 ~]# umount /nfs-share
[root@liuyunfei-CentOS-7 ~]# df -Th
# 此时发现没有了autofs的文件系统的挂载内容

# 而当你再次进入挂载点的目录时候,autofs的挂载的文件系统又会自动挂载,这就是autofs与nfs的区别之处。
[root@liuyunfei-CentOS-7 ~]# cd /nfs-share/
[root@liuyunfei-CentOS-7 nfs-share]# cd storage/
[root@liuyunfei-CentOS-7 storage]# df -Th
192.168.159.137:/nfs-share nfs4       19G  4.4G   15G  24% /nfs-share/storage
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值