Question

How to setup shared storage on DigitalOcean load balanced droplets

Posted September 18, 2019 2k views
CentOSDigitalOceanLoad BalancingClusteringBlock Storage

I have a WordPress site that periodically peaks in traffic, this does not happen often enough to warrant a beefy server. So I was planning on setting up a load balanced cluster of small droplets.

One problem rose though, how do I keep files synced across the multiple replicated servers, there is no master and slave here. I thought of using a tool like rsync, to keep files in check, but I don’t think this will work in this use case! If one session file got to the other server a little bit late, the user will find himself logged out, user uploaded files on one server might take longer to get to the other than it takes for the user to refresh the page.

So I’m feeling like this is not the right way to go about it.

One solution that I came across, is shared storage, but the block storage supported by DigitalOcean can only be attached to one server.

Is there a setup, where load balancing will ONLY use the other servers purely for their CPU and RAM, if I’m not mistaken, Nginx as a load balancer should work this way, right? Or do I still need to host my app files on all servers in an Nginx cluster.

Please advise.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hello, @ALKateb

I would refer to this previous question posted on the DigitalOcean community: https://www.digitalocean.com/community/questions/how-to-best-load-balance-a-wordpress-woocommerce-e-commerce-site

Where the following solution was posted:

“I set up lsyncd from wp1 to wp2, and although it is a few seconds delay to copy/sync, it is more than adequate for my needs.

For setting up the load balancer:

I first pointed my domain to wp1 IP
I then generated a letsencrypt (cert only) so that I would have the cert info I needed.
Then I added this info manually from the files certbot generated to the load balancer
Then I pointed my domain to the load balancer, force all traffic to SSL, and connect to port 80 of my droplets behind the load balancer
For naming my WordPress servers:

I called one of them wp1.mydomain.com and the other wp2.mydomain.com
I manually added entries in the otherwise identical wp-config.php file on each server with the following: define('WP_HOME','https://wp2.mydomain.com'); define('WP_SITEURL','https://wp2.mydomain.com');
I exclude wp-config.php from my lsyncd setup btw, and sync everything else in /var/www/html
For the DB, both wp1 and wp2 point to the same (third) server (db1.mydomain.com) and serve the identical info.”

Also you can check this article as well. It’s great!

https://www.digitalocean.com/community/tutorials/automating-the-deployment-of-a-scalable-wordpress-site

Let me know if you have any questions about the setup.
Alex

by Ryan Quinn
Create and deploy a scalable WordPress instance consisting of a MySQL database server, a GlusterFS distributed filesystem, Nginx web servers and an Nginx load balancer. By using user-data and droplet meta-data we will automate the deployment of our site.
Submit an Answer