Web Server

CentOS8에서 NginX를 이용해 NFS 서버 구축

gamjadori 2024. 1. 31. 16:52
728x90

<NFS란?>

  • 여러 컴퓨터 간에 파일 및 디렉터리를 공유하기 위한 분산 파일 시스템 프로토콜
  • 유닉스와 유닉스 계열의 운영체제에서 사용되며, 서버와 클라이언트 간의 효율적인 파일 공유 및 접근을 지원

<NFS 서버 구축하는 방법>

마운트를 이용하여 서버 간 파일 공유

  • NFS 서버: 192.168.202.3 / 클라이언트 서버: 192.168.113.10

<NFS 서버 (192.168.202.3) 설정>

1. NFS 서비스 설치

yum install nfs-utils
systemctl start nfs-server
systemctl enable nfs-server
systemctl status nfs-server

2. 마운트 대상 폴더 (/etc/mkdir /usr/share) 생성

  • 실습자가 다른 곳으로 지정해도 됨.

3. exports 폴더 작성 및 확인

cd /etc
vi exports

<vi 편집 내용>

/usr/share    192.168.113.*   (rw,root_squash,all_squash,sync)
>> 괄호 안의 옵션은 설정에 따라 다르게
  • 마운트 할 위치 + 마운트 할 서버의 IP 주소 (옵션 추가)

<옵션>

  • ro : 읽기 전용
  • rw : 읽기, 쓰기
  • root_squash : 클라이언트가 root 권한 획득 금지
  • no_root_squash : 클라이언트가 root 권한 획득 가능, 파일 생성시 클라이언트의 권한으로 생성
  • sync : 변경 사항이 커밋된 후에만 요청에 응답(안정적인 저장)

>> exportfs -v로 마운트 목록 작성 확인

4. 방화벽 설정

firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --reload
firewall-cmd --permanent --list-all

5. hosts.allow 파일 작성

vi /etc/hosts.allow

>> 파일 맨 아래에 ALL:ALL 추가

 

<클라이언트 서버(192.168.113.10) 설정>

1. NFS 서비스 설치

yum install nfs-utils
systemctl start nfs-server
systemctl enable nfs-server
systemctl status nfs-server

2. 방화벽 설정

firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --reload
firewall-cmd --permanent --list-all

 

3. hosts.allow 파일로 특정 IP 접속 허용

vi /etc/hosts.allow

 

4. 마운트

showmount -e 192.168.202.3
mount -t nfs 192.168.111.100:/usr/share /usr/share

 

<결과 확인>

  • 명령어 <df -h>로 마운트 상태 확인

system                Size  Used Avail Use% Mounted on
devtmpfs                  384M     0  384M   0% /dev
tmpfs                     400M     0  400M   0% /dev/shm
tmpfs                     400M  6.6M  393M   2% /run
tmpfs                     400M     0  400M   0% /sys/fs/cgroup
/dev/mapper/cl-root        17G  4.0G   14G  24% /
/dev/nvme0n1p1            976M  133M  777M  15% /boot
tmpfs                      80M   28K   80M   1% /run/user/42
tmpfs                      80M  3.5M   77M   5% /run/user/0
/dev/sr0                  6.7G  6.7G     0 100% /run/media/root/CentOS-8-BaseOS-x86_64
192.168.202.3:/usr/share   17G  4.0G   14G  24% /usr/share

>> 제일 하단의 192.168.~ 부분으로 확인 가능