angldavd
By:
angldavd

Load Balancer + Wordpress

June 20, 2017 1k views
WordPress Load Balancing Nginx MariaDB Ubuntu 16.04

I have a Droplet where i have a wordpress + MariaDB + Nginx instalation, i would like to implement load balancing . Any one can give a hint?

3 Answers

@angldavd

I'd be happy to help :-).

When it comes to load balancing, there's more that comes in to play than just the load balancer. You need to think more about how you want to go about separating things out.

Ideally, in a cluster, you'd separate NGINX + PHP, Database, and Storage in to their own clusters. The reason for this is because you won't be able to deploy a load balancer, add your existing Droplet + a new one and things just work -- there's some degree of manual work required.

...

Ideally, you'd setup a load balancer and X number of web servers which will have NGINX and PHP installed (PHP-FPM). We'll start with 2 in this example, which would look something like:

- Load Balancer
- - Web Server 01 (NGINX + PHP-FPM)
- - Web Server 02 (NGINX + PHP-FPM)

The next cluster we'd need to configure would be storage as we need somewhere to store data so we aren't having to replicate data across the web servers. For this, most will recommend GlusterFS.

GlusterFS is setup with a client and then Y number of storage servers. It all depends on what you'll need for your installation. The client is the one you connect to and mount on the Web Servers -- it then serves data from the storage servers in the cluster.

So our modified cluster might look something like:

- Load Balancer
- - Web Server 01 (NGINX + PHP-FPM)
- - Web Server 02 (NGINX + PHP-FPM)

- - - GlusterFS Client
- - - - GlusterFS Storage Node
- - - - GlusterFS Storage Node

You would, for example, mount the GlusterFS client on /home on the web servers and that's how NGINX would pull data to serve requests. It works just like /home does now, except it's being served from the GlusterFS cluster instead of the physical web server.

The last thing you'd want to setup is a database server. You could set MySQL/MariaDB up on one of the web servers, though it's generally recommended that you setup a database only server and then connect over the private network from your application.

...

As you can see, it can get a little complex and this is certainly just one example, though it's more so tailored to WordPress and database driven applications.

You could certainly run fewer GlusterFS servers, though generally you want to at least run one client and one storage node.

...

That said, whether or not I'd go this route depends on your traffic. If you're not at least half way to the point of needing a load balanced solution, I'd start small and work your way up.

There's a lot that can happen and you would need to be able to troubleshoot -- or ask questions here in the community / submit a support ticket for guidance.

If you're not sure how to go about setting everything up properly, I would definitely recommend hiring a sysadmin to do it for you as a load balanced solution won't perform any better if it's not configured properly. It could potentially perform worse or not at all.

Let me know if you have any other questions, always happy to help :-).

i have a very small company (just me hehe) i cant hire no one... but little by little i´ll make my way hehe

  • @angldavd

    I'd start small and work your way up :-). I've been there myself -- I've actually ran a few one-man companies in the past, so I know starting out can be a struggle for sure. The last company I was bootstrapping started with $100 and a lot of hopes and dreams. I ran it for about 2 years and it was sold off to a larger company who took the reigns and was able to do more than I could on my own.

    As long as you're motivated, you can learn everything I detailed in my first reply. I didn't start out knowing how to do it -- far from it. I struggled, tested, failed, and repeated it multiple times. Even after being a sysadmin for the better part of the last 10 years, there are still things I run in to that I have to check and test, or ask others to jump in on. So don't get down, stay motivated :-).

    ...

    First step I'd recommend -- separate the web server and database server. That's probably the easiest thing to do with your current setup.

    You'd deploy a second droplet, install MySQL/MariaDB, port over your database(s) and then work out connecting to it instead of the installation on your current server.

    Once you've successfully connected, you can remove MySQL/MariaDB from the main server and keep the connection alive on the secondary server. If you can get to this step, the rest will start to fall in to place and become far easier -- in the process, you're learning.

    Load Balancing can be added anytime really, so don't rush in to it when you may not need it. You will end up raising your costs when you don't need to.

    ...

    To give you an idea of what I mean, I recently worked with a client that was spending $1,400 a month with a pretty large provider. They were doing about 5-8 million visitors a month, so traffic was pretty heavy.

    I took their site and migrated it to DigitalOcean and set them up on a single server with Apache and PHP (I would have went NGINX, though they relied on Apache), offloaded the database to a single server, and implemented a caching server as well. No load balancing in this setup, though there was a lot of fine-grain tweaking and tuning involved.

    Now they are serving the same amount of traffic on a setup that runs about $400 per month. It's all about finding out what you really need and using it. Don't overspend on what you don't need right now.

    • thats is what i always do, i try to optimize with server side cache (im far from be an expert)... i normally use $5 Droplets with almost 0 problems BUT i want to go beyond with one of my sites for 2 reasons, first i want to learn and second this site is critical for me and i need absolute zero downtime.

      the aproach that you describe is what im thinking to do. would be really nice to keep in touch, a mentor would be a extremely good for improve the skills.

      • @angldavd

        A single load balancer and mini-cluster won't be enough to prevent downtime. With a single load balancer, you're single point of failure is the load balancer. If it fails, the rest of your stack will fail to respond to the incoming requests.

        You'd be looking in to a rather large, multiple data center cluster farm which is where things get quite a bit more complex.

        Even with a complex cluster, downtime can still be an issue and DigitalOcean does not currently provide the DNS functionality needed to handle higher level config via their current iteration/release.

        I know AWS does as I've tinkered with it in the past, and it'd be entirely possible to use AWS for DNS and DigitalOcean for the clusters, though it's not as simple as spinning up a Droplet and installing a LEMP stack. There's a lot of hands-on configuration in this type of setup which you most likely won't find in guides (they'd be lengthy!).

        It can be a lot of trial and error :-). Hitting the docs for each piece of software becomes the norm in most cases, which can be helpful so you become more familiar with all the options you have.

        ...

        When you get in to complex clusters, you'd be load balancing the web server clusters as well as your database server clusters. NGINX has the capabilities to do TCP load balancing via their stream module, so load balancing database servers can be done pretty easily, though you need a way to keep them in sync as well, which is probably the more difficult part (overall).

        At this size and scale, offloading storage is the only way to go, so GlusterFS becomes very important (or software like it).

        There's a lot of bits and pieces and this is by no means an all-inclusive setup, it all depends on how far you want to go with it, but if you need 100% uptime 100% of the time, you're going to need a lot so that you can account for failures 100% of the time.

        • you are right, may be is too soon to make the thing more complicates, however i want to implement a little cluster to learn how to do it.

Have another answer? Share your knowledge.