[Linux] NFS 서버 구축

반응형
반응형

NFS는 네트워크 파일 시스템으로, 

다른 서버의 파일 시스템을 자신의 서버에 붙여서 디렉터리처럼 사용할 수 있게 해주는 것입니다.   

 

 

서버 작업

nfs-utils가 설치가 이미 되어있는지 확인

[root@linux-1 ~]# rpm -qa | grep nfs-utils

 

nfs-utils 설치

[root@linux-1 ~]# yum -y install nfs-utils

 

설치 확인

[root@linux-1 ~]# rpm -qa | grep nfs-utils
nfs-utils-1.3.0-0.66.el7.x86_64

 

/etc/exportfs 파일에 아래 내용을 추가했습니다.

/home/share_dir 192.168.56.102 (rw,sync) # [공유할 경로] [접근 대역 또는 IP] [옵션]

rw : 읽기, 쓰기 가능

sync : 파일 시스템이 변경되면 즉시 동기화한다

 

nfs 데몬 구동

[root@linux-1 share_dir]# systemctl start nfs

 

nfs, rcp.statd, rpc.idmapd, rpcbind, rpc.mountd 총 다섯 종류의 프로세스가 떠있습니다.

rpcuser   1530     1  0 20:46 ?        00:00:00 /usr/sbin/rpc.statd
root      1531     1  0 20:46 ?        00:00:00 /usr/sbin/rpc.idmapd
rpc       1533     1  0 20:46 ?        00:00:00 /sbin/rpcbind -w
root      1540     1  0 20:46 ?        00:00:00 /usr/sbin/rpc.mountd
root      1548     2  0 20:46 ?        00:00:00 [nfsd]
root      1549     2  0 20:46 ?        00:00:00 [nfsd]
root      1550     2  0 20:46 ?        00:00:00 [nfsd]
root      1551     2  0 20:46 ?        00:00:00 [nfsd]
root      1552     2  0 20:46 ?        00:00:00 [nfsd]
root      1553     2  0 20:46 ?        00:00:00 [nfsd]
root      1554     2  0 20:46 ?        00:00:00 [nfsd]
root      1555     2  0 20:46 ?        00:00:00 [nfsd]
root      1544     2  0 20:46 ?        00:00:00 [nfsd4_callbacks]

 

LISTEN 포트는 총 4개가 떠있네요

[root@linux-1 share_dir]# netstat -lntp | grep 2049
tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -
[root@linux-1 share_dir]# netstat -lntp | grep rpc
tcp        0      0 0.0.0.0:40245           0.0.0.0:*               LISTEN      4854/rpc.statd
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      4856/rpcbind
tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      6403/rpc.mountd

 

방화벽 설정

클라이언트에서 서버로 접근하기 위해서는 해당 포트를 열어주어야 한다

실제 클라이언트 서버에서 마운트 시 필요한 포트는 "2049" 하나이다. 

 

아래 명령어로 2049 포트를 열어 줍니다

firewall-cmd --add-port=2049/tcp

 

적용 확인

[root@linux-1 share_dir]# iptables -L | grep nfs 
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:nfs ctstate NEW,UNTRACKED

 

 

클라이언트 작업

 

마운트 할 경로를 생성합니다.(마운트 포인트 생성)

[root@linux-2 ~]# mkdir /mnt/data_dir

 

아래 명령어로 마운트 합니다.

[root@linux-2 ~]# mount -t nfs 192.168.56.101:/home/share_dir /mnt/data_dir

 

연결 확인

[root@linux-2 ~]# df -h 
Filesystem                      Size  Used Avail Use% Mounted on 
devtmpfs                        909M     0  909M   0% /dev 
tmpfs                           919M     0  919M   0% /dev/shm 
tmpfs                           919M  8.7M  911M   1% /run 
tmpfs                           919M     0  919M   0% /sys/fs/cgroup 
/dev/sda3                       7.0G  2.4G  4.7G  34% / 
192.168.56.101:/home/share_dir  7.0G  2.4G  4.7G  34% /mnt/data_dir 
/dev/sda1                      1014M  142M  873M  14% /boot 
tmpfs                           184M     0  184M   0% /run/user/0 

 

mount 명령어로 설정 상태를 확인할 수 있습니다.

[root@linux-2 ~]# mount | grep data_dir
192.168.56.101:/home/share_dir on /mnt/data_dir type nfs4 (rw,relatime,vers=4.1,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.56.102,local_lock=none,addr=192.168.56.101)

 

반응형

댓글

Designed by JB FACTORY

loading