Wordpress Load balancing: 2 web servers 1 MySQL without any Cloud services


This is the exact config that I need to configure a load balancing without other cloud services like Amazon, rackspace or GoGrid, completely customized.

I put my question on stackoverflow.com but no luck, so I put it on Quora.com and immediately I got response:

My Notes:

  1. The load balancer is done by my colleagues so I am not sure what is the config of it.  But one thing to note: Your LB should enable "session stickiness" so that the session will follow visitor.  By the way, I am using Round-robins.
  2. Session: Actually I did not use session, but it seems that other plugins (like WPML) will use it.  If I use Apache load balancer, when I go to wp-admin through load balancing IP, I will not able to login, given the username and password is the same.  I will be redirected to login page.  So ask your load balancer providers or check your load balancer config and see how to manage the "Session Stickiness" issue.
  3. Shared folder: your wp-content/uploads folder must be shared and accessible by other web servers, or you will find that one server will have an image but other doesn't.
  4. wp-config.php: point your DB in this file to your MySQL server.  Remember, since your MySQL now needs to accept more than one connection, in your my.cnf please remove bind-address directive or use bind-address=0.0.0.0, which means accept all connections.
  5. MySQL user account: please also note that your MySQL connection user account should allow those web servers to access.
  6. You may need to use searchreplacedb2.php file to replace all URLs to your load balancing IP (if you are using IP address).  For example, before using LB all the URLs in DB starts with "http://192.168.0.1/", but now your LB use 192.168.0.2 (and your public IP is 192.168.0.2 also), you need to use the script above to change all 192.168.0.1 to 192.168.0.2.
  7. /tmp folder: it seems that I don't need to share /tmp folder for other web servers access.  And actually my colleague did not recommend it also because, there are other services that will also use the /tmp folder.  It may create abnormal or unexpected behavior if this folder is shared.
  8. Make sure your uploads/ folder is shared every time your machine is rebooted.  
  9. If you have services other than Apache, you need to make sure that both web servers can access each other via different ports.  i.e., if you found that you cannot access a service from another web server, check if your port is available to other machine first.
Hope it helps someone.

Comments

N.A said…
Hi there

have : 1 load balanced IP 2 web servers running wp 4.1 1 MySQL DB

in the wp-config for each web server I added the LB DNS name as the siteurl

so actually , both wp-config are similar.

in the Apache server, httpd conf, what are the settings that I need to do there?

i know about the server root and the document root

what about the server name? should i specify the local server name or the LB DNS name? what about the virtual host settings?

am really stuck in this for months now

you help is appreciated.
Ellery Leung said…
Hi N.A

I did not put too much attention on server name and virtual host. Actually, I just saw my vhost.conf and my ServerName is still using default (dummy.example.com).

I guess the key here is, how your LB direct traffic to your web servers? If your LB is using RoundRobins, one of your web server will get traffic, and your WP site will response to that traffic as "your-website.com".

One information for your reference: at that time my web servers are all having their own public IPs. Not sure if it will help you.

If you can give your exact error message/problem and post it on Stackoverflow, I think you can get more useful tips. :D

Hope it helps.

Popular posts from this blog

TCPDF How to show/display Chinese Character?

Using wget bypass htaccess username password 401 authorization