본문 바로가기

자격증/리눅스 마스터 1급

Part3) 네트워크 및 서비스의 활용 - 네트워크 서비스 | 파일관련 서비스 | NFS, FTP

NFS(Network File System) 서버 관리

1) NFS의 정의

•1985년 미국의 썬 마이크로즈시스템즈 사에서 개발되었고, 파일 서버의 표준으로 정착되었다.

•정보 통신 네트워크에 접속되어 있는 다른 컴퓨터에 있는 파일이나 파일 시스템을 공용하기 위한 분산 파일 공유 시스템 소프트웨어이다.

•컴퓨터의 기종이나 운영체제가 다른 환경의 컴퓨터에 분산되어 있는 파일을 공용하기 위한 것이다.

NFS 클라이언트가 있어야 하며 원격지 컴퓨터에는 NFS 서버가 설치되어있어야 한다. (TCP/IP 사용 [※초기엔 UDP가 사용되기도 했음])


※삼바는 리눅스와 윈도우 간에 파일 및 디렉터리, 하드웨어를 공유하기 위한 프로토콜이었는데, 리눅스에선 이보다 NFS 프로토콜을 이용하여 동일한 O/S 간에 파일을 공유할 수 있도록 하고 있다.


2) NFS 서버 설정하기

*NFS 서버 설정

•NFS 서버는 항상 클라이언트가 자신의 자원을 마운트할 수 있도록 준비하고 있어야 하는데 이러한 과정을 'exporting'이라 한다. 따라서 클라이언트가 항상 NFS 데몬인 mounted, nfsd 두 데몬이 프로세스 상에서 작동할 수 있도록 설정해야 한다.


NFS데몬

• /usr/sbin/rpc.nfsd :  클라이언트의 파일 시스템 요청을 처리

• /usr/sbin/rpc.mountd :  NFS접근 정보에 대한 요청과 파일 시스템 마운트 요청에 대해 응답을 해주는 RPC 서버


Exporting 설정: '/etc/exports'

 옵션

 기능 

 root_squash 

 클라이언트에서 루트를 서버상에 nobody로 매핑 

 no_root_squash

 서버와 클라이언트가 root 계정을 사용 

 all_squash 

 접근하는 모든 사용자(root 포함)의 권한을 nobody로 매핑

 ro

 공유된 자원을 읽기 전용으로 마운트 

 rw

 공유된 자원을 읽기/쓰기로 마운트 

 insecure

 인증되지 않은 액세스도 가능하도록 함 

 link_relative

 절대 심볼릭 링크를 상대 심볼릭 링크로 변경 시 사용 


export 파일 예시

root@bjkim:~# cat /etc/export
/data 192.168.5.0/24(rw,no_root_squash)
/data1 192.168.5.224(ro)
/data2 192.168.5.0/225.255.255.0(rw)

2행: data 디렉터리에 대해 root권한으로 읽기쓰기가 가능하다.

•3행: data1 디렉터리에 대해 읽기전용으로 접근 가능하다.

•4행: data2 디렉터리에 대해 읽기쓰기로 접근 가능하다.



NFS 실행과 종료

root@bjkim:~# /etc/rc.d/init.d/nfs restart
NFS mountd를 종료중:                                [ OK ]
NFS 데몬을 종료 중:                                 [ OK ]
NFS 서비스를 종료 중:                               [ OK ]
NFS 서비스를 시작 중:                               [ OK ]
NFS 쿼터를 시작 중:                                 [ OK ]
NFS 데몬을 시작 중:                                 [ OK ]
NFS mountd를 시작 중:                               [ OK ]



*클라이언트 NFS 마운트

•클라이언트에서 NFS 서버를 마운트하기 위해선 portmap 데몬이 항상 동작하고 있어야 하며, 그런 다음 mount 명령이나 부팅 시 자동으로 마운트 되도록 /etc/fstab 파일을 이용한다.

※portmap 데몬: RPC 연결에 관여하는 데몬으로 RPC 서버가 어떤 포트를 Listen 하고 있어야 하고 데이터를 기다려야 하는지을 알려줌.

마운트 명령어
# mount [-t nfs] 서버:디렉터리 /마운트위치


마운트 예시
root@bjkim:~# mount -t nfs 192.168.5.13:/home/bjkim /mnt/linux

 ▲NFS 서버 주소는 192.168.5.13, 공유된 디렉터리는 /home/bjkim 일때, 이 디렉터리를 로컬 시스템의 /mnt/linux 디렉터리로 마운트 할때 명령어



부팅 시 자동으로 마운트 설정 파일 :  '/etc/fstab'

root@bjkim:~# cat /etc/fstab
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tmpfs                     /dev/shm                tmpfs   defaults        0 0
devpts                    /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                     /sys                    sysfs   defaults        0 0
proc                      /proc                   proc    defaults        0 0
192.168.5.13:/home/bjkim  /mnt/linux              nfs     timeo=25

NFS 자동 마운트 시 사용되는 옵션

 옵션 

 의미 

 rsize

 NFS 서버로 부터 읽어들이는 바이트 수를 지정하는 것으로 기본은 1024바이트

 wszie

 NFS 서버에 기록할 때 사용하는 바이트 수를 지정하는 것으로 기본은 1024바이트

 timeo 

 클라이언트에서 타임아웃이 발생되고 나서, 다시 재전송 요구를 보낼 때 사용하는 시간

 retrans 

 재전송 횟수를 지정

 port 

 NFS 서버에 연결할 때 사용하는 포트 번호 지정

 fg 

 NFS 서버에 타임아웃이 발생되면 즉각 접속을 중지

 intr 

 타임아웃이 발생하면 신호를 보내 NFS 호출을 인터럽트

 hard 

 타임아웃이 발생되는 "server not responding" 메세지를 출력하고 계속 재시도

 soft

 타임아웃이 발생하면 I/O 에러 표시  



3) NFS 유틸리티와 보안


*NFS 유틸리티


[1] showmount

-mount 데몬에 NFS 서버에 대해 질의를 하여 사용중인 상태를 표시한다. 즉, NFS 클라이언트에서 NFS 서버에 익스포트된 정보를 확인할때 사용한다.


ex) # showmount -e nfs_server


 옵션

 의미 

 -a, --all 

 클라이언트의 호스트 이름과 마운트된 디렉토리를 '호스트:디렉토리' 포맷으로 출력한다.

 -d, --directories

 클라이언트에서 사용하는 디렉토리 이름만을 출력한다.

 -e, --exports 

 NFS 서버의 export 항목의 리스트를 출력한다.

 -h, --help 

 간단한 도움말을 출력한다. 

 -v, --version 

 현재 사용중인 showmount의 버전 정보를 출력한다. 

 --no-headers

 출력에서 요약 정보를 생략하고 출력한다. 


[2] nfsstat

-NFS 서버와 클라이언트의 동작 상태를 보여주는 유틸리티이다.

 옵션 

 의미 

 -c 

 클라이언트의 상태만을 보여주는 옵션이다. 

 -s 

 서버측의 상태만을 보여주는 옵션이다. 

 -W 

 넓은 포맷으로 출력을 조정하는 옵션으로 일반적으로 -c, -s 옵션과 함께 사용한다. 

 -w 

 일정한 지연 시간을 가지고 간단한 NFS 서버와 클라이언트의 상태를 보여주는 옵션이다. 


[3] nhfsstone

-NFS를 벤치마킹하기 위한 프로그램으로 시간당 부하수, 전송률, 실패율 등의 NFS에 관련된 데이터를 제공한다.

 옵션

 의미 

 -v 

 자세한 출력을 제공하는 옵션이다. 

 -t secs 

 설정한 시간(초) 동안의 동작 시간과 부하를 보여준다. 

 -c 

 NFS에 발생시킬 요청의 총 개수이다. 

 -l 

 초당 NFS 호출을 발생시킬 부하의 개수(기본 값은 30)이다. 


*NFS 보안

보안을 위해선 export파일을 잘 설정해야하는데, 기본적으로 hosts.deny에 rpc.mountd portmap을 모두 금지하고, hosts.allow에 허용하고자 하는 호스트를 입력하여 최소한의 보안 설정을 하여야 한다.



FTP 서버 관리


1) FTP 서버의 정의

•TELNET과 함께 WWW 이전의 인터넷 대표 서비스로서 인터넷으로 연결된 곳이면 어디에서나 원하는 파일을 올려놓을 수도, 가져올 수 있도록 하는 기능을 가진 서비스를 제공하는 서버


2) vsftpd 서버 설정하기


①vsftpd 설치 및 실행


[1] 설치

root@bjkim:~# yum install vsftpd


[2] 설치되는 파일


 파일명 

 설명 

 /etc/logrotate.d/vsftpd.log 

 로그 로테이션 설정 파일 

 /etc/pam.d/vsftpd 

 PAM 인증 파일 

 /etc/vsftpd/ftpusers 

 FTP 서버에 로그인할 수 없는 사용자 목록 

 /etc/vsftpd/user_list

 FTP 서버에 로그인할 수 있는 사용자 목록 

 /etc/vsftpd/vsftpd.conf 

 vsftpd 설정 파일 

 /usr/sbin/vsfptd 

 vsftpd 데몬 파일 

 /usr/shard/doc/vsftpd-2.0.5 

 각종 설정 및 설치 문서 포함 


[3] 데몬 실행

root@bjkim:~# /etc/init.d/vsftpd restart
vsftpd를 종료 중:                             [ OK ]
vsftpd에 대한 vsftpd을 시작 중:               [ OK ]



②vsftpd 서버 환경 설정 :  '/etc/vsftpd/vsftpd.conf' 

root@bjkim:~# cat /etc/vsftpd/vsftpd.conf # Example config file /etc/vsftpd/vsftpd.conf # # The default compiled in settings are fairly paranoid. This sample file # loosens things up a bit, to make the ftp daemon more usable. # Please see vsftpd.conf.5 for all compiled in defaults. # # READ THIS: This example file is NOT an exhaustive list of vsftpd options. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's # capabilities. # # Allow anonymous FTP? (Beware - allowed by default if you comment this out). anonymous_enable=YES # # Uncomment this to allow local users to log in. local_enable=YES # # Uncomment this to enable any form of FTP write command. write_enable=YES # # Default umask for local users is 077. You may wish to change this to 022, # if your users expect that (022 is used by most other ftpd's) local_umask=022 # # Uncomment this to allow the anonymous FTP user to upload files. This only # has an effect if the above global write enable is activated. Also, you will # obviously need to create a directory writable by the FTP user. #anon_upload_enable=YES # # Uncomment this if you want the anonymous FTP user to be able to create # new directories. #anon_mkdir_write_enable=YES # # Activate directory messages - messages given to remote users when they # go into a certain directory. dirmessage_enable=YES # # The target log file can be vsftpd_log_file or xferlog_file. # This depends on setting xferlog_std_format parameter xferlog_enable=YES # # Make sure PORT transfer connections originate from port 20 (ftp-data). connect_from_port_20=YES # # If you want, you can arrange for uploaded anonymous files to be owned by # a different user. Note! Using "root" for uploaded files is not # recommended! #chown_uploads=YES #chown_username=whoever # # The name of log file when xferlog_enable=YES and xferlog_std_format=YES # WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log #xferlog_file=/var/log/xferlog # # Switches between logging into vsftpd_log_file and xferlog_file files. # NO writes to vsftpd_log_file, YES to xferlog_file xferlog_std_format=YES # # You may change the default value for timing out an idle session. #idle_session_timeout=600 # # You may change the default value for timing out a data connection. #data_connection_timeout=120 # # It is recommended that you define on your system a unique user which the # ftp server can use as a totally isolated and unprivileged user. #nopriv_user=ftpsecure # # Enable this and the server will recognise asynchronous ABOR requests. Not # recommended for security (the code is non-trivial). Not enabling it, # however, may confuse older FTP clients. #async_abor_enable=YES # # By default the server will pretend to allow ASCII mode but in fact ignore # the request. Turn on the below options to have the server actually do ASCII # mangling on files when in ASCII mode. # Beware that on some FTP servers, ASCII support allows a denial of service # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd # predicted this attack and has always been safe, reporting the size of the # raw file. # ASCII mangling is a horrible feature of the protocol. #ascii_upload_enable=YES #ascii_download_enable=YES # # You may fully customise the login banner string: #ftpd_banner=Welcome to blah FTP service. # # You may specify a file of disallowed anonymous e-mail addresses. Apparently # useful for combatting certain DoS attacks. #deny_email_enable=YES # (default follows) #banned_email_file=/etc/vsftpd/banned_emails # # You may specify an explicit list of local users to chroot() to their home # directory. If chroot_local_user is YES, then this list becomes a list of # users to NOT chroot(). #chroot_local_user=YES #chroot_list_enable=YES # (default follows) #chroot_list_file=/etc/vsftpd/chroot_list # # You may activate the "-R" option to the builtin ls. This is disabled by # default to avoid remote users being able to cause excessive I/O on large # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume # the presence of the "-R" option, so there is a strong case for enabling it. #ls_recurse_enable=YES # # When "listen" directive is enabled, vsftpd runs in standalone mode and # listens on IPv4 sockets. This directive cannot be used in conjunction # with the listen_ipv6 directive. listen=YES # # This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6 # sockets, you must run two copies of vsftpd with two configuration files. # Make sure, that one of the listen options is commented !! #listen_ipv6=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES

 옵션

 의미 

 anonymous_enable = YES 

 ftp와 anonymous 계정을 이용한 익명 로그인을 허용할 것인지 설정 

 anon_upload_enable = NO 

 write_enable 옵션이 허용될 때 익명 FTP 접속 시 익명의 사용자가 업로드 가능한 디렉터리에서 파일을 업로드할 수 있도록 설정해 주는 옵션

 anon_mkdir_write_enable = NO 

 write_enable=YES 시 쓰기 가능한 디렉터리 내에서 새로운 디렉터리를 생성할 수 있도록 할 것인가 설정

 deny_email_enable = NO

 익명 FTP 서버에서 익명 계정이 로그인 할 때 banned_email_file옵션으로 지정된 파일에 포함된 이메일 주소 형태로는 로그인 할 수 없도록 할 수 있는데, 이 기능을 허용할지 여부 

 banned_email_file = /etc/vsfptd/banned-emails 

 익명 접속 시 허용하지 않을 이메일 패스워드 형태를 담고 있는 파일을 명시하는 옵션

 [deny_email_enable 옵션과 함께 사용]

 anon_max_rate = 0 

 익명 접속 시 다운로드 가능한 최대 전송율을 지정하는 옵션으로, 기본값은 '0' 으로 무제한을 의미 

 anon_root = 경로

 익명 로그인이 되었을 때 위치할 홈 경로를 명시하는 설정으로, 경로가 이상하면 무시됨

 local_enable = YES

 로컬 호스트상에 있는 사용자의 로그인을 허용할 것인가를 설정 

 write_enable = YES

 STOP(저장), DELE(삭제), RNFR(이름변경), RMD(경로삭제) 같은, 파일 변경 FTP 명령 사용 허용 여부

 local_umask = 022 

 파일 생성 시 파일 퍼미션에 적용될 umsak 값 지정 

 dirmessage_enable = NO 

 사용자가 새로운 디렉터리로 이동 시 그 디렉터리에 있는 메세지 파일을 사용자에게 보여줄 것 인지 설정 

 userlist_enable = NO 

 'userlist_file' 옵션으로 명시된 파일안에 있는 계정들만 로그인을 허용할 것인가를 설정 

 listen_port = 21 

 vsftpd 데몬이 외부 접속 요청에 통신할 ftp 포트를 설정 

 virtual_use_local_privs = NO 

 가상 사용자 접속 설정에서 사용되는 옵션으로 익명 접속 사용자와 동일한 권한을 가진 가상 사용자의 권한을 로컬 사용자와 같은 권한을 가질 수 있도록 설정 

 deny_file 

 업로드/다운로드를 금지할 파일 형태를 지정하는 옵션 [ex. deny_file={*.exe,*.pif,*.mpg} 

 hide_file 

 디렉터리/파일 목록에서 숨길 파일 형태를 지정 

 max_clients = 100

 vsftpd 서버에 접속 할 수 있는 클라이언트의 최대 수를 제한 

 max_per_ip = 0 

 호스트당 접속할 때 최대 접속수를 지정 

 chroot_local_user = NO

 로컬 시스템에 존재하는 사용자들이 자신의 디렉터리에 대해서 chroot를 가질 것인가를 설정 

 hide_ids = NO 

 디렉터리 목록에서 사용자의 ID와 그룹의 ID를 보여주지 않고, 모두 ftp를 표시할 것인가를 설정하는 옵션으로, 이 옵션을 YES로 하면 모든 파일의 소유권은 ftp로 표시 

 pasv_enable = YES

 수동 데이터 연결 모드(Passive mode)로 지원할 것인지 설정

 pasv_max_port / pasv_min_port 

 수동 모드로 데이터 연결 시 할당될 최대 및 최소 포트를 설정

 [기본값: 0으로, 포트는 일반적으로 50000~60000포트 사이로 지정]

 ftp_data_port = 20 

 포트 형식의 데이터 연결 시 사용할 포트 지정 

 connect_from_port_20 = YES 

 데이터 전송 포트를 20번으로 사용 할 것인가를 설정 [서버를 능동모드로 운영 시 활성화 필수]

 connect_timeout = 60

 클라이언트가 서버의 제어포트에 연결되었을 때 타임아웃 시간을 설정

 xferlog_enable = YES

 파일 송수신 결과를 xferlog_file 옵션으로 지정된 로그 파일에 저장할 것인가를 지정 




3) proftpd 서버 설정하기


①proftpd 설치 

root@bjkim:~#yum install epel-release
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
root@bjkim:~# yum install proftpd



②proftpd 서버 환경 설정 :  '/etc/proftpd.conf' 


 옵션

 의미 

 ServerName  "ProFTPD server"

 사용자가 FTP 서버 접속 시 FTP 서버이름이 무엇인지 출력

 ServerType   standalone

 # ServerType   inetd

 proftpd 서버를 실행시키는 방법으로, standalone과 xinetd에 의해 실행되는 inetd 방식이 있음

 DefaultServer   on

 가상 호스트 설정 블록에서 설정된 IP가 아닌 다른 IP로부터 연결이 있을때, 기본으로 사용될 서버 설정을 해줌

 DefaultRoot   / 또는 ~/

 '/'로 설정 시  '/'디렉터리 까지 접근 가능하며, ~/로 설정 시 일반 계정의 홈디렉터리 까지 접근 가능 

 Port 21 

 standalone 모드로 동작 시 사용자가 FTP와 연결할 포트를 지정 

 Umask 022 

 파일 생성 시 파일 퍼미션에 적용될 umask 값

 MaxInstances 30

 standalone 모드일 때 최대 접속 가능한 사용자 수를 지정 

 User nobody

 Group nobody 

 proftpd 서버 실행 시에 생성되는 프로세스의 User와 Group를 지정 

 <Directry /*>

 AllowOverwrite on

 </Directory>

사용자가 FTP 서버에 접속하여 새로 전송하려고 하는 파일이 기존에 있는 파일이 있을때 어떻게 할 것인가의 설정 

 <Anonymous ~ftp>

 User                     ftp

 Group                   ftp

 UseAlias                anonymous ftp

 MaxClients             10

 MaxClientsPerHost   2

 DisplayLogin           welcome.msg

 RequireValidShell     on

 </Anonymous>

 < 익명 사용자 접속 환경설정 >

 User, Group : 디렉터리에 대한 시제 권한은 ftp User가 가지게 됨

 UseAlias : 사용자가 anonymous 계정으로 접속하면 ftp 계정으로 접근하게 됨.

 MaxClients : 클라이언트들이 최대로 접속 할 수 있는 수

 MaxClientsPerHost : 한 호스트당 접속 개수는 2명

 DisplayLogin : 'cd'명령을 이용해 처음으로 다른 디렉터리로 접근할 때 접근 디렉터리에 .message file이 있으면 file의 내용을 보여줌

 RequireValidShell : anonymous User로 접속을 하고자 한다면 이 설정을 off로 해주어야 login을 할 수 있다.