NFS: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
(Phase 0.4: Expand NFS)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
NFS - "Network File System" - developed by Sun MicroSystem is the most widely used HPC to share filesystem. It is very easy to set up and performs reasonably well for small to medium clusters as primary storage. You can even use it for larger clusters too.
= NFS =


along with [[Samba|SMB]], NFS serves essentially the same purpose as SMB to access files systems over a network as if they were local.
{{Status
|status=Draft
|owner=Knowledge Agent
|last_update=2026-07-15
|review=Pending
}}


One of the most common questions about NFS configuration is how to tune it for performance and management and what options are typically used. So it is important to know them NFS export and mount options especially when you are facing a performance issue or a functional issue with the NFS mount over network.
{{TOC}}
 
== Overview ==
 
NFS(Network File System)는 Sun Microsystems에서 개발한 네트워크 파일 공유 시스템입니다. SMB/SMB와 함께 네트워크 상의 파일 시스템을 로컬 파일 시스템처럼 접근할 수 있게 해주는 가장 널리 사용되는 HPC 스토리지 솔루션입니다.
 
=== Summary ===
 
* 무엇인가? — 네트워크 파일 공유 프로토콜 (TCP/IP 기반)
* 왜 필요한가? — 중앙 집중식 스토리지, 다수 클라이언트 공유, 간단한 설정
* 언제 사용하는가? — HPC 클러스터, 파일 서버, 스토리지 공유
 
 
== Purpose ==
 
이 문서가 존재하는 이유
 
* Goal: NFS 버전, 서버/클라이언트 설정, 마운트 옵션, 성능 튜닝 제공
* Scope: NFS v2~v4.2, export/mount 옵션, 성능 최적화, 서비스 의존성
* Non-goals: NFS 커널 패치 개발, NFSv4.3+ 최신 기능은 별도 문서
 
 
== Key Concepts ==


== NFS version<ref>https://en.wikipedia.org/wiki/Network_File_System</ref> ==
{| class="wikitable"
{| class="wikitable"
|+
! Concept
!version
! Description
!Description
! Related
|-
|-
|Version 2
| NFSv4
|[https://datatracker.ietf.org/doc/html/rfc1094 RFC 1094], March 1989
| 상태(Stateful) 기반 NFS — 단일 포트 2049
only allowed access to the first 2 GB of a file. The client made the decision about whether the user could access the file or not. This version supported UDP only, and it limited write operations to 8 kbytes. Ugh. It was a nice start, though.
| [[NFS]]
|-
|-
|Version 3
| pNFS
|[https://datatracker.ietf.org/doc/html/rfc1813 RFC 1813], June 1995
| Parallel NFS — 다수 서버 스트라이핑
supported much larger files. The client could ask the server to make the access decision — although it didn't have to and so we still had to fully trust all client hosts. NFSv3 over UDP could use up to 56 kbyte transactions. There was now support for NFS over TCP, although client implementations varied quite a bit as to details with associated compatibility issues
| [[NFS]]
|-
|-
|Version 4
| exportfs
|[https://datatracker.ietf.org/doc/html/rfc3010 RFC 3010], December 2000; revised in <nowiki>RFC 3530</nowiki>, April 2003 and again in <nowiki>RFC 7530</nowiki>, March 2015
| NFS 공유 내보내기 명령어
added statefulness, so an NFSv4 client could directly inform the server about its locking, reading, writing the file, and so on. All the NFS application protocols — mount, stat, ACL checking, and the NFS file service itself, run over a single network protocol always running on a predictable TCP port 2049. There is no longer any need for an RPC port mapper to start first, or for separate mount and file locking daemons to run independently. Access control is now done by user name, not possibly inconsistent UID and GID as before, and security could be further enhanced with the use of Kerberos.
| [[NFS]]
|-
|-
|Version 4.1
| mount options
|[https://datatracker.ietf.org/doc/html/rfc5661 RFC 5661], January 2010; revised in <nowiki>RFC 8881</nowiki>, August 2020
| NFS 클라이언트 마운트 옵션
added Parallel NFS (or pNFS), which can stripe data across multiple NFS servers. You can do block-level access and use NFS v4.1 much like Fibre Channel and iSCSI, and object access is meant to be analogous to AWS S3. NFS v4.1 added some performance enhancements Perhaps more importantly to many current users, NFS v4.1 on Linux better inter-operates with non-Linux NFS servers and clients. Specifically, mounting NFS from Windows servers using Kerberos V5.
| [[NFS]]
|-
|-
|Version 4.2
| rsize/wsize
|RFC 7862
| 읽기/쓰기 블록 크기
| [[NFS]]
|-
| nconnect
| 다중 TCP 연결 (커널 5.3+)
| [[NFS]]
|-
| FS-Cache
| NFS 클라이언트 로컬 캐싱
| [[NFS]]
|-
| root_squash
| 원격 루트 권한 제한
| [[NFS]]
|}
|}


== Basic command ==
 
{| class="wikitable sortable"
== Architecture ==
|+
 
!Commands
NFS는 클라이언트-서버 아키텍처로 구성됩니다:
!Description
 
!Command on
<syntaxhighlight lang="mermaid">
graph TD
    A[NFS Server] --> B[/etc/exports]
    A --> C[nfs-server.service]
    A --> D[nfs-mountd]
    A --> E[nfs-idmapd]
    B --> F[Shared Directory]
    G[NFS Client] --> H[mount -t nfs]
    G --> I[/etc/fstab]
    H --> J[NFS Server:2049]
    I --> J
</syntaxhighlight>
 
 
== Workflow ==
 
{| class="wikitable"
! Stage
! Input
! Output
|-
|-
|# exportfs -r 
| Server Setup
|Re-export your shares
| /etc/exports
|Server
| NFS Share
|-
|-
|# exportfs -a 
| Client Mount
|Export your shares
| mount -t nfs
|Server
| NFS Mount Point
|-
|-
|# exportfs -v
| Performance Tuning
|Verify the NFS Share permissions
| rsize/wsize/timeo
|Server
| Optimized NFS
|-
|-
|$nfsstat -m
| Monitoring
|'''Verify Current NFS Mount Options''' 
| nfsstat / /proc/net/rpc/nfsd
|Client
| Performance Data
|}
|}


== NFS export on Server<ref>https://www.golinuxcloud.com/unix-linux-nfs-mount-options-example/</ref> <ref>https://linux.die.net/man/5/exports</ref> ==
NFS exports options are the permissions '''that is applied on NFS Server''' when we create a NFS Share under <code>/etc/exports</code>


Here are most common(important) options that administrator must understand, full list of options are available on the [https://man7.org/linux/man-pages/man5/exports.5.html man pages]
== Detailed Explanation ==
 
=== NFS 버전 ===
 
{| class="wikitable"
{| class="wikitable"
|+
! Version
!Export Options
! Description
!NFS Server
! Key Features
!Default
|-
| NFSv2
| RFC 1094 (1989)
| UDP만 지원, 2GB 파일 제한, 8KB 쓰기 제한
|-
|-
|<code>secure/insecure</code>
| NFSv3
|'''NFSv4 only uses port 2049''' while to check the list of ports used by '''NFSv3 use in server port'''
| RFC 1813 (1995)
With <code>secure</code> the port number from which the client requests a mount must be lower than 1024.
| 대용량 파일 지원, TCP 지원, 56KB 트랜잭션
To allow client any available free port use <code>insecure</code> in the NFS share
|<code>secure</code>
|-
|-
|rw/ro
| NFSv4
|'''ro''' means '''read-only''' access to the NFS Share
| RFC 3010/3530/7530
 
| 상태(Stateful), 단일 포트 2049, Kerberos 보안
'''rw''' means '''read write''' access to the NFS Share
|-
|rw
| NFSv4.1
| RFC 5661 (2010)
| pNFS(Parallel NFS), 블록/객체 접근, Windows Kerberos
|-
|-
|root_squash/no_root_squash
| NFSv4.2
|'''squash literally means to squash (destroy) the power of the remote root user.'''
| RFC 7862
| 향상된 성능 및 기능
|}


=== NFS 서버 설정 ===


<code>root_squash</code> prevents remote root users from having superuser (root) privileges on remote NFS-mounted volumes.
==== /etc/exports 옵션 ====


<code>no_root_squash</code> allows root user on the NFS client host to access the NFS-mounted directory with the same rights and privileges that the superuser would normally have
{| class="wikitable"
|root_squash
! Export Options
! NFS Server
! Default
|-
|-
|all_quash/no_all_squash
| secure/insecure
|<code>all_squash</code> will map all User IDs (UIDs) and group IDs (GIDs) to the anonymous user. <code>all_squash</code> is useful for NFS-exported public FTP directories, news spool directories
| NFSv4는 포트 2049만 사용. NFSv3는 서버 포트 사용. secure: 클라이언트 포트 < 1024. insecure: 모든 포트 허용.
|<code>no_all_squash</code>
| secure
|-
|-
|sync/aysnc
| rw/ro
|<code>sync</code> reply to requests are done only after the changes have been committed to stable storage
| rw: 읽기/쓰기. ro: 읽기 전용.
 
| rw
<code>async</code> allows the NFS server to violate the NFS protocol and reply to requests before any changes made by that request have been committed to stable storage
|-
 
| root_squash/no_root_squash
Using <code>aysnc</code> option usually improves performance, but at the cost that an unclean server restart (i.e. a crash) '''can cause data to be lost or corrupted'''
| root_squash: 원격 루트 권한 제한. no_root_squash: 원격 루트 전체 권한 허용.
|sync
| root_squash
|-
| all_squash/no_all_squash
| all_squash: 모든 UID/GID를 anonymous로 매핑.
| no_all_squash
|-
| sync/async
| sync: 변경사항 저장 후 응답. async: 저장 전 응답 (성능 ↑, 데이터 손실 위험).
| sync
|-
|-
|insecure_locks<ref>https://www.stigviewer.com/stig/red_hat_enterprise_linux_6/2016-07-22/finding/V-38677</ref>
| insecure_locks
|By default the NFS server requires secure file-lock requests, which require credentials from the client in order to lock a file. Most NFS clients send credentials with file lock requests, however, there are a few clients that do not send credentials when requesting a file-lock, allowing the client to only be able to lock world-readable files.
| 파일 잠금 시 클라이언트 자격 증명 불필요 (보안 위험).
To get around this, the "insecure_locks" option can be used so these clients can access the desired export. This poses a security risk by potentially allowing the client access to data for which it does not have authorization. Remove any instances of the "insecure_locks" option from the file "/etc/exports".
|
|
|}
|}


=== Check exports list and options ===
==== export 명령어 ====
 
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
#with following set
# 공유 내보내기
$ cat /etc/exports
$ exportfs -a
/nas * (rw,sync,no_subtree_check)
 
/nas 192.168.1.0/24 (rw,sync,no_subtree_check,no_root_squash,insecure)
# 공유 다시 내보내기
$ exportfs -r
 
# 공유 권한 확인
$ exportfs -v


# 현재 NFS 서비스 포트 확인
$ rpcinfo -p | grep -i nfs
$ rpcinfo -p | grep -i nfs
    100003    3  tcp  2049  nfs
    100003    4  tcp  2049  nfs
    100003    3  udp  2049  nfs
   
# detailed export status with default export options
$ sudo exportfs -v
/nas  <world>(ro,wdelay,root_squash,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)
</syntaxhighlight>
</syntaxhighlight>


=== NFS exports examples ===
==== export 예시 ====
 
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
/etc/exports file
# /etc/exports
 
/srv/nfs4        192.168.33.0/24(rw,sync,no_subtree_check,crossmnt,fsid=0)
/srv/nfs4        192.168.33.0/24(rw,sync,no_subtree_check,crossmnt,fsid=0)
/srv/nfs4/backups 192.168.33.0/24(ro,sync,no_subtree_check) 192.168.33.3(rw,sync,no_subtree_check)
/srv/nfs4/backups 192.168.33.0/24(ro,sync,no_subtree_check) 192.168.33.3(rw,sync,no_subtree_check)
Line 130: Line 203:
</syntaxhighlight>
</syntaxhighlight>


== Ubuntu NFS service dependency<ref>https://ubuntu.com/server/docs/service-nfs</ref> ==
=== Ubuntu NFS 서비스 의존성 ===
 
{| class="wikitable"
{| class="wikitable"
!Service
! Service
!nfs-utils.service
! nfs-utils.service
!nfs-server.service
! nfs-server.service
!config file (22.04)
! Config File (22.04)
!config file (< 22.04) /etc/default/nfs-*
! Config File (< 22.04)
|-
|-
|nfs-blkmap
| nfs-blkmap
|PartOf
| PartOf
|
|
|nfs.conf
| nfs.conf
|
|
|-
|-
|nfs-mountd
| nfs-mountd
|
|
|BindsTo
| BindsTo
|nfs.conf
| nfs.conf
|nfs-kernel-server
| nfs-[[kernel]]-server
|-
|-
|nfsdcld
| nfsdcld
|
|
|
|
|
|
|
|
|-
|-
|nfs-idmapd
| nfs-idmapd
|
|
|BindsTo
| BindsTo
|nfs.conf, idmapd.conf
| nfs.conf, idmapd.conf
|idmapd.conf
| idmapd.conf
|-
|-
|rpc-gssd
| rpc-gssd
|PartOf
| PartOf
|
|
|nfs.conf
| nfs.conf
|
|
|-
|-
|rpc-statd
| rpc-statd
|PartOf
| PartOf
|
|
|nfs.conf
| nfs.conf
|nfs-common
| nfs-common
|-
|-
|rpc-svcgssd
| rpc-svcgssd
|PartOf
| PartOf
|BindsTo
| BindsTo
|nfs.conf
| nfs.conf
|nfs-kernel-server
| nfs-kernel-server
|}
|}


== NFS Client mount options<ref>https://www.thegeekdiary.com/common-nfs-mount-options-in-linux/</ref> ==
=== NFS 클라이언트 마운트 옵션 ===
<nowiki>#</nowiki> mount -t nfs -o [options] remote:/nfs /mount


{| class="wikitable"
{| class="wikitable"
|+
! Mount Options
!Mount Options
! NFS Client
!NFS Client
! Default
!Default  
! Notes
!Notes
|-
|-
|'''nfsvers='''''n or'' vers=n
| nfsvers/vers=n
|The version of the NFS protocol to use. By default, the local NFS client will attempt to mount the file system using NFS version 3. If the NFS server does not [[support]] version 3, the file system will be mounted using version 2.
| 사용할 NFS 버전. 기본값 3.
If you know that the NFS server does not support version 3, specify vers=2, and you will save time during the mount, because the client will not attempt to use version 3 before using version 2
| 3, 4
|3 and 4
|
|[[NFS tips and tricks#Check NFS server supported version]]
|-
|-
|rw (read/write) / ro (read-only)
| rw/ro
|
| rw: 읽기/쓰기. ro: 읽기 전용.
* Use rw for data that users need to modify. In order for you to mount a directory read/write, the NFS server must export it read/write.
| rw
* Use ro for data you do not want users to change. A directory that is automounted from several servers should be read-only, to keep versions identical on all servers.
|
|rw.
|
|-
|-
|suid / nosuid
| suid/nosuid
|
| suid: setuid 프로그램 허용. nosuid: setuid 차단.
* Specify suid if you want to allow mounted programs that have setuid permission to run with the permissions of their owners, regardless of who starts them. If a program with setuid permission is owned by root, it will run with root permissions, regardless of who starts it.
| suid
* Specify nosuid to protect your system against setuid programs that may run as root and damage your system.
|
|suid
|
|-
|-
|hard / soft
| hard/soft
|
| hard: 서버 다운 시 재시도 (프로세스 대기). soft: 재시도 후 에러 반환.
* Specify hard if users will be writing to the mounted directory or running programs located in it. When NFS tries to access a hard-mounted directory, it keeps trying until it succeeds or someone interrupts its attempts. If the server goes down, any processes using the mounted directory hang until the server comes back up and then continue processing without errors. Interruptible hard mounts may be interrupted with CTRL-C or kill (see the intr option, later).
| hard
* Specify soft if the server is unreliable and you want to prevent systems from hanging when the server is down. When NFS tries to access a soft-mounted directory, it gives up and returns an error message after trying retrans times. Any processes using the mounted directory will return errors if the server goes down.
|
|hard
|
|-
|-
|<code>nconnect=<value></code>
| nconnect=value
|NFS-over-TCP mount for one or more NFS shares from an individual NFS server, the traditional behavior is that all those mounts share one TCP connection if they are using the same NFS protocol version.  In cases of high NFS work load at the client, this connection sharing may result in lower performance or unnecessary bottlenecks.<ref>https://www.suse.com/support/kb/doc/?id=000019933</ref>
| 다중 TCP 연결 (커널 5.3+). 최대 16.
|16
| 16
|In [[Linux]] kernel 5.3 (and higher), the <code>nconnect</code> option allows multiple TCP connections for a single NFS mount.
| 성능 향상
example<ref>https://medium.com/@emilypotyraj/use-nconnect-to-effortlessly-increase-nfs-performance-4ceb46c64089</ref>,
|-
 
| intr/nointr
mount -t nfs -o ro,nconnect=16 198.18.0.100:/datasets /mnt/datasets
| intr: NFS 요청 중단 가능. nointr: 중단 불가.
| intr
| Linux 2.6.25+ deprecated
|-
| fg/bg
| fg: 부팅 필수 마운트. bg: 백그라운드 마운트.
| fg
| —
|-
| devs/nodevs
| devs: 장치 파일 허용. nodevs: 장치 파일 차단.
| devs
| —
|-
|-
|intr / nointr
| timeo=n
|
| 재전송 대기 시간 (0.1초 단위). 최대 30 (3초).
* Specify intr if users are not likely to damage critical data by manually interrupting an NFS request. If a hard mount is interruptible, a user may press [CTRL]-C or issue the kill command to interrupt an NFS mount that is hanging indefinitely because a server is down.
| 0.7
* Specify nointr if users might damage critical data by manually interrupting an NFS request, and you would rather have the system hang while the server is down than risk losing data between the client and the server.
|
|intr
|In Linux kernel 2.6.25 (and higher), the <code>intr</code> and <code>nointr</code> mount options are deprecated. If you use the <code>hard</code> option on modern Linux kernels, you must use the <code>kill -9</code> <code>(SIGKILL)</code> command to interrupt a stuck NFS mount.
|-
|-
|fg (foreground) / bg (background)
| retrans=n
|
| 재전송 횟수.
* Specify fg for directories that are necessary for the client machine to boot or operate correctly. If a foreground mount fails, it is retried again in the foreground until it succeeds or is interrupted. All automounted directories are mounted in the foreground; you cannot specify the bg option with automounted directories.
| 4
* Specify bg for mounting directories that are not necessary for the client to boot or operate correctly. Background mounts that fail are re-tried in the background, allowing the mount process to consider the mount complete and go on to the next one. If you have two machines configured to mount directories from each other, configure the mounts on one of the machines as background mounts. That way, if both systems try to boot at once, they will not become deadlocked, each waiting to mount directories from the other. The bg option cannot be used with automounted directories.
|
|fg
|
|-
|-
|devs / nodevs
| retry=n
|
| 마운트 재시도 횟수.
* Specify devs if you are mounting device files from a server whose device files will work correctly on the client. The devs option allows you to use NFS-mounted device files to read and write to devices from the NFS client. It is useful for maintaining a standard, centralized set of device files, if all your systems are configured similarly.
| 1
* Specify nodevs if device files mounted from a server will not work correctly for reading and writing to devices on the NFS client. The nodevs option generates an error if a process on the NFS client tries to read or write to an NFS-mounted device file.
|
|devs
|
|-
|-
|timeo=n
| rsize=n
|The ''timeo'' (timeout) option is the amount of time the NFS client waits on the NFS server before retransmitting a packet (no ACK received). The value for ''timeo'' is given in tenths of a second, so if ''timeo'' is ''5'', the NFS client will wait 0.5 seconds before retransmitting
| 읽기 블록 크기.
The timeout, in tenths of a second, for NFS requests (read and write requests to mounted directories). If an NFS request times out, this timeout value is doubled, and the request is retransmitted. After the NFS request has been retransmitted the number of times specified by the retrans option, a soft mount returns an error, and a hard mount retries the request. The maximum timeo value is 30 (3 seconds).
| 8192
 
|
Try doubling the timeo value if you see several servers not responding messages within a few minutes. This can happen because you are mounting directories across a gateway, because your server is slow, or because your network is busy with heavy traffic.
|The default is ''0.7'' (0.07 seconds)
|
|-
|-
|retrans=n
| wsize=n
|''retrans'', specifies the number of tries the NFS client will make to retransmit the packet. If the value is ''5'', the client resends the RPC packet five times, waiting ''timeo'' seconds between tries. If, after the last attempt, the NFS server does not respond, you get a message ''Server not responding''.
| 쓰기 블록 크기.
The number of times an NFS request (a read or write request to a mounted directory) is retransmitted after it times out. If the request does not succeed after n retransmissions, a soft mount returns an error, and a hard mount retries the request.
| 8192
Increase the retrans value for a directory that is soft-mounted from a server that has frequent, short periods of downtime. This gives the server sufficient time to recover, so the soft mount does not return an error
|
|4
|
|-
|-
|retry=n
| noac
|The number of times the NFS client attempts to mount a directory after the first attempt fails. If you specify intr, you can interrupt the mount before n retries. However, if you specify nointr, you must wait until n retries have been made, until the mount succeeds, or until you reboot the system.
| 속성 캐싱 비활성화.
If mounts are failing because your server is very busy, increasing the retry value may fix the problem
|
|1
|
|
|-
|-
|rsize=n
| actimeo=n
| rowspan="2" |The number of bytes the NFS client requests from the NFS server in a single read request.
| 모든 캐싱 타임아웃 설정.
If packets are being dropped between the client and the server, decrease rsize to 4096 or 2048. To find out whether packets are being dropped, issue the “nfsstat -rc” command. If the timeout and retrans values returned by this command are high, but the badxid number is close to zero, then packets are being dropped somewhere in the network.
|
|8192
|
| rowspan="2" |if nfsstat -cr reports a significant number (> 5% of the total) of both <samp>timeout</samp>s and <samp>badxid</samp>s, you could increase the '''timeo''' parameter<ref>https://sites.ualberta.ca/dept/chemeng/AIX-43/share/man/info/C/a_doc_lib/aixbman/prftungd/nfstuning.htm</ref>
|-
|-
|wsize=n
| lock/nolock
|8192
| NLM 파일 잠금 사용 여부.
| lock
| —
|-
|-
|O (Overlay mount)
| local_lock=mechanism
|Allows the file system to be mounted over an existing mount point, making the underlying file system inaccessible. If you attempt to mount a file system over an existing mount point without the -O option, the mount will fail with the error device busy.
| 로컬 잠금 방식 (all/flock/posix/none).
'''Caution''': Using the -O mount option can put your system in a confusing state. The -O option allows you to hide local data under an NFS mount point without receiving any warning. Local data hidden beneath an NFS mount point will not be backed up during regular system backups.
|
| 커널 2.6.37+
|}


On HP-UX, the -O option is valid only for NFS-mounted file systems. For this reason, if you specify the -O option, you must also specify the -F nfs option to the mount command or the nfs file system type in the [[Fstab|/etc/fstab]] file.
=== NFS 성능 최적화 ===
|No Default value
 
|
{| class="wikitable"
! Tuning Options
! Target
! Description
! Recommendation
|-
|-
|remount
| sync/async
|If the file system is mounted read-only, this option remounts it read/write. This allows you to change the access permissions from read-only to read/write without forcing everyone to leave the mounted directory or killing all processes using it
| 클라이언트
|No Default value
| mount 또는 /etc/fstab에서 설정
|
|
|-
|-
|noac
| nfsd 수
|If specified, this option prevents the NFS client from caching attributes for the mounted directory.
| 서버
Specify noac for a directory that will be used frequently by many NFS clients. The noac option ensures that the file and directory attributes on the server are up to date, because no changes are cached on the clients. However, if many NFS clients using the same NFS server all disable attribute caching, the server may become overloaded with attribute requests and updates. You can also use the actimeo option to set all the caching timeouts to a small number of seconds, like 1 or 3.
| /proc/net/rpc/nfsd로 스레드 부하 확인
 
| 16C/128GB: 256, 8C/64GB: 64
If you specify noac, do not specify the other caching options.
|-
|No Default value
| rsize/wsize
|
| 클라이언트
| 읽기/쓰기 블록 크기
| /etc/fstab에서 rsize=131072, wsize=131072
|-
| timeo/retrans
| 클라이언트
| 네트워크 혼잡 시 재전송 설정
| timeo=900, retrans=5
|-
| FS-Cache
| 클라이언트
| 로컬 스토리지에 NFS 읽기 캐싱 (-o fsc)
| 읽기 작업에 효과적
|-
| noatime/nodiratime
| 클라이언트
| inode 접근 시간 업데이트 방지
| 성능 향상
|-
|-
|nocto
| System Memory
|If specified, this option suppresses fresh attributes when opening a file.
| 서버
Specify nocto for a file or directory that never changes, to decrease the load on your network
| async 모드 시 메모리 확보 필요
|No Default value
| 가능한 많은 메모리
|
|-
|-
|acdirmax=n
| Network MTU
|The maximum number of seconds a directory’s attributes are cached on the NFS client. When this timeout period expires, the client flushes its attribute cache, and if the attributes have changed, the client sends them to the NFS server.
| 서버+클라이언트
For a directory that rarely changes or that is owned and modified by only one user, like a user’s home directory, you can decrease the load on your network by setting acdirmax=120 or higher
| MTU 1500 → 9000 (Jumbo Packet)
|60
| 대역폭 33% 증가
|
|-
|-
|acdirmin=n
| TCP tuning
|The minimum number of seconds a directory’s attributes are cached on the NFS client. If the directory is modified before this timeout expires, the timeout period is extended by acdirmin seconds.
| 서버
For a directory that rarely changes or that is owned and modified by only one user, like a user’s home directory, you can decrease the load on your network by setting acdirmin=60 or higher
| net.core.rmem/wmem 설정
|30
| 262144 (256KiB)
|
|-
|-
|acregmax=n
| subtree_check
|The maximum number of seconds a file’s attributes are cached on the NFS client. When this timeout period expires, the client flushes its attribute cache, and if the attributes have changed, the client sends them to the NFS server.
| 서버
For a file that rarely changes or that is owned and modified by only one user, like a file in a user’s home directory, you can decrease the load on your network by setting acregmax=120 or higher
| export된 폴더 내 파일 확인
|60
| 보안 ↑, 성능 ↓
|
|-
|-
|actimeo=n
| root_squash
|Setting actimeo to n seconds is equivalent to setting acdirmax, acdirmin, acregmax, and acregmin to n seconds.
| 서버
Set actimeo=1 or actimeo=3 for a directory that is used and modified frequently by many NFS clients. This ensures that the file and directory attributes are kept reasonably up to date, even if they are changed frequently from various client locations.
| 원격 루트 권한 제한
| 보안 ↑
|}


Set actimeo=120 or higher for a directory that rarely or never changes.
=== NFS v4.1/v4.2 권장 ===


If you set the actimeo value, do not set the acdirmax, acdirmin, acregmax, or acregmin values
<syntaxhighlight lang="bash">
|No Default value
# NFS v4.2 마운트
|
$ mount -o nfsvers=4.2 srvr:/export /mountpoint
 
# 또는
$ mount -o nfsvers=4,minorversion=2 srvr:/export /mountpoint
</syntaxhighlight>
 
=== rsize/wsize 설정 ===
 
<syntaxhighlight lang="bash">
# /etc/fstab
srvr1:/usr/local  /usr/local  nfs  nfsvers=4.2,rsize=131072,wsize=131072  0  0
 
# systemd automount
srvr1:/usr/local  /usr/local  nfs  noauto,x-systemd.automount,nfsvers=4.2,rsize=131072,wsize=131072  0  0
</syntaxhighlight>
 
=== 권장 마운트 옵션 ===
 
{| class="wikitable"
! Condition
! Recommended Options
|-
|-
|grpid
| Server-Side NLM Enabled
|Forces a newly created file in the mounted file system to inherit the group ID of the parent directory.
| <syntaxhighlight>mount -t nfs -o rsize=65536,wsize=65536,intr,hard,tcp,rdirplus,readahead=128 server:/path mountpath</syntaxhighlight>
By default, a newly created file inherits the effective group ID of the calling process, unless the GID bit is set on the parent directory. If the GID bit is set, the new file inherits the group ID of the parent directory
|No Default value
|
|-
|-
|'''lock''' / '''nolock'''
| Local Locking Enforced
|
| <syntaxhighlight>mount -t nfs -o rsize=65536,wsize=65536,intr,hard,tcp,locallocks,rdirplus,readahead=128 server:/path mountpath</syntaxhighlight>
; Selects whether to use the NLM sideband protocol to lock files on the server. If neither option is specified (or if '''lock''' is specified), NLM locking is used for this mount point. When using the '''nolock''' option, applications can lock files, but such locks provide exclusion only against other applications running on the same client. Remote applications are not affected by these locks.
|}


NLM locking must be disabled with the '''nolock''' option when using NFS to mount ''/var'' because ''/var'' contains files used by the NLM implementation on Linux. Using the '''nolock''' option is also required when mounting exports on NFS servers that do not support the NLM protocol.  
|
|
|-
|'''local_lock='''mechanism
|Specifies whether to use local locking for any or both of the flock and the POSIX locking mechanisms. ''mechanism'' can be one of '''all''', '''flock''', '''posix''', or '''none'''.
The Linux NFS client provides a way to make locks local. This means, the applications can lock files, but such locks provide exclusion only against other applications running on the same client. Remote applications are not affected by these locks.


If '''all''' is specified, the client assumes that both flock and POSIX locks are local.
== Configuration ==
 
<syntaxhighlight lang="bash">
# NFS 서버 설정
$ sudo systemctl enable nfs-server
$ sudo systemctl start nfs-server
 
# /etc/exports 설정
$ echo "/srv/nfs4 192.168.1.0/24(rw,sync,no_subtree_check)" | sudo tee -a /etc/exports
$ sudo exportfs -r
 
# NFS 클라이언트 마운트
$ sudo mount -t nfs -o vers=4.1 192.168.1.10:/srv/nfs4 /mnt/nfs


If '''flock''' is specified, the client assumes that only flock locks are local and uses NLM sideband protocol to lock files when POSIX locks are used.
# /etc/fstab에 추가
$ echo "192.168.1.10:/srv/nfs4 /mnt/nfs nfs nfsvers=4.1,defaults,nofail,timeo=900,retrans=5,_netdev 0 0" | sudo tee -a /etc/fstab
</syntaxhighlight>


If '''posix''' is specified, the client assumes that POSIX locks are local and uses NLM sideband protocol to lock files when flock locks are used.


To support legacy flock behavior similar to that of NFS clients < 2.6.12, use [[Samba]] as Samba maps Windows share mode locks as flock. Since NFS clients > 2.6.12 implement flock by emulating POSIX locks, this will result in conflicting locks.
== Examples ==


|'''No Default value'''
=== Example 1: NFS 서버 설정 ===
|This option is supported in kernels 2.6.37 and later.
NOTE: When used together, the 'local_lock' mount option will be overridden by 'nolock'/'lock' mount option.  
|}


=== NFS client mount examples ===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
under cli,
# NFS 서버 설치
$ sudo apt-get install nfs-kernel-server


sudo mount -t nfs -o vers=4 192.168.33.10:/backups /backups
# /etc/exports 설정
sudo mount -t nfs -o vers=4 192.168.33.10:/www /srv/www
$ sudo tee /etc/exports << EOF
/srv/nfs4 192.168.1.0/24(rw,sync,no_subtree_check)
EOF


use fstab
# NFS 서비스 시작
192.168.33.10:/backups /backups  nfs   nfsvers=4.1,defaults,nofail,timeo=900,retrans=5,_netdev 0 0
$ sudo systemctl enable nfs-server
192.168.33.10:/www /srv/www      nfs   nfsvers=4.1,defaults,nofail,timeo=900,retrans=5,_netdev 0 0
$ sudo systemctl start nfs-server


# 공유 내보내기
$ sudo exportfs -r
$ sudo exportfs -v
</syntaxhighlight>
</syntaxhighlight>


== Optimizing NFS Performance<ref>https://nfs.sourceforge.net/nfs-howto/ar01s05.html</ref> <ref>https://www.admin-magazine.com/HPC/Articles/Useful-NFS-Options-for-Tuning-and-Management</ref> ==
=== Example 2: NFS 클라이언트 마운트 ===
Tuning for performance is a loaded question because performance is defined by so many different variables, the most important of which is how to measure performance.
 
<syntaxhighlight lang="bash">
# NFS 마운트
$ sudo mount -t nfs -o vers=4.1 192.168.1.10:/srv/nfs4 /mnt/nfs
 
# 마운트 옵션 확인
$ cat /proc/mounts | grep nfs
 
# NFS 상태 확인
$ nfsstat -m
</syntaxhighlight>


{| class="wikitable"
|+
!Tunning Options
!Target
!Description
!Recommendation
|-
| rowspan="6" |NFS performance
|Synchronous vs asynchronous on client
|''sync'' or ''async'' on the ''mount'' command line or in the file ''/etc/fstab''
|To change the option, you first have to unmount the NFS filesystem,
change the option, then remount the filesystem.
|-
|Number of NFS daemons (''nfsd'') on server
|One way to determine whether more NFS threads helps performance is to check the data in ''cat /proc/net/rpc/nfsd (Ubuntu)'' for the load on the NFS daemons.
The output line that starts with ''th'' lists the number of threads, and the last 10 numbers are a histogram of the number of seconds the first 10% of threads were busy, the second 10%, and so on.


== Best Practices ==


* NFS v4.2 사용 (최신 버전)
* rsize/wsize=131072 설정 (대용량 전송)
* nconnect=16 사용 (다중 TCP 연결)
* MTU 9000 (Jumbo Packet) 적용
* sync 옵션 사용 (데이터 무결성)
* root_squash 활성화 (보안)
* FS-Cache 활성화 (읽기 성능)
* noatime/nodiratime 설정 (성능)
* 정기적인 nfsstat 모니터링


[https://svennd.be/nfsd-stats-explained-procnetrpcnfsd/ this page] explain how to part the contents of ''/proc/net/rpc/nfsd.''


== Limitations ==


* NFSv2: 2GB 파일 제한, UDP만 지원
* NFSv3: 상태(Stateless) — 서버 재시작 시 세션 손실
* NFSv4: Kerberos 설정 복잡
* 네트워크 지연에 민감
* 대용량 파일 동시 접근 시 병목
* NFS 서버 단일 장애점 (SPOF)


Ideally, you want the last two numbers to be zero or close to zero, indicating that the threads are busy and you are not "wasting" any threads. If the last two numbers are fairly high, you should add NFS daemons, because the NFS server has become the bottleneck. If the last two, three, or four numbers are zero, then some threads are probably not being used<ref>https://www.admin-magazine.com/HPC/Articles/Useful-NFS-Options-for-Tuning-and-Management</ref>


on Ubuntu 20.04, ''RPCNFSDCOUNT in /etc/default/nfs-kernel-server file'' tells you the number of NFS daemons for the server. [[NFS tips and tricks]]
== References ==


in addition, for tuning how many threads are needed you could look at : /proc/fs/nfsd/pool_stats
* https://en.wikipedia.org/wiki/Network_File_System
|256 on 16C/128GB
* https://nfs.sourceforge.net/nfs-howto/ar01s05.html
64 on 8C/64GB
* https://www.admin-magazine.com/HPC/Articles/Useful-NFS-Options-for-Tuning-and-Management
* https://ubuntu.com/server/docs/service-nfs


to take effect reboot system<ref>https://ubuntuforums.org/showthread.php?t=2345636</ref>
|-
|'''Block Size Setting on client'''
|Two NFS client options specify the size of data chunks for writing (''wsize'') and reading (''rsize''). If you don't specify the chunk sizes, the defaults are determined by the versions of NFS and the kernel being used
the best way to check the current chunk size is to run the command on the NFS client and look for the ''wsize'' and ''rsize'' values.


$cat /proc/mounts
== Related Pages ==
|edit <code>/etc/fstab</code> to reflect the '''rsize/wsize'''
|-
|'''Timeout and Retransmission on client'''
|On congested networks, you often see retransmissions of RPC packets. A good way to tell is to run the
nfsstat -r
command and look for the column labeled ''retrans''. If the number is large, the network is likely very congested. If that is the case, you might want to increase the values of ''timeo'' and ''retrans'' to increase the number of tries and the amount of time between RPC tries. Although taking this action will slow down NFS performance, it might help even out the [[network traffic]] so that congestion is reduced. In my experience, getting rid of congestion and dropped packets can result in better, more even performance
|timeo can be adjusted of the ''mount'' command or by editing the ''/etc/fstab'' file on the NFS client to indicate the value of ''timeo''.
|-
|'''FS-Cache on client'''
|FS-Cache option enable caches NFS client requests on a local storage device, such as a hard drive or SSD, helping improve NFS read I/O: Data that resides on the local NFS client means the NFS server does not have to be contacted.
To use NFS caching you have to enable it explicitly by adding the option ''-o fsc'' to the ''mount'' command or in ''[[Fstab|/etc/fstab]]:''
# mount <nfs-share>:/ </mount/point> -o fsc
Any data access to <''/mount/point>'' will go through the NFS cache unless the file is opened for direct I/O or if a write I/O is performed.


The important thing to remember is that FS-Cache only works if the I/O is a read. FS-Cache can't help with a direct I/O (read or write) or an I/O write request. However, there are plenty of cases in which FS-Cache can help. For example, if you have an application that needs to read from a database or file and you are running a large number of copies of the same application, FS-Cache might help, because each node could cache the database or file.
* [[Samba]]
|
* [[Storage]]
|-
* [[Linux]]
|Filesystem-independent mount options on client
* [[Network]]
|''Linux mount'' command has a number of options that are independent of the filesystem and might be able to improve performance
* [[Fstab]]


* '''''noatime''''' – Inode access times are not updated on the filesystem. This can help performance because the access time of the file is not updated every time a file is accessed.
* '''''nodiratime''''' – The directory inode is not updated on the filesystem when it is accessed. This can help performance in the same way as not updating the file access time.
* '''''relatime''''' – Inode access times are relative to the modify or change time for the file, so the access time is updated only if the previous ''atime'' (access time) was earlier than the modify or change time.
|
|-
| rowspan="3" |System tuning
|'''System Memory on server'''
|If you are choosing to use asynchronous NFS mode, you will need more memory to take advantage of ''async,'' because the NFS server will first store the I/O request in memory, respond to the NFS client, and then retire the I/O by having the filesystem write it to stable storage. Therefore, you need as much memory as possible to get the best performance.
|
|-
|Network MTU on both server and client
|Changing the network MTU (maximum transmission unit) is also a good way to affect performance, but it is not an NFS tunable.
The MTU size can be very important because it determines packet fragments on the network. If your chunk size is 8KB and the MTU is ''1500'', it will take six Ethernet frames to transmit the 8KB. If you increase the MTU to ''9000'' (9,000 bytes), the number of Ethernet frames drops to one.


A study by Dell a few years back examined the effect of an MTU of ''1500'' compared with an MTU of ''9000''. Using Netperf, they found that the bandwidth increased by about 33% when an MTU of ''9000'' was used
[[Category:Server]]
== Knowledge Graph ==


Fortunatly most switches can accommodate an MTU of ''9000'' (commonly called "jumbo packets")
Related
|
|-
|TCP tuning on the server<ref>https://www.cyberciti.biz/faq/linux-tcp-tuning/</ref>
|The NFS server NFS daemons share the same socket input and output queues, so if the queues are larger, all of the NFS daemons have more buffer and can send and receive data much faster.<syntaxhighlight lang="bash">
For read buffer - 256KiB (base 2),
echo 262144 > /proc/sys/net/core/rmem_default
echo 262144 > /proc/sys/net/core/rmem_max


For write buffer -  256KiB (base 2),
→ [[Network]]
echo 262144 > /proc/sys/net/core/wmem_default
→ [[NFSv4 ACLs]]
echo 262144 > /proc/sys/net/core/wmem_max
→ [[Storage]]
</syntaxhighlight>To make the values survive reboots, you need to enter them in the proper form in the ''/etc/sysctl.conf'' file or /etc/sysctl.d/somefile
|
|-
| rowspan="2" |NFS management/policy
|Subtree checking on server
|''subtree_check'' to the exports on the NFS server checks that the file being accessed is contained within the exported directory and force the NFS server to check that the requested file was located within exported folder
Many people have the opinion that ''subtree_check'' can have a big effect on performance, but the final determination is up to that is performance more important than security for the configuration and your situation


For security, it is recommended to export folders which uses separate partition or separate drive to prevent a rogue user from guessing a file handle to anything outside of the filesystem
[[Category:Reference]]
|
|-
|Root squashing on server
|if you want ''root'' to have access to an NFS-mounted filesystem, you can add the option ''no_root_squash'' to the file ''/etc/exports'' to allow root access. Just be aware that if someone reboots your system to gain root access, it's possible for them to copy (steal) data.
|}


=== Specify NFS v4.1 or, Better Yet, v4.2<ref>https://cromwell-intl.com/open-source/performance-tuning/nfs.html</ref> ===
== NFSv4.2 Features ==
<syntaxhighlight lang="bash">
probably:
# mount -o nfsvers=4.2 srvr:/export /mountpoint


or possibly:
NFSv4.2는 NFS 최신 버전. 여러 성능 개선 기능 포함.
# mount -o nfsvers=4,minorversion=2 srvr:/export /mountpoint
</syntaxhighlight>


=== Specify Bytes Per Read/Write With rsize and wsize ===
=== PFCP (Parallel NFS) ===
The mount command options '''<code>rsize</code>''' and '''<code>wsize</code>''' specify the size of the chunks of data that the client and server pass back and forth to each other. All 2.4 clients currently support up to 32K block transfer sizes.<ref>https://nfs.sourceforge.net/nfs-howto/ar01s05.html</ref> <syntaxhighlight lang="bash">
Put options for static mounts in /etc/fstab. Put options for automounted file systems in the map file.


# grep nfs /etc/fstab
* 파일 내 병렬 I/O. 큰 파일 처리 속도↑
srvr1:/usr/local  /usr/local  nfs  nfsvers=4.2,rsize=131072,wsize=131072  0  0
* client-side caching. 로컬 캐시로 읽기 속도↑
# tail -1 /etc/autofs/auto.master
/-  auto.local
# cat /etc/autofs/auto.local
/usr/local  -nfsvers=4.2,rsize=131072,wsize=131072  srvr1:/usr/local


What may be a better way is to use the systemd automounter.
<syntaxhighlight lang="bash">
# grep nfs /etc/fstab
# PFCP 마운트 옵션
srvr1:/usr/local  /usr/local  nfs  noauto,x-systemd.automount,nfsvers=4.2,rsize=131072,wsize=131072  0  0
mount -t nfs4 -o vers=4.2,cache=loose server:/share /mnt/nfs
</syntaxhighlight>
</syntaxhighlight>


== Mount Options Example<ref>https://care.qumulo.com/hc/en-us/articles/115008111268-Recommended-NFS-Mount-Options#recommended-mount-options-for-linux-0-5</ref> ==
=== RDMA-NFS (NFS over RDMA) ===
 
* RDMA로 NFS 트래픽 전송. CPU 부하 ↓, 레이턴시 ↓
* IPoIB ([[InfiniBand]] over IP) 또는 RoCE 사용


* In Linux kernel 5.3 (and higher), the <code>nconnect</code> option allows multiple TCP connections for a single NFS mount. '''Note:''' Currently, the maximum number of concurrent TCP connections is 16.
<syntaxhighlight lang="bash">
* In Linux kernel 2.6.25 (and higher), the <code>intr</code> and <code>nointr</code> mount options are deprecated. If you use the <code>hard</code> option on modern Linux kernels, you must use the <code>kill -9</code> <code>(SIGKILL)</code> command to interrupt a stuck NFS mount.
# RDMA-NFS 마운트
mount -t nfs -o vers=4.2,rdma server:/share /mnt/nfs


{| class="wikitable"
# RDMA-NFS 성능 확인
|+
nfsstat -m
!Condition
!Recommended Options
|-
|'''Client with Server-Side Network Lock Manager (NLM) Enabled'''
|<syntaxhighlight lang="bash">
mount -t nfs -o rsize=65536,wsize=65536,intr,hard,tcp,rdirplus,readahead=128 server:/path mountpath
</syntaxhighlight>
</syntaxhighlight>
|-
|'''Client with Local Locking Enforced'''
|<syntaxhighlight lang="bash">
mount -t nfs  -o rsize=65536,wsize=65536,intr,hard,tcp,locallocks,rdirplus,readahead=128 \ server:/path mountpath
</syntaxhighlight>
|}


=== Copy Offload (COPY/DEDUP) ===
* 서버 사이드 복사. 네트워크 트래픽 없음
* 대용량 데이터 이동 시 효율적


== References ==
<syntaxhighlight lang="bash">
<references />
# 서버 사이드 복사
cp --reflink=auto /mnt/nfs/source /mnt/nfs/dest
</syntaxhighlight>

Latest revision as of 13:37, 17 July 2026

NFS

Template:Status

Template:TOC

Overview

NFS(Network File System)는 Sun Microsystems에서 개발한 네트워크 파일 공유 시스템입니다. SMB/SMB와 함께 네트워크 상의 파일 시스템을 로컬 파일 시스템처럼 접근할 수 있게 해주는 가장 널리 사용되는 HPC 스토리지 솔루션입니다.

Summary

  • 무엇인가? — 네트워크 파일 공유 프로토콜 (TCP/IP 기반)
  • 왜 필요한가? — 중앙 집중식 스토리지, 다수 클라이언트 공유, 간단한 설정
  • 언제 사용하는가? — HPC 클러스터, 파일 서버, 스토리지 공유


Purpose

이 문서가 존재하는 이유

  • Goal: NFS 버전, 서버/클라이언트 설정, 마운트 옵션, 성능 튜닝 제공
  • Scope: NFS v2~v4.2, export/mount 옵션, 성능 최적화, 서비스 의존성
  • Non-goals: NFS 커널 패치 개발, NFSv4.3+ 최신 기능은 별도 문서


Key Concepts

Concept Description Related
NFSv4 상태(Stateful) 기반 NFS — 단일 포트 2049 NFS
pNFS Parallel NFS — 다수 서버 스트라이핑 NFS
exportfs NFS 공유 내보내기 명령어 NFS
mount options NFS 클라이언트 마운트 옵션 NFS
rsize/wsize 읽기/쓰기 블록 크기 NFS
nconnect 다중 TCP 연결 (커널 5.3+) NFS
FS-Cache NFS 클라이언트 로컬 캐싱 NFS
root_squash 원격 루트 권한 제한 NFS


Architecture

NFS는 클라이언트-서버 아키텍처로 구성됩니다:

graph TD
    A[NFS Server] --> B[/etc/exports]
    A --> C[nfs-server.service]
    A --> D[nfs-mountd]
    A --> E[nfs-idmapd]
    B --> F[Shared Directory]
    G[NFS Client] --> H[mount -t nfs]
    G --> I[/etc/fstab]
    H --> J[NFS Server:2049]
    I --> J


Workflow

Stage Input Output
Server Setup /etc/exports NFS Share
Client Mount mount -t nfs NFS Mount Point
Performance Tuning rsize/wsize/timeo Optimized NFS
Monitoring nfsstat / /proc/net/rpc/nfsd Performance Data


Detailed Explanation

NFS 버전

Version Description Key Features
NFSv2 RFC 1094 (1989) UDP만 지원, 2GB 파일 제한, 8KB 쓰기 제한
NFSv3 RFC 1813 (1995) 대용량 파일 지원, TCP 지원, 56KB 트랜잭션
NFSv4 RFC 3010/3530/7530 상태(Stateful), 단일 포트 2049, Kerberos 보안
NFSv4.1 RFC 5661 (2010) pNFS(Parallel NFS), 블록/객체 접근, Windows Kerberos
NFSv4.2 RFC 7862 향상된 성능 및 기능

NFS 서버 설정

/etc/exports 옵션

Export Options NFS Server Default
secure/insecure NFSv4는 포트 2049만 사용. NFSv3는 서버 포트 사용. secure: 클라이언트 포트 < 1024. insecure: 모든 포트 허용. secure
rw/ro rw: 읽기/쓰기. ro: 읽기 전용. rw
root_squash/no_root_squash root_squash: 원격 루트 권한 제한. no_root_squash: 원격 루트 전체 권한 허용. root_squash
all_squash/no_all_squash all_squash: 모든 UID/GID를 anonymous로 매핑. no_all_squash
sync/async sync: 변경사항 저장 후 응답. async: 저장 전 응답 (성능 ↑, 데이터 손실 위험). sync
insecure_locks 파일 잠금 시 클라이언트 자격 증명 불필요 (보안 위험).

export 명령어

# 공유 내보내기
$ exportfs -a

# 공유 다시 내보내기
$ exportfs -r

# 공유 권한 확인
$ exportfs -v

# 현재 NFS 서비스 포트 확인
$ rpcinfo -p | grep -i nfs

export 예시

# /etc/exports
/srv/nfs4         192.168.33.0/24(rw,sync,no_subtree_check,crossmnt,fsid=0)
/srv/nfs4/backups 192.168.33.0/24(ro,sync,no_subtree_check) 192.168.33.3(rw,sync,no_subtree_check)
/srv/nfs4/www     192.168.33.20(rw,sync,no_subtree_check)

Ubuntu NFS 서비스 의존성

Service nfs-utils.service nfs-server.service Config File (22.04) Config File (< 22.04)
nfs-blkmap PartOf nfs.conf
nfs-mountd BindsTo nfs.conf nfs-kernel-server
nfsdcld
nfs-idmapd BindsTo nfs.conf, idmapd.conf idmapd.conf
rpc-gssd PartOf nfs.conf
rpc-statd PartOf nfs.conf nfs-common
rpc-svcgssd PartOf BindsTo nfs.conf nfs-kernel-server

NFS 클라이언트 마운트 옵션

Mount Options NFS Client Default Notes
nfsvers/vers=n 사용할 NFS 버전. 기본값 3. 3, 4
rw/ro rw: 읽기/쓰기. ro: 읽기 전용. rw
suid/nosuid suid: setuid 프로그램 허용. nosuid: setuid 차단. suid
hard/soft hard: 서버 다운 시 재시도 (프로세스 대기). soft: 재시도 후 에러 반환. hard
nconnect=value 다중 TCP 연결 (커널 5.3+). 최대 16. 16 성능 향상
intr/nointr intr: NFS 요청 중단 가능. nointr: 중단 불가. intr Linux 2.6.25+ deprecated
fg/bg fg: 부팅 필수 마운트. bg: 백그라운드 마운트. fg
devs/nodevs devs: 장치 파일 허용. nodevs: 장치 파일 차단. devs
timeo=n 재전송 대기 시간 (0.1초 단위). 최대 30 (3초). 0.7
retrans=n 재전송 횟수. 4
retry=n 마운트 재시도 횟수. 1
rsize=n 읽기 블록 크기. 8192
wsize=n 쓰기 블록 크기. 8192
noac 속성 캐싱 비활성화.
actimeo=n 모든 캐싱 타임아웃 설정.
lock/nolock NLM 파일 잠금 사용 여부. lock
local_lock=mechanism 로컬 잠금 방식 (all/flock/posix/none). 커널 2.6.37+

NFS 성능 최적화

Tuning Options Target Description Recommendation
sync/async 클라이언트 mount 또는 /etc/fstab에서 설정
nfsd 수 서버 /proc/net/rpc/nfsd로 스레드 부하 확인 16C/128GB: 256, 8C/64GB: 64
rsize/wsize 클라이언트 읽기/쓰기 블록 크기 /etc/fstab에서 rsize=131072, wsize=131072
timeo/retrans 클라이언트 네트워크 혼잡 시 재전송 설정 timeo=900, retrans=5
FS-Cache 클라이언트 로컬 스토리지에 NFS 읽기 캐싱 (-o fsc) 읽기 작업에 효과적
noatime/nodiratime 클라이언트 inode 접근 시간 업데이트 방지 성능 향상
System Memory 서버 async 모드 시 메모리 확보 필요 가능한 많은 메모리
Network MTU 서버+클라이언트 MTU 1500 → 9000 (Jumbo Packet) 대역폭 33% 증가
TCP tuning 서버 net.core.rmem/wmem 설정 262144 (256KiB)
subtree_check 서버 export된 폴더 내 파일 확인 보안 ↑, 성능 ↓
root_squash 서버 원격 루트 권한 제한 보안 ↑

NFS v4.1/v4.2 권장

# NFS v4.2 마운트
$ mount -o nfsvers=4.2 srvr:/export /mountpoint

# 또는
$ mount -o nfsvers=4,minorversion=2 srvr:/export /mountpoint

rsize/wsize 설정

# /etc/fstab
srvr1:/usr/local  /usr/local  nfs  nfsvers=4.2,rsize=131072,wsize=131072  0  0

# systemd automount
srvr1:/usr/local  /usr/local  nfs  noauto,x-systemd.automount,nfsvers=4.2,rsize=131072,wsize=131072  0  0

권장 마운트 옵션

Condition Recommended Options
Server-Side NLM Enabled
mount -t nfs -o rsize=65536,wsize=65536,intr,hard,tcp,rdirplus,readahead=128 server:/path mountpath
Local Locking Enforced
mount -t nfs -o rsize=65536,wsize=65536,intr,hard,tcp,locallocks,rdirplus,readahead=128 server:/path mountpath


Configuration

# NFS 서버 설정
$ sudo systemctl enable nfs-server
$ sudo systemctl start nfs-server

# /etc/exports 설정
$ echo "/srv/nfs4 192.168.1.0/24(rw,sync,no_subtree_check)" | sudo tee -a /etc/exports
$ sudo exportfs -r

# NFS 클라이언트 마운트
$ sudo mount -t nfs -o vers=4.1 192.168.1.10:/srv/nfs4 /mnt/nfs

# /etc/fstab에 추가
$ echo "192.168.1.10:/srv/nfs4 /mnt/nfs nfs nfsvers=4.1,defaults,nofail,timeo=900,retrans=5,_netdev 0 0" | sudo tee -a /etc/fstab


Examples

Example 1: NFS 서버 설정

# NFS 서버 설치
$ sudo apt-get install nfs-kernel-server

# /etc/exports 설정
$ sudo tee /etc/exports << EOF
/srv/nfs4 192.168.1.0/24(rw,sync,no_subtree_check)
EOF

# NFS 서비스 시작
$ sudo systemctl enable nfs-server
$ sudo systemctl start nfs-server

# 공유 내보내기
$ sudo exportfs -r
$ sudo exportfs -v

Example 2: NFS 클라이언트 마운트

# NFS 마운트
$ sudo mount -t nfs -o vers=4.1 192.168.1.10:/srv/nfs4 /mnt/nfs

# 마운트 옵션 확인
$ cat /proc/mounts | grep nfs

# NFS 상태 확인
$ nfsstat -m


Best Practices

  • NFS v4.2 사용 (최신 버전)
  • rsize/wsize=131072 설정 (대용량 전송)
  • nconnect=16 사용 (다중 TCP 연결)
  • MTU 9000 (Jumbo Packet) 적용
  • sync 옵션 사용 (데이터 무결성)
  • root_squash 활성화 (보안)
  • FS-Cache 활성화 (읽기 성능)
  • noatime/nodiratime 설정 (성능)
  • 정기적인 nfsstat 모니터링


Limitations

  • NFSv2: 2GB 파일 제한, UDP만 지원
  • NFSv3: 상태(Stateless) — 서버 재시작 시 세션 손실
  • NFSv4: Kerberos 설정 복잡
  • 네트워크 지연에 민감
  • 대용량 파일 동시 접근 시 병목
  • NFS 서버 단일 장애점 (SPOF)


References


Related Pages

Knowledge Graph

Related

NetworkNFSv4 ACLsStorage

NFSv4.2 Features

NFSv4.2는 NFS 최신 버전. 여러 성능 개선 기능 포함.

PFCP (Parallel NFS)

  • 파일 내 병렬 I/O. 큰 파일 처리 속도↑
  • client-side caching. 로컬 캐시로 읽기 속도↑
# PFCP 마운트 옵션
mount -t nfs4 -o vers=4.2,cache=loose server:/share /mnt/nfs

RDMA-NFS (NFS over RDMA)

  • RDMA로 NFS 트래픽 전송. CPU 부하 ↓, 레이턴시 ↓
  • IPoIB (InfiniBand over IP) 또는 RoCE 사용
# RDMA-NFS 마운트
mount -t nfs -o vers=4.2,rdma server:/share /mnt/nfs

# RDMA-NFS 성능 확인
nfsstat -m

Copy Offload (COPY/DEDUP)

  • 서버 사이드 복사. 네트워크 트래픽 없음
  • 대용량 데이터 이동 시 효율적
# 서버 사이드 복사
cp --reflink=auto /mnt/nfs/source /mnt/nfs/dest