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

本文详细介绍了NFS(网络文件系统)的基本概念、安装步骤、配置方法及客户端自动挂载设置。NFS允许远程计算机共享文件系统,通过简单的配置,用户可以在不同计算机间无缝共享文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

NFS服务器
什么是NFS?

NFS:Network File System,即网络文件系统。
简单地说,一台服务器共享目录(提供NFS服务),客户机可将服务器上的共享目录挂载到本地,从而共享信息。客户端通过RPC获得服务器的提供NFS的端口,并与服务器建立连接,进行资料传输管理。
NFS的安装

yum install nfs-utils -y
systemctl start nfs
systemctl enable nfs-server    ##设定nfs服务开机自启

NFS的配置
编辑配置文件/etc/exports。配置文件的结构分为三部分,即本地要共享出去的目录(如share目录)、允许访问的主机和由该主机登陆NFS服务器的用户的权限设置。

vim /etc/exports
/share 172.25.254.32(ro) 172.25.254.132(rw,sync)

##各项权限说明##
rw:读写
ro:只读
sync:同步模式,内存中数据时时写入磁盘,即数据同步
no_root_squash:登陆NFS主机使用共享目录的使用者,如果该使用者是root身份,那么对于这个共享目录来说,他就具有root的权限。

exportfs -rv

在这里插入图片描述
使用autofs自动挂载,默认5分钟取消挂载 (/etc/auto.master、 /etc/auto.misc)
服务端:创建共享目录

[root@localhost ~]# mkdir /user
[root@localhost ~]# vim /etc/exports
/user *(rw,no_root_squash,sync)
[root@localhost user]# exportfs -arv
exporting *:/user
exporting *:/home/share

客户端:创建挂载点

[root@localhost ~]# mkdir /var/autofs
[root@localhost ~]# yum install autofs -y

编辑 auto.master (主要是控制作用,指定默认目录及对应文件)

root@localhost ~]# vim /etc/auto.master
/var/autofs /etc/auto.misc
[root@localhost ~]# cat /etc/auto.master | grep -v '#'
/misc	/etc/auto.misc
/var/autofs /etc/auto.misc
/net	-hosts
+auto.master
编辑 auto.misc (主要是定义挂载点及指定下一级目录,该目录可以不存在)
[root@localhost ~]# vim /etc/auto.misc
test -rw,soft,intr 192.168.190.138:/user

注意:这里test 是下级目录,千万不要画蛇添足的加/ ,否则自动挂载不成功!!

[root@localhost ~]# cat /etc/auto.misc | grep -v '#'
cd		-fstype=iso9660,ro,nosuid,nodev	:/dev/cdrom
test -rw,soft,intr 192.168.190.138:/user
重启autofs服务:
[root@localhost ~]# /etc/init.d/autofs restart

测试

[root@localhost autofs]# cd /var/autofs/test
[root@localhost test]# ls 
mount
[root@localhost test]# touch 123
服务器端:
[root@localhost ~]# cd /user/
[root@localhost user]# ll
total 4
-rw-r--r--. 1 root root    0 Sep 30 15:57 123
drwxr-xr-x. 2 root root 4096 Sep 30 15:36 mount
autofs 服务 默认300s (5min) 会自动取消挂载 可参考文件 /etc/sysconfig/autofs 设置

[root@localhost ~]# cat /etc/sysconfig/autofs | grep 'TIMEOUT' | grep -v '#'
TIMEOUT=300

1
2
三、 开机自动挂载,永久生效 (修改/etc/fstab)
开机自动挂载nfs服务 修改/etc/fstab 即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值