Skip to Content
문서서버Samba 및 NFS

삼바/NFS 파일 공유

Samba는 Windows 시스템(SMB/CIFS 프로토콜)과 파일을 공유하는 데 사용되는 반면, NFS는 Linux 시스템 간의 파일 공유에 사용됩니다.

삼바 파일 공유

삼바 설치

sudo apt update sudo apt install samba samba-common-bin -y # Check version smbd --version # Check service status sudo systemctl status smbd nmbd

기본 구성

Samba 구성 파일은 /etc/samba/smb.conf입니다.

# Back up the original configuration sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak # Edit the configuration sudo nano /etc/samba/smb.conf

공개 공유(인증 없음)

# /etc/samba/smb.conf [global] workgroup = WORKGROUP server string = Ubuntu File Server security = user map to guest = Bad User dns proxy = no # Performance tuning socket options = TCP_NODELAY IPTOS_LOWDELAY read raw = yes write raw = yes max xmit = 65535 [public] path = /srv/samba/public browsable = yes read only = no guest ok = yes create mask = 0664 directory mask = 0775 force user = nobody
# Create the shared directory sudo mkdir -p /srv/samba/public sudo chown nobody:nogroup /srv/samba/public sudo chmod 0775 /srv/samba/public

인증된 공유

[shared] path = /srv/samba/shared browsable = yes read only = no guest ok = no valid users = @smbgroup create mask = 0660 directory mask = 0770 force group = smbgroup [homes] comment = Home Directories browsable = no read only = no valid users = %S create mask = 0600 directory mask = 0700
# Create a Samba user group sudo groupadd smbgroup # Create a system user and add to the group sudo useradd -M -s /usr/sbin/nologin smbuser sudo usermod -aG smbgroup smbuser # Set a Samba password (independent of the system password) sudo smbpasswd -a smbuser sudo smbpasswd -e smbuser # Enable the user # Create the shared directory sudo mkdir -p /srv/samba/shared sudo chown root:smbgroup /srv/samba/shared sudo chmod 0770 /srv/samba/shared

검증 및 시작

# Test configuration file syntax testparm # Restart services sudo systemctl restart smbd nmbd # Enable at boot sudo systemctl enable smbd nmbd # Open Samba ports in the firewall sudo ufw allow samba

클라이언트 연결

리눅스 클라이언트

# Install client tools sudo apt install cifs-utils smbclient -y # Browse shares smbclient -L //server-ip -U smbuser # Mount a share sudo mkdir -p /mnt/samba sudo mount -t cifs //server-ip/shared /mnt/samba -o username=smbuser,password=yourpass,uid=$(id -u),gid=$(id -g) # Auto-mount at boot (/etc/fstab) # First create a credentials file sudo tee /etc/samba/.credentials << 'EOF' username=smbuser password=yourpass EOF sudo chmod 600 /etc/samba/.credentials # Add an fstab entry echo "//server-ip/shared /mnt/samba cifs credentials=/etc/samba/.credentials,uid=1000,gid=1000,iocharset=utf8 0 0" | sudo tee -a /etc/fstab sudo mount -a

윈도우 클라이언트

파일 탐색기의 주소 표시줄에 다음을 입력합니다.

\\server-ip\shared

네트워크 드라이브를 매핑하려면:

  1. “이 PC”를 마우스 오른쪽 버튼으로 클릭 -> “네트워크 드라이브 연결”을 클릭합니다.
  2. \\server-ip\shared을 입력하세요.
  3. “다른 자격 증명을 사용하여 연결”을 확인하십시오.

NFS 파일 공유

NFS 서버 설치

sudo apt update sudo apt install nfs-kernel-server -y # Check status sudo systemctl status nfs-server

내보낸 디렉터리 구성

/etc/exports 편집:

# /etc/exports # Format: directory client(options) # Allow a single IP /srv/nfs/data 192.168.1.100(rw,sync,no_subtree_check) # Allow an entire subnet /srv/nfs/data 192.168.1.0/24(rw,sync,no_subtree_check,no_root_squash) # Allow multiple clients /srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check) 10.0.0.0/8(ro,sync,no_subtree_check) # Read-only share /srv/nfs/public *(ro,sync,no_subtree_check)

공통 옵션

옵션설명
rw읽기-쓰기 액세스
ro읽기 전용 액세스
sync동기식 쓰기(더 안전함)
async비동기식 쓰기(더 빠르지만 더 위험함)
no_subtree_check하위 트리 검사 비활성화(성능 향상)
no_root_squash클라이언트 루트 권한 유지
root_squash루트를 없음으로 매핑(기본값)
all_squash모든 사용자를 없음으로 매핑
anonuid/anongid익명 사용자의 UID/GID 지정

공유 생성 및 시작

# Create shared directories sudo mkdir -p /srv/nfs/data /srv/nfs/shared /srv/nfs/public sudo chown nobody:nogroup /srv/nfs/data /srv/nfs/shared /srv/nfs/public sudo chmod 0777 /srv/nfs/data # Apply the export configuration sudo exportfs -ra # View current exports sudo exportfs -v # Open NFS ports in the firewall sudo ufw allow from 192.168.1.0/24 to any port nfs sudo ufw allow from 192.168.1.0/24 to any port 111 # rpcbind

NFS 클라이언트

# Install the client sudo apt install nfs-common -y # View the server's export list showmount -e server-ip # Mount an NFS share sudo mkdir -p /mnt/nfs sudo mount -t nfs server-ip:/srv/nfs/data /mnt/nfs # Mount with NFS v4 sudo mount -t nfs4 server-ip:/srv/nfs/data /mnt/nfs # Auto-mount at boot (/etc/fstab) echo "server-ip:/srv/nfs/data /mnt/nfs nfs defaults,_netdev 0 0" | sudo tee -a /etc/fstab sudo mount -a

autofs를 사용한 자동 마운트

# Install autofs sudo apt install autofs -y # Configure the master map file echo "/mnt/nfs /etc/auto.nfs" | sudo tee -a /etc/auto.master # Configure the NFS map echo "data -rw,soft,intr server-ip:/srv/nfs/data" | sudo tee /etc/auto.nfs # Restart autofs sudo systemctl restart autofs # Access triggers automatic mounting ls /mnt/nfs/data

NFS 성능 튜닝

# Server: increase the number of NFS threads # Edit /etc/nfs.conf sudo tee -a /etc/nfs.conf << 'EOF' [nfsd] threads = 16 EOF # Client: optimized mount options sudo mount -t nfs -o rw,hard,intr,rsize=1048576,wsize=1048576,timeo=600 server-ip:/srv/nfs/data /mnt/nfs

삼바와 NFS 비교

특징삼바(SMB/CIFS)NFS
프로토콜중소기업/CIFSNFS v3/v4
사용 사례Windows + Linux 혼합Linux/Unix 시스템 간
인증별도의 비밀번호 데이터베이스UID/GID 기반 또는 Kerberos
성능좋음더 좋음(Linux 시스템 간)
구성 복잡성보통단순
윈도우 지원네이티브추가 소프트웨어 필요
ACL 지원전체기본
암호화된 전송SMB3 지원NFS v4 + Kerberos

문제 해결

# Samba logs sudo tail -f /var/log/samba/log.smbd # NFS checks showmount -e server-ip rpcinfo -p server-ip nfsstat # Check mounts mount | grep -E "(cifs|nfs)" df -h | grep -E "(cifs|nfs)" # Check ports ss -tlnp | grep -E "(445|139|2049|111)"