NFS 文件共享

作者: 説詩 | 来源:发表于2019-02-13 13:08 被阅读29次

    NFS

    network file system (网络文件系统),可以把网络中的一个硬盘当成本机的来使用。
    背景:解决多个服务器之间数据共享

    环境

    CentOS 7.2

    linux 主机 s1 服务端:192.168.134.33
    linux 主机 c1 客户端:192.168.134.131

    开始操作

    一 环境检查:

    1、检查服务器是否安装nfs服务
    rpm  -q  nfs-utils
    
    2、如果没有安装的话执行
    yum install nfs-utils -y
    
    3、启动rpcbind
    /etc/init.d/rpcbind start #centos 6
    /bin/systemctl start rpcbind.service #centos 7
    
    4、启动nfs
    /etc/init.d/nfs start  #centos 6
    /bin/systemctl start nfs.service #centos 7
    

    二 开始配置

    1. 在s1上面编辑一个配置文件 /etc/exports
    /www/ *(rw,sync)    #允许所有的ip访问
    /www/ 192.168.134.131(rw,sync,no_root_squash)
    /www/ 192.168.134.0/24(rw,sync,all_squash,anonuid=501,anongid=501)
    

    文件编写说明:
    rw :读写;
    ro :只读;
    sync :同步模式,内存中数据时时写入磁盘;
    async :不同步,把内存中数据定期写入磁盘中;
    norootsquash :加上这个选项后,root用户就会对共享的目录拥有至高的权限控制,就像是对本机的目录操作一样。不安全,不建议使用;
    root_squash:和上面的选项对应,root用户对共享目录的权限不高,只有普通用户的权限,即限制了root;
    all_squash:不管使用NFS的用户是谁,他的身份都会被限定成为一个指定的普通用户身份;
    anonuid/anongid :要和rootsquash 以及allsquash一同使用,用于指定使用NFS的用户限定后的uid和gid,前提是本机的/etc/passwd中存在这个uid和gid。
    介绍了上面的相关的权限选项后,再来分析一下刚配置的那个/etc/exports文件。其中要共享的目录为/home,信任的主机为192.168.134.0/24这个网段,权限为读写,同步,限定所有使用者,并且限定的uid和gid都为501。

    2. 重启rpcbind nfs
    /bin/systemctl restart rpcbind.service
    /bin/systemctl restart nfs.service
    
    /bin/systemctl enable rpcbind.service #开机启动
    /bin/systemctl enable nfs.service #开机启动
    
    
    3.在s1执行以下命令使上面目录生效
    exportfs -arv   #让上面的目录执行成功
    
    4.在客户端c1上操作
    showmount -e 192.168.134.33
    # 报错 clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
    # 关s1防火墙或开相应端口
    
    mount -t nfs 192.168.134.33:/guazai /nfsdir #挂载,开机之后会失效
    vim /etc/fstab  #编辑开机挂载文件
    192.168.134.33:/guazai  /nfsdir nfs defaults    0 0 
    

    相关文章

      网友评论

        本文标题:NFS 文件共享

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