File Synchronization in Cluster
File Synchronization Between Application Servers
This is useful for horizontally scaled applications such as WordPress, Drupal, Joomla, Liferay, and Redmine, where uploaded content may otherwise exist only on the server that originally processed the request.
File Synchronization Implementation
The solution is provided as a one-click add-on built around lsyncd, cron, and file-system change detection. Synchronization starts only when actual changes are detected, reducing unnecessary CPU usage compared with repeated full synchronisation calls.
Install the Example Application
The following example uses WordPress with two NGINX-PHP application-server nodes. The same approach can be used with other supported applications and languages.
1Install WordPress
Open the Marketplace, locate WordPress, click Install, and provide the environment name, display name, and region.
2Add another application-server node
Open Change environment topology, increase the number of application-server nodes in the Horizontal Scaling section, and click Apply.
Test Upload without Synchronization
3Upload a file through WordPress
Open the WordPress administration panel, sign in, and upload an image or another file to the Media Library.
4Compare both nodes
Open Config for the application-server layer and compare the content of webroot/ROOT/wp-content on both nodes. Without synchronization, the uploaded file appears only on the node that handled the request.
webroot/ROOT/wp-content for WordPress, webroot/ROOT/sites for Drupal, webroot/ROOT/images for Joomla, and webroot/home/liferay/data for Liferay.
Apply File Synchronization
5Install the add-on
Open Marketplace, locate File Synchronization, and click Install.
6Configure synchronization
Select One environment synchronization and provide the following values:
- Sync path: Directory relative to the webroot, for example
/ROOT/wp-content. - Sync delay (sec): Number of seconds to wait before synchronising changes.
- Environment name: Target environment.
- Nodes: Application-server layer selected automatically after choosing the environment.
Click Install. After installation completes, the uploaded files become available on all selected nodes.
Synchronize Two Environments
To synchronize application servers across two different environments, install the add-on in both environments and choose Two environments synchronization.
- 2nd environment IP: Internal IP when both environments are on the same platform and hardware region; otherwise use an external IP.
- Password: Optional synchronization password. Use the same value on both sides.
Mount-Point Exceptions
When the synchronized directory contains mount points, add those paths to the exceptions in:
<sync_path>/lsyncd/etc/lsyncd.conf
Then restart synchronization by terminating the running rsync and lsyncd processes on each node:
for pid in $(ps aux | grep 'rsync\|lsyncd' | awk '!/grep/{print $2}'); do kill -9 $pid; done
Check Synchronization Logs
Synchronization logs are stored in the following directory on the application server:
webroot/lsyncd/var/log
The most useful files are lsyncd.log and lsyncd.status, which show synchronization events and the current state.
