Linux搭建NFS服务器

什么是NFS

  • NFS是网络文件系统(Network File System)的缩写,是一种分布式文件系统协议,用于在网络上共享文件和目录。
  • NFS允许用户从一个计算机上访问另一个计算机上的文件,就像它们本地存在一样。这意味着,用户可以在本地计算机上打开、编辑和保存远程计算机上的文件,而无需将它们复制到本地计算机上。

NFS服务器的搭建

环境准备

系统IP地址/磁盘
centos7.1(服务器)10.0.128.71
centos7.2(客户机)10.0.128.72

服务器操作
1.安装nfs的相关软件

yum install nfs-utils -y

2.启动nfs-server服务

[root@centos71-1503 ~]# service nfs restart
Redirecting to /bin/systemctl restart nfs.service

3.编辑共享文件的配置文件

[root@centos71-1503 ~]# vi /etc/exports
#加入下面的语句
/share 10.0.0.0/16(rw,all_squash,sync)

/share:共享文件夹
10.0.0.0/16:允许访问的客户机IP地址网段
rw 表示可读可写;ro 表示只能读。
all_squash 表示任何客户机的用户过来访问时为普通用户。
sync 同时将数据写入到内存与硬盘中,保存不丢失数据。
async 优先将数据保存到内存,然后再写入硬盘,效率更高,但可能会丢失数据。

4.将share目录设置为共享文件夹

[root@centos71-1503 ~]# exportfs -rv
exporting 10.0.0.0/16:/share

5.关闭防火墙

[root@centos71-1503 ~]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service

客户机操作
1.安装nfs的相关软件

yum install nfs-utils -y

2.将nfs共享的目录挂载到本机

[root@centos72-1511 ~]# mkdir /myfile
[root@centos72-1511 ~]# mount  10.0.128.71:/share  /myfile
                                         #服务器IP:服务器共享路径      客户机挂载点
[root@centos72-1511 ~]# df -Th
文件系统                类型      容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root xfs        33G  1.1G   32G    4% /
devtmpfs                devtmpfs  910M     0  910M    0% /dev
tmpfs                   tmpfs     921M     0  921M    0% /dev/shm
tmpfs                   tmpfs     921M  8.5M  912M    1% /run
tmpfs                   tmpfs     921M     0  921M    0% /sys/fs/cgroup
/dev/sda1               xfs       497M  124M  373M   25% /boot
tmpfs                   tmpfs     185M     0  185M    0% /run/user/0
10.0.128.71:/share      nfs4       33G  1.1G   32G    4% /myfile

3.进入到对应目录下查看文件

#nfs服务器
[root@centos71-1503 share]# ll
总用量 4
-rw-r--r--. 1 root root 42 4月  22 15:15 test-demo.txt
#客户机
[root@centos72-1511 ~]# cd /myfile/
[root@centos72-1511 myfile]# ll
总用量 4
-rw-r--r--. 1 root root 42 4月  22 15:15 test-demo.txt

注意事项

1.客户机在共享目录下创建文件提示:权限不够
因为nfs服务器的共享目录的权限不够,客户机访问时的身份为普通用户

[root@centos71-1503 /]# ll | grep share
drwxr-xr-x.   2 root root   26 4月  22 15:15 share
#可以看到其他用户没有该目录的写权限
[root@centos71-1503 /]# chmod o+w /share
[root@centos71-1503 /]# ll | grep share
drwxr-xrwx.   2 root root   47 4月  22 15:20 share
#给其他用户分配该目录的写权限即可。
  • 11
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孤岛与风

谢谢您的认可~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值