Install NFS Centos 7

  • NFS Server: server.example.com, IP address: 192.168.2.133
  • NFS Client: client.example.com, IP address: 192.168.2.134

Yum -y install vim perl mlocate  

Configure the Firewall  

yum -y install firewalld  

systemctl start firewalld.service
systemctl enable firewalld.service  

firewall-cmd --permanent --zone=public --add-service=ssh
firewall-cmd --permanent --zone=public --add-service=nfs
firewall-cmd --reload  

Installing NFS  

yum -y install nfs-utils  

systemctl enable nfs-server.service
systemctl start nfs-server.service  

client:  

yum -y install nfs-utils  

Exporting Directories on the Server    

mkdir /var/nfs
chown nfsnobody:nfsnobody /var/nfs
chmod 755 /var/nfs  

vim /etc/exports  

/home           192.168.2.134(rw,sync,no_root_squash,no_subtree_check)
/var/nfs        192.168.2.134(rw,sync,no_subtree_check)  

exportfs -a  

Mounting the NFS Shares on the Client  

client:  

mkdir -p /mnt/nfs/home
mkdir -p /mnt/nfs/var/nfs  

mount 192.168.1.133:/home /mnt/nfs/home
mount 192.168.1.133:/var/nfs /mnt/nfs/var/nfs  

df -h  

[root@client ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 28G 1.7G 26G 7% / devtmpfs 909M 0 909M 0% /dev tmpfs 919M 0 919M 0% /dev/shm tmpfs 919M 8.6M 910M 1% /run tmpfs 919M 0 919M 0% /sys/fs/cgroup /dev/sda1 497M 208M 290M 42% /boot tmpfs 184M 0 184M 0% /run/user/0 192.168.1.100:/home 28G 1.2G 27G 5% /mnt/nfs/home 192.168.1.100:/var/nfs 28G 1.2G 27G 5% /mnt/nfs/var/nfs   mount   [root@client ~]# mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=930320k,nr_inodes=232580,mode=755) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755) tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755) cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd) pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime) cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event) cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb) cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices) cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer) cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset) cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu) cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls) cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio) cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory) configfs on /sys/kernel/config type configfs (rw,relatime) /dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota) selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime) systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=25,pgrp=1,timeout=300,minproto=5,maxproto=5,direct) mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel) debugfs on /sys/kernel/debug type debugfs (rw,relatime) hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime) nfsd on /proc/fs/nfsd type nfsd (rw,relatime) /dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota) tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=188060k,mode=700) 192.168.1.100:/home on /mnt/nfs/home type nfs4 (rw,relatime,vers=4.0,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,port
=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.1.101,local_lock=none,addr=192.168.1.100)
192.168.1.100:/var/nfs on /mnt/nfs/var/nfs type nfs4 (rw,relatime,vers=4.0,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,port
=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.1.101,local_lock=none,addr=192.168.1.100) 

Testing  

client:  

touch /mnt/nfs/home/test.txt
touch /mnt/nfs/var/nfs/test.txt  

server:  

ls -l /home/  

[root@server1 ~]# ls -l /home/
total 0
drwx------. 2 administrator administrator 59 Jun 21 16:13 administrator
-rw-r--r--. 1 root root 0 Jun 29 13:07 test.txt  

ls -l /var/nfs  

[root@server1 ~]# ls -l /var/nfs
total 0
-rw-r--r--. 1 nfsnobody nfsnobody 0 Jun 29 13:07 test.txt  

Mounting NFS Shares at Boot Time  

client:  

Open /etc/fstab and append the following lines:  

vim /etc/fstab  

[...]
192.168.2.133:/home  /mnt/nfs/home   nfs      rw,sync,hard,intr  0     0
192.168.2.133:/var/nfs  /mnt/nfs/var/nfs   nfs      rw,sync,hard,intr  0     0  

reboot  

df -h  

mount