配置nfs的方法

以下步骤在centos8 下进行

安装

依赖的安装包 nfs-utils

配置

配置/etc/exports 文件

export host1(options1) host2(options2) host3(options3)

分为3个部分, 这里可以看出可以针对主机ip的不同,配置不同的选项

  1. 暴露的文件目录
  2. host主机地址,或者掩码。如果想任意客户端都能连接,则直接设置为*
  3. 选项,一般为(rw,sync,no_root_squash)

注意掩码会校验客户端的ip,即如果不能匹配,则拒绝连接

启动

要启动两个服务,nfs-server rpcbind

防火墙配置

通过firewalld-cmd 允许 mountd 和 nfs服务, 以及重载配置

firewalld-cmd --permanent --add-service mountd
firewalld-cmd --permanent --add-service nfs
firewalld-cmd --reload

备注

  1. 修改exports 配置后,可以执行 exportfs -r 或者 systemctl reload nfs-server。 但直接restart nfs-server 是不推荐的
  2. 执行exportfs -av 可以查看本机提供的nfs服务
  3. 通过showmount 来查看特定主机的nfs 服务,如下命令查看 192.168.122.199 主机提供的可挂载目录,另外showmount 依赖mountd服务
       [root@servera tester]# showmount -e 192.168.122.199 
       Export list for 192.168.122.199:
       /root/nfs *
    
原文地址:https://www.cnblogs.com/hustcpp/p/12938245.html