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

本次实验的环境是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 命令的参数

[root@localhost ~]# showmount -e 192.168.137.10
Export list for 192.168.137.10:
/nfsdir 192.168.137.*

猜你喜欢

转载自blog.51cto.com/12227788/2471637