NFS: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
(Phase 0.4: Expand NFS)
 
(24 intermediate revisions by 2 users not shown)
Line 1: Line 1:
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.
= NFS =


{{Status
|status=Draft
|owner=Knowledge Agent
|last_update=2026-07-15
|review=Pending
}}


{{TOC}}


== Basic command ==
== Overview ==
{| class="wikitable sortable"
 
|+
NFS(Network File System)는 Sun Microsystems에서 개발한 네트워크 파일 공유 시스템입니다. SMB/SMB와 함께 네트워크 상의 파일 시스템을 로컬 파일 시스템처럼 접근할 수 있게 해주는 가장 널리 사용되는 HPC 스토리지 솔루션입니다.
!Commands
 
!Description
=== Summary ===
!Command on
 
* 무엇인가? — 네트워크 파일 공유 프로토콜 (TCP/IP 기반)
* 왜 필요한가? — 중앙 집중식 스토리지, 다수 클라이언트 공유, 간단한 설정
* 언제 사용하는가? — HPC 클러스터, 파일 서버, 스토리지 공유
 
 
== Purpose ==
 
이 문서가 존재하는 이유
 
* Goal: NFS 버전, 서버/클라이언트 설정, 마운트 옵션, 성능 튜닝 제공
* Scope: NFS v2~v4.2, export/mount 옵션, 성능 최적화, 서비스 의존성
* Non-goals: NFS 커널 패치 개발, NFSv4.3+ 최신 기능은 별도 문서
 
 
== Key Concepts ==
 
{| class="wikitable"
! Concept
! Description
! Related
|-
| NFSv4
| 상태(Stateful) 기반 NFS — 단일 포트 2049
| [[NFS]]
|-
| pNFS
| Parallel NFS — 다수 서버 스트라이핑
| [[NFS]]
|-
| exportfs
| NFS 공유 내보내기 명령어
| [[NFS]]
|-
| mount options
| NFS 클라이언트 마운트 옵션
| [[NFS]]
|-
|-
|# exportfs -r 
| rsize/wsize
|Re-export your shares
| 읽기/쓰기 블록 크기
|Server
| [[NFS]]
|-
|-
|# exportfs -a 
| nconnect
|Export your shares
| 다중 TCP 연결 (커널 5.3+)
|Server
| [[NFS]]
|-
|-
|# exportfs -v
| FS-Cache
|Verify the NFS Share permissions
| NFS 클라이언트 로컬 캐싱
|Server
| [[NFS]]
|-
|-
|$nfsstat -m
| root_squash
|'''Verify Current NFS Mount Options''' 
| 원격 루트 권한 제한
|Client
| [[NFS]]
|}
|}




== NFS export on Server<ref>https://www.golinuxcloud.com/unix-linux-nfs-mount-options-example/</ref> ==
== Architecture ==
NFS exports options are the permissions '''that is applied on NFS Server''' when we create a NFS Share under <code>/etc/exports</code>
 
NFS는 클라이언트-서버 아키텍처로 구성됩니다:
 
<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 ==


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]
{| class="wikitable"
{| class="wikitable"
|+
! Stage
!Export Options
! Input
!NFS Server
! Output
!Default
|-
| Server Setup
| /etc/exports
| NFS Share
|-
| Client Mount
| mount -t nfs
| NFS Mount Point
|-
|-
|<code>secure/insecure</code>
| Performance Tuning
|'''NFSv4 only uses port 2049''' while to check the list of ports used by '''NFSv3 use in server port'''
| rsize/wsize/timeo
With <code>secure</code> the port number from which the client requests a mount must be lower than 1024.
| Optimized NFS
To allow client any available free port use <code>insecure</code> in the NFS share
|<code>secure</code>
|-
|-
|rw/ro
| Monitoring
|'''ro''' means '''read-only''' access to the NFS Share
| nfsstat / /proc/net/rpc/nfsd
| Performance Data
|}


'''rw''' means '''read write''' access to the NFS Share
|
|-
|root_squash/no_root_squash
|'''squash literally means to squash (destroy) the power of the remote root user.'''


== Detailed Explanation ==


<code>root_squash</code> prevents remote root users from having superuser (root) privileges on remote NFS-mounted volumes.
=== NFS 버전 ===


<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"
|
! 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 보안
|-
|-
|all_quash/no_all_squash
| NFSv4.1
|<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
| RFC 5661 (2010)
|<code>no_all_squash</code>
| pNFS(Parallel NFS), 블록/객체 접근, Windows Kerberos
|-
|-
|sync/aysnc
| NFSv4.2
|<code>sync</code> reply to requests are done only after the changes have been committed to stable storage
| RFC 7862
| 향상된 성능 및 기능
|}
 
=== NFS 서버 설정 ===


<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
==== /etc/exports 옵션 ====


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'''
{| class="wikitable"
|
! 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
| 파일 잠금 시 클라이언트 자격 증명 불필요 (보안 위험).
|
|}
|}


=== Check exports list and options ===
==== export 명령어 ====
 
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
#with following set
# 공유 내보내기
$ cat /etc/exports
$ exportfs -a
/nas * (rw,sync,no_root_squash,no_subtree_check)


# 공유 다시 내보내기
$ 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 mount on Client<ref>https://www.thegeekdiary.com/common-nfs-mount-options-in-linux/</ref> ==
==== export 예시 ====
<nowiki>#</nowiki> mount -t nfs -o [options] remote:/nfs /mount
 
<syntaxhighlight lang="bash">
# /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)
</syntaxhighlight>
 
=== Ubuntu NFS 서비스 의존성 ===


{| class="wikitable"
{| class="wikitable"
|+
! Service
!Mount Options
! nfs-utils.service
!NFS Client
! nfs-server.service
!Default
! Config File (22.04)
!Notes
! Config File (< 22.04)
|-
| nfs-blkmap
| PartOf
| —
| nfs.conf
| —
|-
|-
|'''nfsvers='''''n or'' vers=n
| nfs-mountd
|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.
|
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
| BindsTo
|3
| nfs.conf
|
| nfs-[[kernel]]-server
|-
|-
|rw (read/write) / ro (read-only)
| nfsdcld
|
|
* 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.
| —
* 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
| nfs-idmapd
|
|
* 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.
| BindsTo
* Specify nosuid to protect your system against setuid programs that may run as root and damage your system.
| nfs.conf, idmapd.conf
|suid
| idmapd.conf
|
|-
|-
|hard / soft
| rpc-gssd
|
| PartOf
* 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).
| —
* 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 (see the retrans option, later). Any processes using the mounted directory will return errors if the server goes down.
| nfs.conf
|hard
|
|
|-
|-
|<code>nconnect=<value></code>
| rpc-statd
|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>
| PartOf
|16
|
|In [[Linux]] kernel 5.3 (and higher), the <code>nconnect</code> option allows multiple TCP connections for a single NFS mount.
| nfs.conf
| nfs-common
|-
|-
|intr / nointr
| rpc-svcgssd
|
| PartOf
* 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.
| BindsTo
* 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.
| nfs.conf
|intr
| nfs-kernel-server
|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.
|}
 
=== NFS 클라이언트 마운트 옵션 ===
 
{| class="wikitable"
! Mount Options
! NFS Client
! Default
! Notes
|-
|-
|fg (foreground) / bg (background)
| nfsvers/vers=n
|
| 사용할 NFS 버전. 기본값 3.
* 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.
| 3, 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
| rw/ro
|
| rw: 읽기/쓰기. ro: 읽기 전용.
* 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.
| rw
* 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
| suid/nosuid
|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).
| suid: setuid 프로그램 허용. nosuid: setuid 차단.
– 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.
| suid
|7
|
|
|-
|-
|retrans=n
| hard/soft
|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.
| hard: 서버 다운 시 재시도 (프로세스 대기). soft: 재시도 후 에러 반환.
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
| hard
|4
|
|
|-
|-
|retry=n
| nconnect=value
|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.
| 다중 TCP 연결 (커널 5.3+). 최대 16.
If mounts are failing because your server is very busy, increasing the retry value may fix the problem
| 16
|1
| 성능 향상
|
|-
|-
|rsize=n
| intr/nointr
|The number of bytes the NFS client requests from the NFS server in a single read request.
| intr: NFS 요청 중단 가능. nointr: 중단 불가.
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 at the HP-UX prompt. 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.
| intr
|8192
| Linux 2.6.25+ deprecated
|
|-
|-
|wsize=n
| fg/bg
|The number of bytes the NFS client sends to the NFS server in a single write request.
| fg: 부팅 필수 마운트. bg: 백그라운드 마운트.
If packets are being dropped between the client and the server, decrease wsize to 4096 or 2048. To find out whether packets are being dropped, issue the “nfsstat -rc” command at the HP-UX prompt. 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.
| fg
|8192
|
|
|-
|-
|O (Overlay mount)
| devs/nodevs
|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.
| devs: 장치 파일 허용. nodevs: 장치 파일 차단.
'''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.
| devs
 
| —
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 /etc/fstab file.
|-
|The default value is not specified
| timeo=n
|
| 재전송 대기 시간 (0.1초 단위). 최대 30 (3초).
| 0.7
| —
|-
| retrans=n
| 재전송 횟수.
| 4
|
|-
|-
|remount
| retry=n
|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
| 마운트 재시도 횟수.
|The Default value is not specified
| 1
|
|
|-
|-
|noac
| rsize=n
|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.
| 8192
 
|
If you specify noac, do not specify the other caching options.
|The Default value is not specified
|
|-
|-
|nocto
| wsize=n
|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
| 8192
|The Default value is not specified
|
|
|-
|-
|acdirmax=n
| noac
|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
|
|60
|
|
|-
|-
|acdirmin=n
| actimeo=n
|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
|
|30
|
|
|-
|-
|acregmax=n
| lock/nolock
|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.
| NLM 파일 잠금 사용 여부.
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
| lock
|60
|
|
|-
|-
|actimeo=n
| local_lock=mechanism
|Setting actimeo to n seconds is equivalent to setting acdirmax, acdirmin, acregmax, and acregmin to n seconds.
| 로컬 잠금 방식 (all/flock/posix/none).
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.
| —
| 커널 2.6.37+
|}


Set actimeo=120 or higher for a directory that rarely or never changes.
=== NFS 성능 최적화 ===


If you set the actimeo value, do not set the acdirmax, acdirmin, acregmax, or acregmin values
{| class="wikitable"
|The Default value is not specified
! 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% 증가
|-
|-
|grpid
| TCP tuning
|Forces a newly created file in the mounted file system to inherit the group ID of the parent directory.
| 서버
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
| net.core.rmem/wmem 설정
|The Default value is not specified
| 262144 (256KiB)
|
|-
|-
|'''lock''' / '''nolock'''
| subtree_check
|
| 서버
; 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.
| export된 폴더 내 파일 확인
 
| 보안 ↑, 성능 ↓
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
| root_squash
|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.
=== NFS v4.1/v4.2 권장 ===


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.
<syntaxhighlight lang="bash">
# NFS v4.2 마운트
$ mount -o nfsvers=4.2 srvr:/export /mountpoint


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.
# 또는
$ mount -o nfsvers=4,minorversion=2 srvr:/export /mountpoint
</syntaxhighlight>


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.
=== rsize/wsize 설정 ===


|'''none'''
<syntaxhighlight lang="bash">
|This option is supported in kernels 2.6.37 and later.
# /etc/fstab
NOTE: When used together, the 'local_lock' mount option will be overridden by 'nolock'/'lock' mount option.  
srvr1:/usr/local  /usr/local  nfs  nfsvers=4.2,rsize=131072,wsize=131072  0  0
|}


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


* 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.
=== 권장 마운트 옵션 ===
* 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.


{| class="wikitable"
{| class="wikitable"
|+
! Condition
!
! Recommended Options
!
|-
|-
|'''Client with Server-Side Network Lock Manager (NLM) Enabled'''
| Server-Side NLM Enabled
|<syntaxhighlight lang="bash">
| <syntaxhighlight>mount -t nfs -o rsize=65536,wsize=65536,intr,hard,tcp,rdirplus,readahead=128 server:/path mountpath</syntaxhighlight>
mount -t nfs -o rsize=65536,wsize=65536,intr,hard,tcp,rdirplus,readahead=128 server:/path mountpath
|-
| Local Locking Enforced
| <syntaxhighlight>mount -t nfs -o rsize=65536,wsize=65536,intr,hard,tcp,locallocks,rdirplus,readahead=128 server:/path mountpath</syntaxhighlight>
|}
 
 
== 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
 
# /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>
</syntaxhighlight>
|-
 
|'''Client with Local Locking Enforced'''
 
|<syntaxhighlight lang="bash">
== Examples ==
mount -t nfs   -o rsize=65536,wsize=65536,intr,hard,tcp,locallocks,rdirplus,readahead=128 \ server:/path mountpath
 
=== Example 1: NFS 서버 설정 ===
 
<syntaxhighlight lang="bash">
# 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
</syntaxhighlight>
 
=== Example 2: NFS 클라이언트 마운트 ===
 
<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>
</syntaxhighlight>
|-
 
|
 
|
== 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 ==
== References ==
<references />
 
* https://en.wikipedia.org/wiki/Network_File_System
* https://nfs.sourceforge.net/nfs-howto/ar01s05.html
* https://www.admin-magazine.com/HPC/Articles/Useful-NFS-Options-for-Tuning-and-Management
* https://ubuntu.com/server/docs/service-nfs
 
 
== Related Pages ==
 
* [[Samba]]
* [[Storage]]
* [[Linux]]
* [[Network]]
* [[Fstab]]
 
 
[[Category:Server]]
== Knowledge Graph ==
 
Related
 
→ [[Network]]
→ [[NFSv4 ACLs]]
→ [[Storage]]
 
[[Category:Reference]]
 
== NFSv4.2 Features ==
 
NFSv4.2는 NFS 최신 버전. 여러 성능 개선 기능 포함.
 
=== PFCP (Parallel NFS) ===
 
* 파일 내 병렬 I/O. 큰 파일 처리 속도↑
* client-side caching. 로컬 캐시로 읽기 속도↑
 
<syntaxhighlight lang="bash">
# PFCP 마운트 옵션
mount -t nfs4 -o vers=4.2,cache=loose server:/share /mnt/nfs
</syntaxhighlight>
 
=== RDMA-NFS (NFS over RDMA) ===
 
* RDMA로 NFS 트래픽 전송. CPU 부하 ↓, 레이턴시 ↓
* IPoIB ([[InfiniBand]] over IP) 또는 RoCE 사용
 
<syntaxhighlight lang="bash">
# RDMA-NFS 마운트
mount -t nfs -o vers=4.2,rdma server:/share /mnt/nfs
 
# RDMA-NFS 성능 확인
nfsstat -m
</syntaxhighlight>
 
=== Copy Offload (COPY/DEDUP) ===
 
* 서버 사이드 복사. 네트워크 트래픽 없음
* 대용량 데이터 이동 시 효율적
 
<syntaxhighlight lang="bash">
# 서버 사이드 복사
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