How to Achieve Web Server Load Balancing and Data Sync with NFS on CentOS
This guide explains how to use NFS on CentOS to synchronize data between multiple web servers and implement load balancing, covering NFS service basics, configuration files, export options, related commands, DNS setup, shared directory creation, Apache virtual host configuration, and testing the synchronized WordPress site.
Introduction
When traffic grows, a single web server may no longer suffice, requiring multiple servers and a method to keep their data synchronized. This article demonstrates how to achieve web server load balancing and data synchronization using NFS.
NFS Service Overview
NFS (Network File System) allows a system to share directories and files over a network, enabling users and programs to access remote files as if they were local. NFS relies on RPC for data transport.
Configuration Files on CentOS 6
Key packages and scripts:
Package: nfs-utils Scripts: /etc/rc.d/init.d/nfs, /etc/rc.d/init.d/nfslock, /etc/rc.d/init.d/rpcgssd, /etc/rc.d/init.d/rpcidmapd, /etc/rc.d/init.d/rpcsvcgssd Configuration files: /etc/exports, /etc/sysconfig/nfsExport Options Explained
Common options include secure, rw, async / sync, no_wdelay, nohide, no_subtree_check, no_auth_nlm, mp, fsid, root_squash, no_root_squash, all_squash, anonuid, and anongid.
Useful Commands
showmount -e NFSSERVER_IP mount -t nfs SERVER:/path/to/sharedfs /path/to/mount_point exportfs -ar exportfs -au exportfs -u FS vim /etc/fstabImplementing NFS for Web Server Load Balancing
Workflow
Two web servers share the same WordPress site directory located on the NFS server at /web/blog. The DNS name blog.scholar.com resolves to both web servers.
Environment
DNS server: 172.168.10.10 (CentOS 6.6)
Web server 1: 172.16.10.100 (CentOS 6.6)
Web server 2: 172.16.10.212 (CentOS 6.6)
PHP server: 172.16.10.110 (CentOS 6.6)
NFS server: 172.16.10.110 (CentOS 6.6)
Database server: 172.16.10.211 (CentOS 6.6, MariaDB)
DNS Configuration
Configure forward and reverse zones for blog.scholar.com. (Images omitted for brevity.)
NFS Server Setup
Create the shared directory and set permissions.
Edit /etc/exports to export the directory to both web servers:
# vim /etc/exports /web/blog 172.16.10.100(rw,sync) 172.16.10.212(rw,async)Prepare WordPress Site
# unzip wordpress-3.2.1-zh_CN.zip # cd wordpress # mv * /web/blog # cd /web/blog # cp wp-config-sample.php wp-config.php # vim wp-config.phpSet database credentials:
define('DB_NAME','wpdb'); define('DB_USER','wpuser'); define('DB_PASSWORD','wppass'); define('DB_HOST','172.16.10.211');Database Server Configuration
Install and configure MariaDB for WordPress (image omitted).
Web Server Configuration
Enable required Apache modules:
# vim /etc/httpd24/httpd.conf LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.soEnable virtual host:
# vim /etc/httpd24/extra/httpd-vhosts.conf <VirtualHost *:80> DocumentRoot "/web/blog" ServerName blog.scholar.com ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.10.110:9000/web/blog/$1 <Directory "/web/blog"> Options none AllowOverride none Require all granted </Directory> </VirtualHost>Mount Shared Directory on Web Servers
# vim /etc/fstab 172.16.10.110:/web/blog /web/blog nfs defaults,_netdev 0 0Check syntax and start services (images omitted).
Testing
Access http://blog.scholar.com to verify the site loads. Publish a post on one web server and confirm it appears on the other, demonstrating successful data synchronization.
Conclusion
Using NFS to share the WordPress directory enables both web servers to serve the same site while keeping content synchronized, achieving load balancing without data inconsistency.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
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.
