본문 바로가기
LINUX

NAS Mount 하는 법(NFS Mount)

by study4me 2024. 12. 1.
반응형

NAS(Network Attached Storage)의 IP는 10.0.0.100이고 NAS의 경로는 /A_Project이다.

NAS Client 서버에서는 /mnt/data/nas에 NAS를 마운트하고자한다.

 

사전 준비

yum install nfs-utils
#systemctl start nfs-server
#systemctl enable nfs-server
#systemctl status nfs-server
#NFS Client에서는 굳이 nfs-server가 실행중일 필요는 없는 것 같다.
#테스트를 진행해봤는데 Client 서버에서 nfs-server가 stop 중일 때도 마운트는 잘되었다.
#아마 nfs-utils 설치하면서 의존성으로 같이 설치되는 패키지들에 의해서 마운트가 잘되는 걸수도?

# Ubuntu일 경우
# apt-get -y install nfs-common

mkdir /mnt/nas/data

 

 

임시로 Mount 하는 법

서버를 재부팅하면 Mount가 풀린다.

# 옵션 t: 파일 시스템 타입
mount -t nfs ${NFS_IP}:${NAS_PATH} ${LOCAL_PATH}

# 예시
mount -t nfs 10.0.0.100:/A_Project /mnt/data/nas

 

 

 

영구적으로 Mount 하는 법

서버를 재부팅해도 Mount가 유지된다.

cp /etc/fstab /etc/fstab.orig
echo "${NFS_IP}:${NAS_PATH} ${LOCAL_PATH} nfs defaults,nofail,_netdev 0 0" | tee -a /etc/fstab
systemctl daemon-reload
mount -a

AWS에서 작성한 권장 NFS Mount 셋팅을 참고했다.

(https://docs.aws.amazon.com/efs/latest/ug/mounting-fs-nfs-mount-settings.html)

더보기

noresvport – Tells the NFS client to use a new non-privileged Transmission Control Protocol (TCP) source port when a network connection is reestablished. NFS client software included in older versions of the Linux kernel (versions v5.4 and below) include a behavior that causes NFS clients to, upon disconnection, attempt reconnecting on the same TCP source port. This behavior does not comply with the TCP RFC, and can prevent these clients from quickly re-establishing connections to an EFS file system. Using noresvport option helps to ensure that NFS clients reconnect transparently to your EFS file system, maintaining uninterrupted availability when reconnecting after a network recovery event.
Important
We strongly recommend using the noresvport mounting option to help ensure that your EFS file system has uninterrupted availability after a reconnection or network recovery event. Consider using the EFS mount helper to mount your file systems. The EFS mount helper uses NFS mount options optimized for Amazon EFS file systems.

rsize=1048576 : Sets the maximum number of bytes of data that the NFS client can receive for each network READ request. This value applies when reading data from a file on an EFS file system. We recommend that you use the largest size possible (up to 1048576) to avoid diminished performance.

wsize=1048576 : Sets the maximum number of bytes of data that the NFS client can send for each network WRITE request. This value applies when writing data to a file on an EFS file system. We recommend that you use the largest size possible (up to 1048576) to avoid diminished performance.

hard : Sets the recovery behavior of the NFS client after an NFS request times out, so that NFS requests are retried indefinitely until the server replies. We recommend that you use the hard mount option (hard) to ensure data integrity. If you use a soft mount, set the timeo parameter to at least 150 deciseconds (15 seconds). Doing so helps minimize the risk of data corruption that is inherent with soft mounts.

timeo=600 : Sets the timeout value that the NFS client uses to wait for a response before it retries an NFS request to 600 deciseconds (60 seconds). If you must change the timeout parameter (timeo), we recommend that you use a value of at least 150, which is equivalent to 15 seconds. Doing so helps avoid diminished performance.

retrans=2 : Sets to 2 the number of times the NFS client retries a request before it attempts further recovery action.

_netdev : When present in /etc/fstab, prevents the client from attempting to mount the EFS file system until the network has been enabled.

nofail : If your EC2 instance needs to start regardless of the status of your mounted EFS file system, add the nofail option to your file system's entry in your /etc/fstab file.

 

 

Mount 후 확인 방법

df -h |grep ${LOCAL_PATH}
showmount -e $NFS_IP

 

 

 

번외

nfs-utils를 설치하지 않고 마운트를 시도하면 다음과 같은 에러가 발생한다. nfs-utils를 설치한 후 마운트를 해줬더니 마운트가 잘 되었다.

mount: /mnt/nas/data: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program.
반응형