美文网首页
NFS:网络文件系统

NFS:网络文件系统

作者: 朱溪江 | 来源:发表于2019-01-13 18:41 被阅读10次

NFS 重要指数5星
项目名称: 为集群中的 Web Server 配置后端存储

NFS:Network File System 网络文件系统,Unix系统之间共享文件的一种协议
NFS 的客户端主要为Linux
支持多节点同时挂载以及并发写入
========================================================
nas 192.168.122.59
web1 192.168.122.85
web2 192.168.122.166
web3 192.168.122.111

nas web1 web2 web3

# sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
# setenforce 0
centos6
# iptables -F
# service iptables save
centos7
# systemctl stop firewalld
# systemctl disable firewalld

# vim /etc/hosts [可选]
192.168.122.59  nas
192.168.122.85  web1
192.168.122.166 web2
192.168.122.111 web3

NFS
1.安装软件
yum -y install nfs-utils(主包提供文件系统)
yum -y install rpcbind(提供rpc协议)
2.启动服务------>这两个服务必须同时启用
systemctl start nfs
systemctl start rpcbind

一、nas(存储端)
[root@nas ~]# yum -y install nfs-utils
[root@nas ~]# mkdir /webdata //存储网站代码
[root@nas ~]# echo "nfs test..." > /webdata/index.html

[root@nas ~]# vim /etc/exports
/webdata 192.168.122.0/24(rw,sync,no_root_squash) //不压制root(当client端使用root挂载时,也有root权限) 挂载是root ,同样保持root权限
[root@nas ~]# systemctl start nfs-server
[root@nas ~]# systemctl enable nfs-server
[root@nas ~]# exportfs -v
/webdata 192.168.122.0/24(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)

二、web1 web2 web3 客户端
以web1为例:
[root@web1 ~]# yum -y install nfs-utils httpd
[root@web1 ~]# systemctl start httpd
[root@web1 ~]# systemctl enable httpd

  1. 查看存储端共享 [可选]
    [root@web1 ~]# showmount -e nas
    Export list for nas:
    /webdata 192.168.122.0/24
    ps -ef | grep nfs

  2. 手动挂载 [可选]
    [root@web1 ~]# mount -t nfs nas:/webdata /var/www/html/
    [root@web1 ~]# umount /var/www/html/

  3. 自动挂载到网站主目录
    [root@web1 ~]# vim /etc/fstab
    nas:/webdata /var/www/html nfs defaults 0 0
    [root@web1 ~]# mount -a

  4. 查看挂载
    [root@web1 ~]# df
    nas:/webdata 7923136 692416 6821568 10% /var/www/html
    [root@web1 ~]# ls /var/www/html/
    index.html

  5. web2 web3同上

三、测试网站访问

# firefox 192.168.122.85
# firefox 192.168.122.111
# firefox 192.168.122.166

systemctl stop NetworkManager
systemctl disable

相关文章

网友评论

      本文标题:NFS:网络文件系统

      本文链接:https://www.haomeiwen.com/subject/mueldqtx.html