How to Deploy an NFS Server on CentOS 7 for Shared Storage
Learn step‑by‑step how to install, configure, and launch an NFS server on CentOS 7, set up shared directories, edit export rules, adjust firewall settings, and mount the share on client machines, enabling reliable network file sharing for distributed and containerized environments.
When handling large file uploads in a distributed environment, a shared file system is needed; NFS (Network File System) provides a simple, stable, and efficient solution for network‑based file sharing.
NFS allows Unix/Linux clients to mount remote directories and use them as if they were local, making it ideal for multi‑node clusters and container orchestration platforms.
1. What Is an NFS Server
Definition NFS server is a host that exports one or more local directories over the network, allowing clients to mount and access them.
Working principle NFS uses RPC to handle client file operation requests (read, write, delete, etc.) and returns results, enabling concurrent access.
Applicable scenarios In distributed systems, multi‑node clusters, and platforms like Kubernetes, NFS can provide shared storage for containers and applications.
2. How to Deploy an NFS Server
The following steps illustrate a basic deployment on CentOS 7.
1. Install NFS service software
sudo yum install nfs-utils2. Configure the shared directory
Assume the shared directory is /export/shared-storage. Create it if it does not exist and set appropriate ownership:
sudo mkdir -p /export/shared-storage
sudo chown nfsnobody:nfsnobody /export/shared-storage3. Edit the NFS export file
Edit /etc/exports and add a line to export the directory:
/export/shared-storage *(rw,sync,no_subtree_check)Explanation of the options: /export/shared-storage – path of the shared directory. * – allows any client (can be restricted to specific IPs or subnets, e.g., 192.168.1.0/24). rw – read‑write access. sync – synchronous writes for data safety. no_subtree_check – disables subtree checking to improve performance.
4. Start the NFS service
sudo systemctl enable nfs-server
sudo systemctl start nfs-server5. Configure the firewall
Allow NFS‑related ports (typically 2049/tcp and 111/tcp/udp):
sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --permanent --add-service=mountd
sudo firewall-cmd --permanent --add-service=rpc-bind
sudo firewall-cmd --reload6. Mount the shared directory on a client
Install the NFS client utilities and mount the export: sudo yum install nfs-utils Mount command example:
sudo mount -t nfs export/shared-storage /mnt/shared-storageReplace <nfs_server_ip> with the server’s IP address and /mnt/shared-storage with the desired mount point on the client.
7. Verify the setup
cd /mnt/shared-storage
ls -lIf the shared files are visible, the NFS server is successfully deployed and the client can access the shared storage.
3. Summary
NFS server provides network‑based file sharing, allowing clients to mount and access shared directories.
Deployment steps include installing NFS software, configuring the export directory and /etc/exports, starting the service, adjusting firewall rules, and mounting the share on clients.
In distributed or multi‑node environments, mounting an NFS share enables containers or applications on different nodes to use the same data, ensuring consistency and shared access.
Lin is Dream
Sharing Java developer knowledge, practical articles, and continuous insights into computer engineering.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
