配置nfs

2019/11/12

简介

最近公司需要给局方配置个ftp服务器,局方要求是个固定ip,考虑到我们有个自己的云服务器,但是ftp服务器的硬盘容量要求较高,如果购买云厂商的话,那么代价太大了.由于我们办公室拥有公网的非固定ip,于是就考虑做个域名映射,把办公室大容量的服务器硬盘空间,映射到云服务器挂载来提供给局方访问.

步骤

办公室服务器操作

  1. 做公网映射(略)

  2. 安装nfs服务端

    #1.查看系统版本
    cat /etc/redhat-release
    uname -r
    uname -m
    #2.检查并安装NFS服务
    yum grouplist
    yum install nfs-utils rpcbind -y
    #或者
    yum groupinstall "NFS file server" -y
    #3.启动RPC及NFS服务并检查
    /etc/init.d/rpcbind start
    ps -ef | grep rpc
    /etc/init.d/rpcbind status
    rpcinfo -p localhost
    /etc/init.d/nfs start
    rpcinfo -p localhost
    #4.设置开机自启动并检查
    chkconfig nfs --level 3 on
    chkconfig rpcbind --level 3 on
    chkconfig --list nfs
    chkconfig --list rpcbind
    #5.配置共享/data目录
    cat >> /etc/exports <<EOF
    #shared data for bbs by superwang at 20171017
    #此处配置任意ip可访问
    /application/static_online  *.*.*.*(rw,sync,no_rootl_squash)
    EOF
    cat /etc/exports
    #6.创建共享目录
    mkdir /application/static_online
    #7.平滑加载NFS服务并检查服务
    /etc/init.d/nfs reload
    showmount -e localhost
    #8.查看链接写入名
    cat /var/lib/nfs/etab
    #防火墙配置  nfs使用的 是udp
    -A INPUT -s 117.71.46.0/26 -p tcp -m state --state NEW -m tcp -j ACCEPT
    -A INPUT -s 117.71.46.0/26 -p udp -m state --state NEW -m udp -j ACCEPT
    
  3. 固定端口配置

    #编辑 /etc/sysconfig/nfs
    RQUOTAD_PORT=8021
    LOCKD_TCPPORT=8022
    LOCKD_UDPPORT=8023
    MOUNTD_PORT=8024
    STATD_PORT=8025
    #如果需要修改 111 和2049端口 需要修改/etc/services中的数据,客户端也需要对应修改
    cat /etc/services|grep nfs
    cat /etc/services|grep rpcbind
    #重启服务端
    /etc/init.d/rpcbind start
    /etc/init.d/rpcbind status
    /etc/init.d/nfs restart
    
  4. 路由端口映射

    在路由器上做好端口映射

    111,2049,8021-8025

  5. 查看目前挂在的机器

    showmount -e localhost
    

云服务器操作

  1. 安装nfs客户端

    #1.查看系统版本
    cat /etc/redhat-release
    uname -r
    uname -m
    #2.安装rpc服务并检查
    rpm -qa nfs-utils portmap rpcbind
    yum install nfs-utils rpcbind -y
    #3.启动rpc服务并检查
    /etc/init.d/rpcbind start 
    /etc/init.d/rpcbind status
    #4.设置开机自启动并检查
    chkconfig rpcbind --level 3 on
    chkconfig --list rpcbind
    #5.检查服务端的NFS是否OK
    
  2. 挂载

    #此处使用 soft软挂在 服务端宕机是 df -h不会卡死
    mount -t nfs -o soft xxx.xxx.com:/application/static_online /application/ftp
    
  3. 查看

    df -h
    

    img

备注

NFS配置参数

ro                      只读访问 
rw                      读写访问 
sync                    所有数据在请求时写入共享 
async                   NFS在写入数据前可以相应请求 
secure                  NFS通过1024以下的安全TCP/IP端口发送 
insecure                NFS通过1024以上的端口发送 
wdelay                  如果多个用户要写入NFS目录,则归组写入(默认) 
no_wdelay               如果多个用户要写入NFS目录,则立即写入,当使用async时,无需此设置。 
hide                    在NFS共享目录中不共享其子目录 
no_hide                 共享NFS目录的子目录 
subtree_check           如果共享/usr/bin之类的子目录时,强制NFS检查父目录的权限(默认) 
no_subtree_check        和上面相对,不检查父目录权限 
all_squash              共享文件的UID和GID映射匿名用户anonymous,适合公用目录。 
no_all_squash           保留共享文件的UID和GID(默认) 
root_squash             root用户的所有请求映射成如anonymous用户一样的权限(默认) 
no_root_squas           root用户具有根目录的完全管理访问权限 
anonuid=xxx             指定NFS服务器/etc/passwd文件中匿名用户的UID 
anongid=xxx             指定NFS服务器/etc/passwd文件中匿名用户的GID 

端口

Nfs-utils:提供rpc.nfsd和rpc.mountd两个daemon与其他document说明文件。
rpc.nfsd:管理client是否能够登入主机,及对登入者ID的辨别。
rpc.mountd:管理NFS文件系统,读取/etc/exports对比client取得相应的权限。
Portmap:端口映射;在启动rpc之前做好端口映射工作。

FAQ

权限问题

  1. nfs 的权限配置

    #rw可写
    cat >> /etc/exports <<EOF
    /application/static_online  *.*.*.*(rw,sync,no_rootl_squash)
    EOF
    
  2. 目录的权限配置

    chmod 777 /application/static_online
    
    
  3. 目录拥有者 改为ftp映射的虚拟用户名

(本篇博文完结;中文字数一共:3203字,英文字数一共:451 字)


扫扫加关注公众号 让我们一起学习一起成长

(转载本站文章请注明作者和出处 IT超仔

Post Directory