https://blog.csdn.net/qq_38550887/article/details/108014194
接上篇FTP服务,感兴趣的小伙伴也可以去查看
NFS网络文件系统
可以提供文件共享服务,支持多点同时挂载和并发写入
接下来我们进行实验,其中 我们需要一台NFS服务器和若干台web服务器
NFS服务器的地址为192.168.5.141
Web1服务器的地址为 129.168.5.144
所有服务器都检查一下防火墙状态 一定要关闭防火墙
[root@localhost ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
[root@localhost ~]#
安装NFS程序
[root@localhost ~]# yum provides nfs-utils
创建一个文件夹在文件夹中创建哥index文件内容为“NFS测试”,用于web服务器挂载使用
[root@localhost ~]# mkdir /webtest
[root@localhost ~]# echo “NFS测试”>index.html
[root@localhost ~]# ls
anaconda-ks.cfg index.html
[root@localhost ~]# cat index.html
NFS测试
配置nfs配置文件
发布文件资源的位置/webtest ,允许访问的网段为192.168.5拥有读写权限
[root@localhost ~]# vim /etc/exports
/webtest 192.168.5.0/24(rw)
开启nfs服务
[root@localhost ~]# systemctl start nfs-utils.service
查看一下配置的情况
[root@localhost ~]# exportfs -v
/webdate 192.168.5.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
[root@localhost ~]#
NFS服务器配置完毕,接下来在web服务器上进行设置
[root@localhost ~]# yum install httpd -y 在web服务器上安装上httpd程序
查看NFS服务器上的挂载可用挂载点
[root@localhost ~]# showmount -e 192.168.5.141
Export list for 192.168.5.141:
/webtest 192.168.5.0/24
把本机http服务的html的目录挂载到NFS服务器的指定文件夹/webtest内
[root@localhost ~]# mount -t nfs 192.168.5.141:/webtest /var/www/html
[root@localhost ~]# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 475M 0 475M 0% /dev
tmpfs tmpfs 487M 0 487M 0% /dev/shm
tmpfs tmpfs 487M 7.7M 479M 2% /run
tmpfs tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 17G 1.8G 16G 11% /
/dev/sda1 xfs 1014M 137M 878M 14% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
192.168.5.141:/webtest nfs4 17G 1.8G 16G 11% /var/www/html
[root@localhost ~]#
配置成功后 真机浏览器测试,正常访问web服务器的欢迎界面转移到了我们挂载的NFS服务器的/webtest目录内的index.html内。
我们可以用很多台web服务器用这个操作挂载到这个nfs服务器上,方便了我们管理各个web服务器,并且分担了服务器的压力。