NFS挂载设置

544 阅读1分钟

NFS挂载设置

服务端安装

  1. 安装软件
# yum install nfs-utils

只安装 nfs-utils 即可,rpcbind 属于它的依赖,也会安装上。

  1. 服务端配置

    设置 NFS 服务开机启动

    # systemctl enable rpcbind
    # systemctl enable nfs
    
  2. 启动 NFS 服务

    # systemctl start rpcbind
    # systemctl start nfs
    
  3. 若使用防火墙,需要设置防火墙开启端口

    防火墙需要打开 rpc-bind 和 nfs 的服务

    # firewall-cmd --zone=public --permanent --add-service=rpc-bind
    # firewall-cmd --zone=public --permanent --add-service=mountd
    # firewall-cmd --zone=public --permanent --add-service=nfs
    # firewall-cmd --reload
    
  4. 配置共享目录

    /etc/exports 中添加如下信息:

    # vim /etc/exports
    /data/     192.168.0.0/24(rw,sync,no_root_squash,no_all_squash)
    

    备注:exports中参数说明如下

    /data: 共享目录位置。

    192.168.0.0/24: 客户端 IP 范围,* 代表所有,即没有限制。

    rw: 权限设置,可读可写。

    sync: 同步共享目录。

    no_root_squash: 可以使用 root 授权。

    no_all_squash: 可以使用普通用户授权。

  5. 重启 NFS 服务

    # systemctl restart nfs
    

    检查本地的共享目录

    # showmount -e localhost
    Export list for localhost:      /data 192.168.0.0/24
    

    备注:修改了/etc/exports之后,也可以用如下命令使之生效

    # exportfs -a 
    

客户端安装

  1. 客户端安装

    # yum install nfs-utils -y
    
  2. 客户端配置

    设置 rpcbind 服务的开机启动

    # systemctl enable rpcbind
    

    启动NFS 服务

    # systemctl start rpcbind
    
  3. 客户端配置

    执行如下命令挂载

    # mount -t nfs 192.168.0.101:/data /data
    

    挂载之后,可以使用df命令查看挂载情况

    # df -h
    192.168.0.101:/data  498G   42G  436G   9% /data
    
  4. 客户端自动挂载

    设置fstab文件,客户端启动自动挂载

    vim /etc/fstab
    192.168.0.101:/data      /data                   nfs     defaults        0 0
    

    由于修改了 /etc/fstab,需要重新加载 systemctl

    # systemctl daemon-reload
    

常见问题解决

特殊情况下,没法取消挂载,强制取消挂载

# umount -f -l /data