Operations 18 min read

Mastering NFS: Deploy Shared Storage on Linux with RPC

This guide explains the purpose of NFS for Linux file sharing, its architecture and RPC relationship, step‑by‑step server and client deployment, integration with Nginx, and common troubleshooting techniques for reliable shared storage in production environments.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Mastering NFS: Deploy Shared Storage on Linux with RPC

Why Enterprise Clusters Need Shared Storage

Shared storage allows multiple servers to read and write the same data, enabling load‑balanced web clusters to serve consistent content regardless of which node handles a request.

What Is Shared Storage?

Simply put, many servers store their data on a single storage server, so the entire cluster accesses a unified data pool.

What Is NFS?

Network File System (NFS) is a protocol used primarily in LANs to share files or directories between Linux hosts. It lacks user authentication and transmits data in clear text, making it suitable only for trusted internal networks. It supports multi‑node mounts and concurrent writes.

NFS Architecture

NFS relies on the Remote Procedure Call (RPC) protocol. Key components include:

rpcbind – registers NFS services on port 111.

nfs-utils – controls which files are shared and manages permissions.

What Is RPC?

Remote Procedure Call allows a program to request a service from a remote computer without dealing with low‑level network details.

Think of RPC like calling home to ask someone else to run a program for you and return the result.

Relationship Between NFS and RPC

NFS uses RPC to discover the dynamic ports on which its services run. The NFS server registers its ports with rpcbind; the client queries rpcbind to obtain the correct port before sending file‑access requests.

NFS Working Principle

1. NFS server starts and registers its port with rpcbind.
2. NFS client contacts rpcbind on port 111 to get the server's port.
3. Client sends file operation requests to that port.
4. NFS daemon checks client permissions.
5. rpc.mount validates mount permissions.
6. The request is executed by the kernel.

Conclusion: NFS communication is based on RPC and requires rpcbind to be running.

rpcbind Service Role

rpcbind registers NFS service ports and must be running (both rpcbind.service and rpcbind.socket) for NFS to function.

# systemctl status rpcbind
● rpcbind.socket - RPCbind Server Activation Socket
   Loaded: loaded (/usr/lib/systemd/system/rpcbind.socket; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2020-03-10 10:59:12 CST; 4h 35min ago
   Listen: /var/run/rpcbind.sock (Stream)
           0.0.0.0:111 (Stream)
           0.0.0.0:111 (Datagram)

NFS Server Deployment (Important)

1. Prepare the NFS server machine.
2. Install NFS utilities:
   yum install nfs-utils rpcbind -y
3. Edit /etc/exports with the desired share and client permissions.
   Example: /nfs-data 172.16.1.0/24(rw,sync)
4. Create the shared directory and set ownership to nfsnobody:
   mkdir /nfs-data
   chown -R nfsnobody:nfsnobody /nfs-data
5. Start rpcbind services:
   systemctl start rpcbind.service
   systemctl start rpcbind.socket
6. Start NFS service (port numbers may change on each start):
   systemctl start nfs
7. Verify the export list:
   showmount -e 172.16.1.31
8. Adjust export options (e.g., root_squash) and reload:
   exportfs -r
9. Enable services at boot:
   systemctl enable rpcbind nfs
10. Reload NFS after configuration changes:
    systemctl reload nfs
    exportfs -r

NFS Client Deployment (Important)

1. Install NFS utilities:
   yum install nfs-utils -y
2. Start rpcbind on the client:
   systemctl start rpcbind
3. Verify rpcbind is listening on port 111.
4. View server exports:
   showmount -e 172.16.1.31
5. Create a mount point and mount the share:
   mkdir -p /test-nfs
   mount -t nfs 172.16.1.31:/nfs-data /test-nfs
6. Test read/write:
   ls /test-nfs
   touch /test-nfs/hello.log

NFS Combined with Nginx for Shared Storage

# Install NFS server
# Use production‑grade options: rw,sync,all_squash,anonuid,anongid
# Example export for nginx host (IP 172.16.1.7):
/nfs-nginx 172.16.1.7(rw,sync,all_squash,anonuid=1500,anongid=1500)

Integrating Nginx

# Create www user (uid 1500, no login)
useradd www -u 1500 -M -s /sbin/nologin
# Install nginx and set it to run as www
yum install nginx -y
vim /etc/nginx/nginx.conf   # set: user www;
systemctl start nginx
# Mount NFS share to nginx html directory
mount -t nfs 172.16.1.31:/nfs-nginx /usr/share/nginx/html/
# Verify with df -h
# Add a static image to the html directory and reference it in index.html

NFS Failure Cases

1. NFS Server Crash

# Stop NFS on server
systemctl stop nfs
# Client operations will hang; to force unmount:
umount -lf /t3

2. NFS Server Crash Causes Client Boot Hang

# If /etc/fstab contains an NFS mount, the system may hang on boot.
# Boot into single‑user mode, edit /etc/fstab, then reboot.

References

Original article (Chinese)

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

RPCLinuxNGINXSystem AdministrationNFSshared-storage
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.