Linux系统安装NFS服务器

NFS是一种网络文件系统,英文全称Network File System,通过NFS可以让不同的主机系统之间共享文件或目录。通过NFS,用户可以直接在本地NFS客户端读写NFS服务端上的文件,是非常好的共享存储工具。本篇文章将介绍如何在CentOS7上安装NFS服务器,包括服务端和客户端安装两部分。

服务端安装:

一、下载安装nfs-utils

su #切换为root用户
yum install -y nfs-utils #使用yum下载安装nfs

二、创建共享文件夹

mkdir /share #创建名为share的文件夹
chmod 777 /share #给share文件夹777全权限
nfs001 - Linux系统安装NFS服务器

三、编辑配置文件

vi /ect/exports #用vi编辑器打开/ect/目录下的exports文件

在exports文件里写入

/share *(rw,sync,no_root_squash,no_all_squash)
#/share: 共享目录位置。
#*: 客户端 IP 范围,* 代表所有,即没有限制。
#rw: 权限设置,可读可写。
#sync: 同步共享目录。
#no_root_squash: 可以使用 root 授权。
#no_all_squash: 可以使用普通用户授权。
nfs002 - Linux系统安装NFS服务器

四、开启nfs和rpcbind服务

systemctl restart rpcbind #重启rpcbind服务
systemctl restart nfs-server #重启nfs-server服务
systemctl  enable  rpcbind #设置rpcbind服务开机自启
systemctl  enable  nfs-server#设置nfs-server服务开机自启
firewall-cmd --zone=public --permanent --add-service={rpc-bind,mountd,nfs}
firewall-cmd --reload #防火墙需要打开 rpc-bind 和 nfs 的服务
nfs003 - Linux系统安装NFS服务器

五、检查挂载

showmount -e localhost #检查共享文件夹的挂载

六、查询NFS是否正常工作

systemctl status nfs #查询服务状态
systemctl stop nfs #停止服务 
systemctl start nfs #开启服务
systemctl restrart nfs #重启服务
nfs004 - Linux系统安装NFS服务器

NFS服务正常工作,状态为Active,说明配置成功!


客户端安装:

1、安装nfs-utils并创建目录

su #切换为root用户
yum install -y nfs-utils #使用yum下载安装nfs
mkdir /client-share #创建名为client-share的目录
chmod 777 /client-share #给client-share文件夹777全权限

2、执行nfs挂载

mount -t nfs LinuxIPAddress:/client-share /client-share #执行nfs挂载
mount #查看挂载是否成功
#下面测试 NFS
touch /client-share/a #在客户端向共享目录创建一个文件a
#接着去 NFS 服务端 查看,看到共享目录已经成功写入文件a。
此条目发表在CentOS, Linux, RHEL, Tool分类目录,贴了, , , , , , 标签。将固定链接加入收藏夹。

发表回复