1. 개요

NFS 환경에서 마운트 방법을 알아본다.

  • 명령줄 mount (리붓시 날라감)
  • /etc/fstab 파일 (영구 적용)
  • autofs (반영구 적용으로 인한 자원 효율적 사용, 동적으로 자동 마운트. 권장)

2. 테스트 환경 준비

RHCSA 실습으로 주어진 랩 환경에서 하다가, 본인 로컬 VM에서 바로 하려니까 기본 환경을 준비하지 않아 안되었던 부분이 있었다.

2.1 NFS 서버 환경

1
2
# yum install -y nfs-utils
# systemctl enable --now nfs-server.service

대부분 기본으로 설치되어 있는 nfs 패키지를 설치하고,

nfs-server 서비스 실행

1
2
3
4
5
6
# mkdir -p /public_NAS/{admin,manager,employee}
# tree /public_NAS
/public_NAS
├── admin
├── employee
└── manager

/public_NAS 에 admin, manager, employee 디렉토리 생성

1
2
# echo "/public_NAS *(rw)" >> /etc/exports
# exportfs -r

exports 파일에 NFS 서버가 공유할 디렉토리 설정

1
2
# firewall-cmd --add-service=nfs --permanent
# firewall-cmd --reload

nfs 방화벽 허용 정책

1
2
3
4
# exportfs -v
# showmount -e <NFS Server ip>
Export list for servera:
/public_NAS *

exportfs -v : exportfs 파일 정상 등록 여부 확인

showmount -e : NFS Server에서 공유하는 디렉토리 리스트 확인

2.2 NFS 클라이언트 환경

1
2
# yum install -y nfs-utils
# systemctl enable --now nfs-client.service

RHEL8은 기본적으로 nfs-client 서비스는 자동 시작 되어 있다.

1
2
3
# showmount -e <NFS Server ip>
Export list for servera:
/public_NAS *

client 에서 NFS Server로 조회 결과가 좋다.

3. NFS 마운트

3.1 mount 명령줄

1
2
3
4
5
6
7
8
9
10
# mkdir /shares
# mount -t nfs4 <NFS Server ip>:/public_NAS /shares
# mount | grep nfs4
x.x.x.x:/public_NAS on /shares type nfs4 (rw,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=x.x.x.x,local_lock=none,addr=x.x.x.x)

# tree /shares
/shares
├── admin
├── employee
└── manager

mount가 쉽게 잘 되었다. 재기동하면 날라간다~

아래 다른 방법을 테스트하기 위해서는…

1
2
# cd /tmp
# umount /shares

3.2 /etc/fstab

1
2
3
# echo "<NFS Server ip>:/public_NAS /shares nfs4 defaults,rw,sync 0 0" >> /etc/fstab
# systemctl daemon-reload
# mount /shares

rw는 기본 옵션이다. sync옵션은 그냥 갑자기 넣었다. 이렇게 옵션을 넣을 수 있다고 양식을 보여주기 위함.

3.3 autofs

1
# yum install -y autofs

(1). 직접맵

1
# echo "/- /etc/directMap" >> /etc/auto.master.d/shares.autofs

/- : 해당 문자 자체가 직접 맵. NFS Server와 디렉토리를 일대일(1:1)로 연결한다는 뜻.

1
2
# echo "/local/admin -rw,sync,fstype=nfs4 <NFS Server ip>:/public_NAS/admin" > /etc/directMap
# systemctl enable --now autofs

/local/admin : 해당 디렉토리는 만들지 않는다. autofs 가 자동 생성한다.

(2). 간접맵

1
# echo "/locals /etc/indirectMap" >> /etc/auto.master.d/shares.autofs

/locals 디렉토리를 간접맵으로 연결 한다. 간접맵과 달리 일대일이 아니라, 다수의 디렉토리를 자동으로 마_운트 한다.

1
# echo "* -rw,sync,fstype=nfs4 <NFS Server ip>:/public_NAS/&" > /etc/indirectMap

/locals 디렉토리에서 요청하는 디렉토리(*)를 /public_NAS/ 아래에서(&) 가져온다.

1
2
3
4
5
6
7
8
9
# ll /locals/{admin,manager,employee}
/locals/admin:
합계 0

/locals/employee:
합계 0

/locals/manager:
합계 0

/locals 디렉토리를 만들지 않았고, autofs 를 재실행 하지 않고도 자동 마운트 되었다.

다만 디렉토리명을 정확히 알아야만 접근 및 자동 마운트가 된다.

1
2
3
4
5
# mount | grep /locals
/etc/indirectMap on /locals type autofs (rw,relatime,fd=26,pgrp=32434,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=77703)
<NFS Server ip>:/public_NAS/admin on /locals/admin type nfs4 (rw,relatime,sync,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.0.16,local_lock=none,addr=<NFS Server ip>)
<NFS Server ip>:/public_NAS/manager on /locals/manager type nfs4 (rw,relatime,sync,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.0.16,local_lock=none,addr=<NFS Server ip>)
<NFS Server ip>:/public_NAS/employee on /locals/employee type nfs4 (rw,relatime,sync,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.0.16,local_lock=none,addr=<NFS Server ip>)