温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

nfs网络文件系统--学习笔记

发布时间:2020-03-02 08:25:32 来源:网络 阅读:91 作者:15128179570 栏目:系统运维

本次实验的环境是redhat 7.0系统
nfs服务可以将远程linux服务器上的文件共享资源挂载到本地linux主机上,本地的linux主机可以基于TCP/IP协议,像使用本地目录文件一样去操作远程共享的目录文件。

1. 服务器端

1.1 安装

[root@localhost Desktop]# yum install nfs-utils -y

# 关闭iptables
[root@localhost Desktop]# iptables -F
[root@localhost Desktop]# system^C
[root@localhost Desktop]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

1.2 创建共享目录

[root@localhost Desktop]# mkdir /nfsdir
# 确保共享目录有权限,其他人可以读写
[root@localhost Desktop]# chmod -Rf 777 /nfsdir

1.3 配置nfs

主配置文件/etc/exports
格式:共享目录的路径 允许访问的nfs客户端IP(共享权限参数),nfs客户端IP和权限之间没有空格。
权限的参数:

参数 作用
ro 只读
rw 读写
root_squash 当nfs客户端以root管理员访问时,映射为nfs服务器的匿名用户
no_root_squash 芳nfs客户端以root管理员访问时,映射为nfs服务器的root管理员
all_saquash 无论nfs客户端使用什么账户访问,均映射为nfs服务器的匿名用户
sync 同时将数据写入到内存与硬盘中,保证数据不丢
async 优先将数据保存到内存,然后再写入硬盘;这样效率高,但有可丢失数据
[root@localhost Desktop]# vim /etc/exports
/nfsdir 192.168.137.*(rw,sync,root_squash)

1.4 启动

# 启动RPC,nfs需要使用RPC服务
[root@localhost Desktop]# systemctl restart rpcbind.service 
[root@localhost Desktop]# systemctl enable rpcbind.service 
# 启动nfs
[root@localhost Desktop]# systemctl restart nfs-server
[root@localhost Desktop]# systemctl enable nfs-server
ln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/nfs.target.wants/nfs-server.service'

2. 客户端

2.1 安装nfs-utils工具

[root@localhost ~]# yum install nfs-utils -y

2.2 查询服务端共享信息

showmount 命令的参数

参数 作用
-e 显示nfs服务器的共享列表
-a 显示本机挂载的fns资源
[root@localhost ~]# showmount -e 192.168.137.10
Export list for 192.168.137.10:
/nfsdir 192.168.137.*

2.3 挂载

[root@localhost ~]# mkdir /nfsdir
[root@localhost ~]# mount -t nfs 192.168.137.10:/nfsdir /nfsdir
[root@localhost ~]# df -Th
Filesystem             Type      Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root  xfs        18G  3.0G   15G  17% /
devtmpfs               devtmpfs  985M     0  985M   0% /dev
tmpfs                  tmpfs     994M  140K  994M   1% /dev/shm
tmpfs                  tmpfs     994M  8.9M  986M   1% /run
tmpfs                  tmpfs     994M     0  994M   0% /sys/fs/cgroup
/dev/sda1              xfs       497M  112M  385M  23% /boot
/dev/sr0               iso9660   3.5G  3.5G     0 100% /media/cdrom
192.168.137.10:/nfsdir nfs4       18G  3.0G   15G  17% /nfsdir

测试成功

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI