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:
- 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.
- 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.
- 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.
- 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.
- MySQL user account: please also note that your MySQL connection user account should allow those web servers to access.
- 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.
- /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.
- Make sure your uploads/ folder is shared every time your machine is rebooted.
- 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.