Board logo

标题: NFS共享存储服务 [打印本页]

作者: admin    时间: 2019-10-6 09:09     标题: NFS共享存储服务

NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。 备注:NFS一般用于服务器之间的共享。 下面使用的系统均为CentOS6.9 NFS服务器 ( IP:192.168.168.130 ) 安装软件: yum -y install nfs-utils rpcbind 需要设置为开机自动运行: chkconfig --level 35 nfs on chkconfig --level 35 rpcbind on 自定义共享文件夹和文件: mkdir -p /www echo 'NFS Server!!!' > /www/index.html chmod -R 777 /www/ 将共享文件夹提供给所有人用:(已经赋予了读写权限) echo "/www *(rw,sync,no_root_squash)" >> /etc/exports nfs的端口设置: 1、固定nfs服务端口以便设置防火墙 [root@localhost ~]# cat /etc/sysconfig/nfs | grep -v "^#" #注释:去掉以下选项前面的 # RQUOTAD_PORT=875 LOCKD_TCPPORT=32803 LOCKD_UDPPORT=32769 MOUNTD_PORT=892 STATD_PORT=662 iptables中需要开放的端口: iptables -I INPUT -p TCP --dport 111 -j ACCEPT iptables -I INPUT -p UDP --dport 111 -j ACCEPT iptables -I INPUT -p TCP --dport 662 -j ACCEPT iptables -I INPUT -p UDP --dport 662 -j ACCEPT iptables -I INPUT -p TCP --dport 875 -j ACCEPT iptables -I INPUT -p UDP --dport 875 -j ACCEPT iptables -I INPUT -p TCP --dport 892 -j ACCEPT iptables -I INPUT -p UDP --dport 892 -j ACCEPT iptables -I INPUT -p TCP --dport 2049 -j ACCEPT iptables -I INPUT -p UDP --dport 2049 -j ACCEPT 保存防火墙规则: iptables-save > /etc/sysconfig/iptables 查看防火墙规则: 图片1.png 重启NFS服务程序: service rpcbind restart service nfs restart 关闭SELinux: setenforce 0 sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config ###### NFS客户端访问NFS共享资源: 安装软件包: yum -y install nfs-utils rpcbind 启动NFS服务程序: service rpcbind start service nfs start chkconfig --level 35 nfs on chkconfig --level 35 rpcbind on 关闭SELinux: setenforce 0 sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config NFS客户端查看NFS服务器共享了哪些目录: showmount -e 192.168.168.130 图片2.png NFS客户端挂载NFS的共享目录:(假设网站文件存放目录为 /var/www/html ) mount -t nfs 192.168.168.130:/www /var/www/html 开机自动挂载: echo 'mount -t nfs 192.168.168.130:/www /var/www/html' >> /etc/rc.d/rc.local 测试:NFS客户端对NFS共享文件夹里的东西有读写的权限。 图片3.png NFS客户端卸载NFS共享文件夹: [root@nfs_client1 ~]# umount /var/www/html/ [root@nfs_client1 ~]# cd /var/www/html/ [root@nfs_client1 html]# ls [root@nfs_client1 html]# 在NFS服务器可以看到NFS客户端创建的文件的属主、属组都为root: 图片4.png 实验证明: 1、多台Web服务器可以同时连接NFS服务器,使用相同的共享资源就可以实现访问不同的Web服务器都看到相同的页面内容 ^_^ ^_^ 2、NFS服务器和所有Web服务器都可以对共享文件夹进行读写操作 ####### 共享多个文件夹提供给所有人用: [root@localhost yum.repos.d]# cat /etc/exports /www *(rw,sync,no_root_squash) /www1 *(rw,sync,no_root_squash) /www2 *(rw,sync,no_root_squash) NFS服务器修改完 /etc/exports 后,需要重启以下两个服务,使修改生效: service rpcbind restart service nfs restart [root@nfs_client1 ~]# showmount -e 192.168.168.130 Export list for 192.168.168.130: /www2 * /www1 * /www * ####### ####### 允许某个网段对共享文件夹进行访问: [root@localhost ~]# cat /etc/exports /www 192.168.168.0/24(rw,sync,no_root_squash) 允许多个IP对共享文件夹进行访问: [root@localhost ~]# cat /etc/exports /www 192.168.168.132(rw,sync,no_root_squash) /www 192.168.168.131(rw,sync,no_root_squash) /www 192.168.168.133(rw,sync,no_root_squash) 笺注: NFS服务器修改完 /etc/exports 后,需要重启以下两个服务,使修改生效: service rpcbind restart service nfs restart 相关文章: Keepalived+LVS CentOS8_NFS共享存储服务 ################################# ################################# 亲,学习研究也要劳逸结合哦,来我微店逛逛,买点东西好好犒劳犒劳自己和家人吧^_^^_^ 电蚊拍可充电式LED灭苍蝇拍大号网面强力灭蚊拍电蚊子拍 wenpai.png 苏泊尔榨汁机杯家用全自动果蔬多功能迷你学生小型便携式炸果汁机 shuiguo.png

图片附件: shuiguo.png (2020-1-30 15:38, 412.47 KB) / 下载次数 40
http://blog.zhuohua.store/attachment.php?aid=4166&k=518d91783f4b9530eb22cca1b7b6ca65&t=1714965564&sid=5z5B98



图片附件: wenpai.png (2020-1-30 15:38, 198.64 KB) / 下载次数 45
http://blog.zhuohua.store/attachment.php?aid=4168&k=627fd33bbde0d54d9c6a0dfb0790f6a8&t=1714965564&sid=5z5B98



图片附件: 图片1.png (2020-5-6 13:52, 133.93 KB) / 下载次数 138
http://blog.zhuohua.store/attachment.php?aid=6901&k=cc9fdbfd158a3f835d466c23b14812e8&t=1714965564&sid=5z5B98



图片附件: 图片2.png (2020-5-6 13:53, 5.58 KB) / 下载次数 146
http://blog.zhuohua.store/attachment.php?aid=6902&k=fb5db3722ad6009f403cf05d718ec889&t=1714965564&sid=5z5B98



图片附件: 图片3.png (2020-5-6 13:53, 18.82 KB) / 下载次数 159
http://blog.zhuohua.store/attachment.php?aid=6903&k=7ef2496b52fa0f50d4d73e45b57382c1&t=1714965564&sid=5z5B98



图片附件: 图片4.png (2020-5-6 13:54, 9.76 KB) / 下载次数 139
http://blog.zhuohua.store/attachment.php?aid=6904&k=a25e458261af2cb28aacc99cf1ac916c&t=1714965564&sid=5z5B98






欢迎光临 blog.zhuohua.store (http://blog.zhuohua.store/) Powered by Discuz! 7.2