IT/linux

[linux] nfs 설치, 설정

주니- 2023. 3. 30. 13:22

환경 : Ubuntu 20.04

# Server (10.109.0.2)
apt install nfs-utils
apt install nfs-kernel-server

# create share directory
mkdir /share
chmod 777 /share

# firewalld or ufw
ufw allow 2049/tcp,udp

firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-port=2049/tcp
firewall-cmd --permanent --add-port=2049/udp
firewall-cmd --reload

# chage conf
vi /etc/exports
#####
# (mount point)    (host, option)
# /appnas         *(rw,sync,no_root_squash,no_subtree_check) # all open
/appnas         10.109.0.7(rw,sync,no_root_squash,no_subtree_check)
/appnas         10.109.0.3(ro,rw,sync,no_root_squash)
#####

# export command
exportfs -ra
exportfs -v

# hosts (10.109.0.x)
# ubuntu install
apt install nfs-common
# CentOS install
yum install nfs-utils

# create mount directory
mkdir /data/nfs

# nfs mount
mount -t nfs ${server_ip}:/${server mount point} /${host mount point}
mount -t nfs 10.109.0.2:/appnas /data/nfs

# fstab
vi /etc/fstab
#####
# ${server_ip}:/${server mount point}     ${host mount point}                ${mount type}     ${option}        ${dump option} ${filesystem}
10.117.2.17:/appnas     /appnas/                nfs     defaults,_netdev        0 0
#####
# error (nfs)
mount bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program

# solution
# ubuntu
apt install nfs-common
# CentOS
yum install nfs-utils

# error (mount, umount)
umount device is busy

# solution
umount -l /${directory}
umount -f /${directory}