//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 服务端安装
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1、服务安装
服务器和客户端都关闭防火墙,装好nfs服务组件:
# 关闭防火墙:
systemctl stop firewalld && systemctl disable firewalld
# 临时关闭selinux:
setenforce 0
# 永久关闭selinux:
sed -i ‘s/=enforcring/=disabled/’ /etc/selinux/config
2、安装服务端
yum install -y nfs-utils rpcbind
3、 检查是否启动了rpcbind服务并监听着 111端口
netstat -tunlp | grep 111
如果没有记录,说明没启动,需要先启动
# 允许启动自动运行
systemctl enable rpcbind.service
# 启动rpc服务
systemctl start rpcbind.service
4、创建共享文件夹(/opt/)
mkdir nfs
5、 配置NFS服务的配置文件,参数配置以下内容
vi /etc/exports
# 2023-08-08 Mike nfs,其中0.4为客户端ip
# 如果存在多个客户端,则可以使用掩码,如:172.30.0.0/24
/opt/nfs 172.30.0.4(rw,sync,no_root_squash)
6、启动nfs服务
systemctl start nfs
ps -ef|grep nfs
7、设置开机启动
systemctl enable rpcbind.service
systemctl enable nfs-server.service
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 客户端安装
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1、安装nfs-utils和rpcbind包
yum install -y nfs-utils rpcbind
2、创建目录保存数据
cd /
mkdir /nfs
cd nfs
netstat -tunlp|grep 111
注意:nfs不启动
3、设置开机启动
systemctl start rpcbind
systemctl enable rpcbind.service
4、用showmount搜索网络中可用的共享文件
# 0.3 为服务端ip
showmount -e 172.30.0.3
注意:如果报错(clnt_create: RPC: Program not registered)
则需要先关闭服务端服务,再重启,顺序如下:
(1)先停止rpcbind
(2)再停止nfs
(3)重启rpcbind和nfs,一定要按顺序启动和停止
5、挂载服务端共享目录
进行mount挂载的时候,挂载和被挂载的当前目录一定不要在挂载目录上!!!
mount -t nfs 172.30.0.3:/opt/nfs /nfs
6、查看挂载情况
df -h
7、取消挂载
umount /nfs
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 报错注意事项
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1、挂载的文件夹,不能大写,只能小写!!!
2、执行挂载命令时,当前不能在挂载目录中
3、如果写入共享目录,报错:权限不足或不能写入,可以设置文件夹权限为777,重启服务端