环境
iptables -F
iptables-save
firewall-cmd --permanent --zone=public --add-service=nfs
firewall-cmd --permanent --zone=public --add-service=rpc-bind
firewall-cmd --permanent --zone=public --add-service=mountd
firewall-cmd --reload
第一步:为了检验NFS配置的效果,我们需要使用两台linux主机,并设置他们所使用的ip地址。
安装nfs软件包
yum -y install nfs-utils
第二步:在NFS服务器上建立用于NFS文件共享的目录,并设置足够的权限确保其他人也有写入权限。
mkdir /nfsfile
chmod -R 777 /nfsfile
echo "welcome to linuxprobe.com" > /nfsfile/readme
第三步:NFS服务程序的配置文件为/etc/exports,默认情况下里面没有任何内容。我们可以按照“共享目录的路径 允许访问的
NFS客户端的格式”,定义要共享的目录与相应的权限。
vim /etc/exports
/nfsfile 192.168.183.*(rw,sync,root_squash)
:wq 保存退出
第四步:启动和启用NFS服务程序。由于在使用NFS服务进行文件共享之前,需要使用RPC服务将NFS服务器的IP地址和端口号等信息
发送给客户端。因此,在启动NFS服务之前,还需要顺带重启并启用rpcbind服务程序,并将这两个服务一并加入开机启动项中。
systemctl restart rpcbind
systemctl enable rpcbind
systemctl start nfs-server
systemctl enable nfs-server
客户端的配置:
showmount -e 192.168.183.172
mkdir /nfsfile
mount -t nfs 192.168.183.172:/nfsfile /nfsfile
df -h
cat /nfsfile/readme
vi /etc/fstab
192.168.183.172:/nfsfile /nfsfile nfs defaults 0 0
:wq 保存退出