一,NFS (网络文件服务)

NFS是一种基于TCP/IP传输的网络文件系统协议,最初由 sun公司开发
通过使用NFS协议,客户机可以像访问本地目录一样访问远程服务器中的共享资源,NFS 也是NAS 存储设备必然支持的一种协议
NAS存储:
NFS服务的实现依赖于RPC (Remote Processcall,远端过程调用)机制,以完成远程到本地的映射过程。在 centos 7系统中,需要安装nfs-utils、rpcbind 软件包来提供NES 共享服务,前者用于NFS共享发布和访问,后者用于RPC支持。
手动加载NFS共享服务时,应该先启动rpcbind,再启动nfs

nfs端口号2049
RPC端口号111
特点:

采用TCP/IP传输网络文件
安全性低
简单易操作
适合局域网环境

二,实验步骤:
安装nfs和rpcbind软件

修改配置文件设置共享

创建共享目录
开启服务
客户端验证共享目录可访问

rpm -q rpcbind nfs-utils
yum install -y nfs-utils rpcbind
vim /etc/exports#NFS 的配置文件为/etc/exports,文件内容默认为空(无任何共享)/ opt/web 192.168.10.0/24(rw,sync,no_root_squash)
常用选项:

rw
表示允许读写
ro
表示为只读
sync
表示同步写入到内存与硬盘中

no_root_squash
表示当客户机以root身份访问时赋予本地root权限(默认是root_squash),如果不加那么客户端无法在里面编辑或写入文件,因为默认以nfsnobody的权限
root_squash
表示客户机用root用户访问该共享目录时,将root用户映射成匿名用户
其它常用选项:
all_squash
所有访问用户都映射为匿名用户或用户组

async
将数据先保存在内存缓冲区中,必要时才写入磁盘,速度快但会丢失数据42 subtree_check (默认)
若输出目录是一个子目录,则nfs服务器将检查其父目录的权限
no_subtree_check
即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率
systemctl start rpcbind    /需要先启动rpc服务,因为nfs要向rpc注册端口
systemctl start nfs
服务器192.168.118.11上配置:
yum install -y nfs-utils rpcbind
vim /etc/exports
/opt/web 192.168.118.0/24(rw,sync,no_root_squash)
ls /opt/
mkdir -p /opt/web
ls /opt/
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs
netstat -anpu |grep rpc
yum -y install netstat
yum -y install net-tools
netstat -anpu |grep rpc
netstat -anpu |grep nfs
systemctl stop firewalld
setenforce 0
showmount -e 192.168.118.11
exportfs -v

客户机192.168.118.12上配置:
yum -y install nfs-utils rpcbind
showmount -e 192.168.118.11
yum  -y install httpd
ls /var/www/html/
mount -t nfs 192.168.118.11:/opt/web /var/www/html/
df -h
systemctl start httpd
curl 127.0.0.1
echo "Welcome to the Destiny Terminal database" >> /var/www/html/index.html

在浏览器上输入192.168.118.12

posted on 2022-10-20 08:37  知趣。  阅读(196)  评论(0编辑  收藏  举报