【整理】Linux中fstab的语法和参数含义和mount NFS时相关参数含义

【背景】

折腾:

【已解决】在远程Ubuntu服务器中开通NFS服务供别人访问服务器上的文件

期间,对于参考文档,写了下面的配置:

121.41.120.185:/home/share/image /root/nfs_client_root/ nfs auto,noatime,nolock,bg,nfsvers=4,intr,tcp,actimeo=1800 0 0

需要搞懂fstab的格式,语法。

【折腾过程】

1.搜:

fstab 语法

man fstab

man fstab bg

man fstab nolock

参考:

linux fstab 语法 – rajaruan – 51CTO技术博客

/etc/fstab Mount Process

fstab(5) – Linux manual page

nfs(5) – nfs, nfs – nfs fstab format and options – man 5 nfs

/etc/fstab Mount Process

NFS Client Configuration Files

fstab的格式:

file_system

Is the remote server directory to be mounted.

directory

Is the mount point on the client where the directory is attached.

type

Is the file system type. This can be nfs2 for NFS2 mounting, nfs3 for the NFS3 protocol, and nfs and nfs3pref for mounts that attempt the NFS3 protocol, but fall back to nfs2 if the attempt fails.

options

Is mount options (see Section 4.6.2.1 in this section).

frequency

Is always set to zero (0) for NFS and CacheFS entries.

pass

Is always set to zero (0) for NFS and CacheFS entries.

其中那些参数的含义是:

defaults  use default options: rw, suid, dev, exec, auto, nouser,
                     and async.



acregmin=n

The minimum time (in seconds) that the NFS client caches attributes of a regular file before it requests fresh attribute information from a server. If this option is not specified, the NFS client uses a 3-second minimum.

acregmax=n

The maximum time (in seconds) that the NFS client caches attributes of a regular file before it requests fresh attribute information from a server. If this option is not specified, the NFS client uses a 60-second maximum.

acdirmin=n

The minimum time (in seconds) that the NFS client caches attributes of a directory before it requests fresh attribute information from a server. If this option is not specified, the NFS client uses a 30-second minimum.

acdirmax=n

The maximum time (in seconds) that the NFS client caches attributes of a directory before it requests fresh attribute information from a server. If this option is not specified, the NFS client uses a 60-second maximum.

actimeo=n

Using actimeo sets all of acregmin, acregmax, acdirmin, and acdirmax to the same value. If this option is not specified, the NFS client uses the defaults for each of these options listed above.

atime / noatime / relatime / strictatime (Linux-specific)

                在Unix中,每个文件都有记录上次访问文件时间(atime的),修改时间(mtime),和changed time(ctime)。atime是指每个文件被读取的时间,这个功能经常受到批评,因为这样会造成性能下降,并增加磨损。然而,一些应用程序和用户会使用到atime,因此需要指定选项,atime?noatime?(in Linux) relatime (update atime if older than mtime)?Linux内核版本是2.6.29,默认是atime;2.6.30则默认是relatime。

       bg                 (background) Mounting is performed as a background task if the first att empt fails. The default setting is off.

       nfsvers=n      Use  an  alternate RPC version number to contact the NFS

                      daemon on the remote host.  This option  is  useful  for

                      hosts  that  can  run multiple NFS servers.  The default

                      value is version 2.

       intr           If  an  NFS file operation has a major timeout and it is

                      hard mounted, then allow signals to  interupt  the  file

                      operation  and  cause  it to return EINTR to the calling

                      program.  The default is to not allow file operations to

                      be interrupted.

       tcp            Mount  the NFS filesystem using the TCP protocol instead 

                      of the default UDP protocol.  Many NFS servers only sup-

                      port UDP.

      actimeo=n      Using  actimeo sets all of acregmin, acregmax, acdirmin,

                      and acdirmax to the same value.   There  is  no  default

                      value.

 

  • hard or soft — Specifies whether the program using a file via an NFS connection should stop and wait (hard) for the server to come back online if the host serving the exported file system is unavailable, or if it should report an error (soft).

    If hard is specified, the user cannot terminate the process waiting for the NFS communication to resume unless the intr option is also specified.

    If soft, is specified, the user can set an additional timeo=<value> option, where<value> specifies the number of seconds to pass before the error is reported.

  • intr — Allows NFS requests to be interrupted if the server goes down or cannot be reached.

  • nfsvers=2 or nfsvers=3 — Specifies which version of the NFS protocol to use.

  • nolock — Disables file locking. This setting is occasionally required when connecting to older NFS servers.

  • noexec — Prevents execution of binaries on mounted file systems. This is useful if the system is mounting a non-Linux file system via NFS containing incompatible binaries.

  • nosuid — Disables set-user-identifier or set-group-identifier bits. This prevents remote users from gaining higher privileges by running a setuid program.

  • rsize=8192 and wsize=8192 — These settings speed up NFS communication for reads (rsize) and writes (wsize) by setting a larger data block size, in bytes, to be transferred at one time. Be careful when changing these values; some older Linux kernels and network cards do not work well with larger block sizes.

  • tcp — Specifies for the NFS mount to use the TCP protocol instead of UDP.

 

【总结】

上述的fstab中的配置:

121.41.120.185:/home/share/image /root/nfs_client_root/ nfs auto,noatime,nolock,bg,nfsvers=4,intr,tcp,actimeo=1800 0 0

的含义是:

  • 121.41.120.185:/home/share/image
    • 是目标NFS服务器的IP(或域名)和NFS共享的路径
  • /root/nfs_client_root/
    • 是NFS客户端要mount挂载的路径(一般挂载到/mnt下面某个路径,此处只是测试,就随便挂了)
  • nfs
    • 表示挂载的文件系统类型时NFS
  • 各个参数的含义:
    • auto:自动挂载;
    • noatime:不要添加access time==上次访问文件时间;
    • nolock:禁止文件加锁。有时候访问旧的NFS服务器需要此参数。
    • bg:挂载作为后台服务去运行,如果第一次挂载失败了。默认是off的。
    • nfsvers=4:指定NFS协议的版本。
    • intr:允许NFS请求被中断,如果服务器挂了或连不上
    • tcp:指定NFS(不适用默认的UDP而改用)TCP
    • actimeo=1800:acregmin==acregmax==acdirmin====acdirmax,都设置为1800s=30分钟,即文件缓存时间为30分钟
  • 0
    • 不需要NFS的CacheFS?
  • 0
    • 不需要NFS的CacheFS?


    发表评论

    电子邮件地址不会被公开。 必填项已用*标注

    无觅相关文章插件,快速提升流量