NFS服务与触发挂载


一、介绍

Network File System,网络文件系统
– 用途:为客户机提供共享使用的文件夹
– 协议:NFS( 2049)、RPC( 111)

由 autofs 服务提供的“按需访问”机制
– 只要访问挂载点就会触发响应,自动挂载指定设备
– 闲置超过时限(默认5分钟)后,会自动卸载


二、使用

1.NFS


// 安装对应的软件包
[root@tk ~]# yum -y install nfs-utils
// 建立共享文件夹
[root@tk ~]# mkdir /public
[root@tk ~]# echo "test_nfs" > /public/test_nfs.txt
[root@tk ~]# ls /public/
test_nfs.txt
[root@tk ~]# vim /etc/exports
// 写如下的配置语句,表示共享的文件是/public *代表所有主机都可以访问
// ro表示只有只读权限
[root@tk ~]# cat /etc/exports
/public *(ro)
// 重启服务
[root@tk ~]# systemctl restart rpcbind
[root@tk ~]# systemctl restart nfs-server
// 关闭防火墙
[root@tk ~]# systemctl stop firewalld
[root@tk ~]# cat /etc/exports
/public *(ro)
[root@tk ~]#
// 检查201的主机的共享
[root@gitlab ~]# showmount -e 10.0.0.200
Export list for 10.0.0.200:
/public *
[root@gitlab ~]# mkdir /mynfs
[root@gitlab ~]# mount 10.0.0.200:/public /mynfs/
[root@gitlab ~]# ls /mynfs/
test_nfs.txt
[root@gitlab ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   39G  6.2G   33G  17% /
devtmpfs                 2.0G     0  2.0G   0% /dev
tmpfs                    2.0G     0  2.0G   0% /dev/shm
tmpfs                    2.0G   12M  2.0G   1% /run
tmpfs                    2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sr0                 4.3G  4.3G     0 100% /mydvd
/dev/sda1               1014M  133M  882M  14% /boot
/dev/mapper/centos-home   19G   33M   19G   1% /home
tmpfs                    394M     0  394M   0% /run/user/0
10.0.0.200:/public        39G  3.7G   35G  10% /mynfs
[root@gitlab ~]#

2.触发挂载


// 触发挂载实现,必须多级的目录结构: /监控目录/挂载点目录
// 主配置文件 /etc/auto.master
// 建立监控目录
[root@gitlab ~]# mkdir /myauto
// 此时没有文件
[root@gitlab ~]# ls /myauto/
// 添加配置语句 /myauto /autonfs.txt
[root@gitlab ~]# vim /etc/auto.master
[root@gitlab ~]# cat /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
#
# NOTE: mounts done from a hosts map will be mounted with the
#       "nosuid" and "nodev" options unless the "suid" and "dev"
#       options are explicitly given.
#
/net    -hosts
// ... 
+auto.masteri
/myauto /autonfs.txt
// 建立对应的文件
[root@gitlab ~]# vim /autonfs.txt
[root@gitlab ~]#
[root@gitlab ~]# cat /autonfs.txt
nfs -fstype=nfs 10.0.0.200:/public
// 重启服务
[root@gitlab ~]# systemctl restart autofs.service
// 进入目录,发现自动挂载
[root@gitlab ~]# ls /myauto/nfs
test_nfs.txt
[root@gitlab ~]#


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值