返回列表 发帖

CentOS8_NFS共享存储服务

NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。

备注:NFS一般用于服务器之间的共享。

下面使用的系统均为CentOS8

图片1.png
2020-5-6 13:59



NFS服务器 ( IP:192.168.168.154 )

安装软件:
yum -y install nfs-utils rpcbind

需要设置为开机自动运行:
systemctl enable nfs-server
systemctl enable rpcbind


自定义共享文件夹和文件:
mkdir -p /www
echo 'NFS Server!!!' > /www/index.html


将共享文件夹提供给所有人用:(已经赋予了读写权限)
echo "/www *(rw,sync,no_root_squash)" >> /etc/exports



防火墙允许客户端访问本机的NFS服务:
[root@centos8 yum.repos.d]# firewall-cmd --add-service=nfs --permanent
success
[root@centos8 yum.repos.d]# firewall-cmd --add-service={nfs3,mountd,rpc-bind} --permanent
success
[root@centos8 yum.repos.d]# firewall-cmd --reload
success

查看防火墙打开的服务:
[root@centos8 yum.repos.d]# firewall-cmd --zone=public --list-services
cockpit dhcpv6-client mountd nfs nfs3 rpc-bind ssh



重启NFS服务程序:
systemctl restart nfs-server
systemctl restart rpcbind


关闭SELinux:
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config














######
NFS客户端访问NFS共享资源

安装软件包:
yum -y install nfs-utils rpcbind


启动NFS服务程序:
systemctl start nfs-server
systemctl start rpcbind

systemctl enable nfs-server
systemctl enable rpcbind


关闭SELinux:
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config


NFS客户端查看NFS服务器共享了哪些目录: showmount -e 192.168.168.154
图片2.png
2020-5-6 14:01



NFS客户端挂载NFS的共享目录:(假设网站文件存放目录为 /var/www/html )
mount -t nfs 192.168.168.154:/www /var/www/html

开机自动挂载:
echo '192.168.168.154:/www /var/www/html nfs defaults 0 0' >> /etc/fstab


测试:NFS客户端对NFS共享文件夹里的东西有读写的权限。
图片3.png
2020-5-6 14:01




在NFS服务器可以看到NFS客户端创建的文件的属主、属组都为root:
图片4.png
2020-5-6 14:01




实验证明:
1、多台Web服务器可以同时连接NFS服务器,使用相同的共享资源就可以实现访问不同的Web服务器都看到相同的页面内容 ^_^  ^_^

2、NFS服务器和所有Web服务器都可以对共享文件夹进行读写操作




相关文章:
CentOS8_Keepalived+LVS
CentOS8防火墙(firewalld)
CentOS6_NFS共享存储服务

返回列表