NFS

yoni·2023년 4월 17일

Linux

목록 보기
11/16

NFS vs CIFS

nfs = unix, linux
cifs = windows

File Sharing via NFS

  • 공유 파일 시스템
  • 버전이 여러개 존재
    • NFS v1/v2 : UDP 프로토콜
      • 1:다
      • 빠르다
      • 복구 기능 X, 대용량 파일 전송 불가 WAN환경에서 적합 X)
    • NFS v3 : TCP 기반
      • 64-bit file 지원
      • 2Gb이상의 파일 전송 가능,
      • WAN 환경 적합
      • but 보안관련 문제 존재
      • port 번호 여러개 쓰임 -> 방화벽 여러개 열어야 함. (불편)
    • NFS v4 : TCP 기반
      • 보안 관련 문제 보완
      • TCP port 2049 하나로 통합

NFS clients

  • showmount -e server(nfs server ip)
    • mount -t nfs nfs서버ip:/공유디렉토리 마운트포인트

@@Physical computer
> nfs utils 패키지 있는지 확인
[root@station14 ~]# rpm -qa | grep nfs
libnfsidmap-0.25-15.el7.x86_64
nfs4-acl-tools-0.3.3-15.el7.x86_64
nfs-utils-1.3.0-0.33.el7_3.x86_64

> 실습 서버가 공유하고 있는 공유 디렉토리 목록 출력
[root@station14 ~]# showmount -e 59.29.224.181
Export list for 59.29.224.181:
/export/courserepos *
/export/autoyast    *
/export/home        *
/export/tmp         *
/export/netinstall  *
/export/kickstart   *

> /data1이라는 서브 디렉토리 생성
[root@station14 ~]# mkdir /data1

> 공유 디렉토리에 /data1 마운트
[root@station14 ~]# mount -t nfs 59.29.224.181:/export/netinstall /data1

> df -h 확인
[root@station14 ~]# df -h
Filesystem                        Size  Used Avail Use% Mounted on
/dev/mapper/vg0-root              8.0G  4.6G  3.5G  57% /
devtmpfs                          7.8G     0  7.8G   0% /dev
tmpfs                             7.8G   54M  7.8G   1% /dev/shm
tmpfs                             7.8G  712K  7.8G   1% /run
tmpfs                             7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda1                         494M  151M  344M  31% /boot
/dev/mapper/vg0-tmp              1014M   34M  981M   4% /tmp
/dev/mapper/vg0-var               2.0G  671M  1.4G  33% /var
/dev/sda3                         100G  4.9G   96G   5% /var/lib/libvirt/images
tmpfs                             1.6G   12K  1.6G   1% /run/user/0
59.29.224.181:/export/netinstall  931G   14G  917G   2% /data1  --this check!!

> /data1 디렉토리에 mount된 모습
[root@station14 ~]# ls /data1
CENTOS7  configs  postinstalldata  README.txt

자동 mount 방법

  • /etc/fstab 파일에 등록 -> 다음번 부팅할 때, 자동으로 마운트된다.

    • 첫번째 컬럼 : 59.29.224.181:/공유디렉토리명

    • 두번째 컬럼: /data1

    • 세번째 컬럼 : nfs

    • 네번째 컬럼 : mount옵션 -> default

    • 다섯번째 컬럼 : 백업안하므로 -> 0

    • 여섯번째 컬럼 : 파일시스템체크할것인가? 내것도 아니므로 체크 x ->0

    • 문제점: 재부팅할 때 /data1에 마운트할 것이라고 시도를 하는데, nfs 서버에 응답이 없을 경우 계속 시도를 해서 결국 시스템 부팅이 안되는 문제 발생.

    • AutoFS를 설정하여 마운트하는 것이 일반적!

    • 부팅할 때 마운트하는게 아니라, 필요할 때 자동으로 마운트

  • AutoFS

    • /etc/fstab처럼 부팅할 때 마운트하는게 아니라, 필요할 때 자동으로 마운트해줌.
    • 사용하지 않는 경우에는 자동으로 unmount하는 기능도 포함.

재실습!!!!!!

@@@VM -nfs server

[root@localhost ~]# vi /etc/exports
/nfsdata 192.168.122.0/24(rw,sync)



> nfs-server 상태 확인
[root@localhost ~]# systemctl status nfs-server
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

> nfs server start
[root@localhost ~]# systemctl start nfs-server

[root@localhost ~]# mkdir /nfsdata

[root@localhost ~]# cp /etc/*.conf /nfsdata

[root@localhost ~]# systemctl status nfs-server
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
   Active: active (exited) since Mon 2023-04-17 16:57:15 KST; 2min 4s ago
  Process: 8028 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 8026 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=1/FAILURE)
 Main PID: 8028 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service

Apr 17 16:57:15 localhost.localdomain systemd[1]: Starting NFS server and services...
Apr 17 16:57:15 localhost.localdomain exportfs[8026]: exportfs: Failed to stat /nfsdata: No such file or d...ory
Apr 17 16:57:15 localhost.localdomain systemd[1]: Started NFS server and services.
Hint: Some lines were ellipsized, use -l to show in full.

[root@localhost ~]# systemctl restart nfs-server

[root@localhost ~]# showmount -e localhost
Export list for localhost:
/nfsdata 192.168.122.0/24


@@@ physical computer - nfs client 역할
> data2 디렉토리 생성 후 vm에서 공유하는 디렉토리를 마운트 (재부팅 후에도 자동으로 마운트되도록 설정)
[root@station14 ~]# mkdir /data2

[root@station14 ~]# showmount -e vm의 ip

[root@station14 ~]# mkdir /data2

[root@station14 ~]# vi /etc/fstab
vm의ip:/nfsdata	/data2	nfs	defaults	0	0

[root@station14 ~]# mount -a

[root@station14 ~]# df -h



@@@ physical computer -nfs client
> cifs-utils와 samba있는지 검색
[root@station14 ~]#rpm -qa | grep 새-e samba -e cifs

[root@station14 ~]# smbclient -L 59.29.224.20 

[root@station14 ~]# mkdir /data3

[root@station14 ~]# moount -t cifs -o user=administrator //59.29.224.20/windata /data3

[root@station14 ~]# df -h 

[root@station14 ~]# ls /data3
profile
study log

0개의 댓글