CentOS 7 Server Deployment Cookbook
上QQ阅读APP看书,第一时间看更新

Configuring an NFS client to use a shared filesystem

This recipe continues where the previous recipe left off, showing you how to configure NFS on a client system.

Getting ready

This recipe requires a CentOS system with a working network connection. It assumes that an NFS server has been configured as explained in the previous recipe. You'll also need administrative privileges provided by logging in with the root account.

How to do it...

Follow these steps to configure an NFS client:

  1. Install the nfs-utils and libnfsidmap packages:
    yum install nfs-utils libnfsidmap
    
  2. Create the directory which will serve as the mount point for the remote filesystem:
    mkdir /mnt/nfs
    
  3. Start the rpcbind service and register it so that it will start when the server boots:
    systemctl start rpcbind
    systemctl enable rpcbind
    
  4. Mount the NFS share to the mount point:
    mount -t nfs 192.168.56.100:/var/nfsshare /mnt/nfs
    

How it works...

Like the server side, the client side of NFS relies on RPC. So, we started and enabled the rpcbind service. The mount command is then used to mount the remote share:

mount -t nfs 192.168.56.100:/var/nfsshare /mnt/nfs

The -t argument indicates the share's filesystem type, which, of course is, nfs. The location of the remote share is also provided, the IP address of the server and the directory of the shared data separated by a colon. Finally, the mount target is given.

To manually unmount the share, the umount command is used with the mount point:

umount /mnt/nfs

We can also configure the system to mount the NFS share automatically at boot time. Open /etc/fstab using your editor and add the following line:

192.168.0.100:/var/nfsshare /mnt/nfs/var/nfsshare nfs defaults 0 0

The share will be automatically mounted when the system boots. Since mount can look up information in /etc/fstab, the invocation to mount the share manually becomes much simpler once it's registered in this manner. You can now mount the share manually by providing just the mount:

mount /mnt/nfs

See also

Refer to the following resources for more information about configuring an NFS client: