NFS (Network File System) is used to share directories over the network; once the client mounts them, they can be read and written like a local disk. This post covers deploying an NFS service on CentOS and Ubuntu, and how to mount a remote NFS directory on each system.
1. exports Configuration
Both the CentOS and Ubuntu server sides configure shared directories through /etc/exports. Each line has the format: 共享目录 客户端地址(选项).
| |
/data/: the directory to share192.168.10.0/24: the client IP range allowed to access it;*means no restrictionrw: readable and writablesync: synchronous writesno_root_squash: the client’s root is also mapped to root on the serverno_all_squash: preserve the client user’s UID/GID
After modifying /etc/exports, you must restart the NFS service for the change to take effect:
| |
2. CentOS 7
2.1 Deploying the NFS Service
Install:
| |
Create the shared directory and edit /etc/exports:
| |
Start it and enable it at boot:
| |
Verify:
| |
2.2 Mounting NFS
Install the client tools:
| |
Mount:
| |
To mount automatically at boot, edit /etc/fstab and add:
| |
Unmount:
| |
3. Ubuntu
3.1 Deploying the NFS Service
Install:
| |
Create the shared directory and edit /etc/exports:
| |
Start it and enable it at boot:
| |
Verify:
| |
3.2 Mounting NFS
Install the client tools:
| |
Mount:
| |
To mount automatically at boot, edit /etc/fstab and add:
| |
Unmount:
| |
4. macOS
macOS has a built-in NFS client, so no extra installation is needed; it acts only as a client mounting a remote directory.
Mount:
| |
For example:
| |
Unmount:
| |
