Skip to content

搭建nfs服务器

centOS7centOS8搭建nfs服务器

http://blog.huatai.me/2014/10/14/CentOS-7-NFS-Server-and-Client-Setup/https://www.howtoforge.com/tutorial/setting-up-an-nfs-server-and-client-on-centos-7/

  • 关闭selinuxfirewalld

  • 安装nfs-server

    bash
    yum install nfs-utils -y
    systemctl start nfs-server
    systemctl enable nfs-server
  • 配置nfs共享/data文件夹,编辑/etc/exports文件内容如下:

    bash
    /data *(rw,sync,no_root_squash,no_subtree_check)
  • 使nfs-server export配置立即生效

    bash
    exportfs -a
  • 显示/data文件夹是否被nfs export

    bash
    showmount -e
  • 客户端mount nfs-server测试,挂载nfs-server /data文件夹到本地/opt/temp文件夹

    nfs挂载参数https://help.aliyun.com/zh/nas/user-guide/mount-an-nfs-file-system-on-a-linux-ecs-instance?spm=a2c4g.11186623.help-menu-27516.d_2_0_2_1_0.4c1cda29aX7laN

    bash
    mkdir /opt/temp
    mount -t nfs -o vers=3,nolock,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 192.168.235.191:/data /opt/temp
    • vers=3:使用NFS v3协议挂载文件系统。

    • rsize:定义数据块的大小,用于客户端与文件系统之间读取数据。建议值:1048576

    • wsize:定义数据块的大小,用于客户端与文件系统之间写入数据。建议值:1048576

      如果您需要更改IO大小参数(rsizewsize),建议您尽可能使用最大值(1048576),以避免性能下降。

    • hard:在文件存储NAS暂时不可用的情况下,使用文件系统上某个文件的本地应用程序时会停止并等待至该文件系统恢复在线状态。建议启用该参数。

    • timeo:指定时长,单位为0.1秒,即NFS客户端在重试向文件系统发送请求之前等待响应的时间。建议值:60060秒)。

      如果您必须更改超时参数(timeo),建议您使用150或更大的值。该timeo参数的单位为0.1秒,因此150表示的时间为15秒。

    • retransNFS客户端重试请求的次数。建议值:2

    • noresvport:在网络重连时使用新的TCP端口,保障在网络发生故障恢复时不会中断连接。建议启用该参数。

  • 客户端主机执行命令显示所有mount文件系统

    bash
    mount
  • 取消nfs挂载

    bash
    umount /opt/temp