Note: The setup I’m about to describe is not only UNSUPPORTED by MySQL but also clearly "Not a good idea", following posts all over MySQL sites. I’m not kidding : Here (second paragraph), here (big orange warning in the center) and so on. Read the conclusion of this post, it also bring one important point.
Yesterday, while helping a friend with a server, I’ve decided to improve my lab setup. The configuration in question involve dual LAMP system accessing shared-storage system to deliver webpages. The load-balancing part will be secured by PEN software on my router. I’ve integrated a small php function to show which server is answering the request, this information is available under my LinkedIn tag in the last sidebar.
So I have 2 " servers" systems, MD devices + DRBD 8.2.5 + OCFSv2 + Apache2 + Php5 + Mysql 5.0.51, with dual network interface {one toward the LAN, one as a cross-over}.
Over the cross-over, DRBD sustain a primary/primary array, with OCFSv2, creating a shared-disk device. Procedures to create such setup is available on mass-storage.org. We still need to create the rest of the infrastructure, this will be a 3 steps job.
Load-Balancing
The current setup is a load-balanced environment, there isn’t much high-availability value since our load-balancer is going to be the point of failure. We will be using PEN load-balancer on the router. Why ? Because it is very easy to configure and was the fastest to install. In time, I’ll post a true walkthrough to get an HA infrastructure, but not today.
apt-get install pen
pen -T 10 10.0.0.25:80 10.0.0.26:80 10.0.0.27:80
And I NAT all my inbound web traffics towards 10.0.0.25, which, in turn, load balance over 10.0.0.26 and 10.0.0.27. "Connection tracking" is kept for 10 seconds, giving the same servers for most of the sessions. This isn’t really needed, but allow me to give an excuse for the "DO NOT hammer my server to play with the load-balancing ;-)" part of my speach to my friends.
Apache2 + Php5
This really is the easy part, we configure both Apache service toward the same files, it work. If you intend to do heavy use of sessions (or small), you better use a modules to relocate them on you shared storage.
MySQL 5.0.51
Here goes the tricky part. MySQL doesn’t like shared storage, so you better really know what you are doing. The first thing we do is change some default configuration:
in /etc/mysql/my.cnf, we need to create the external-locking mode
skip-external-locking -> external-locking
To remove the caching:
delay-key-write = OFF
query-cache-size = 0
And we need to be sure we are using MyISAM tables. Innodb is really a big NO-GO here. Kinda cool to know that MySQL default mode/tables are already using the MyISAM storage engine.
Conclusion
If you have any services which require you to think about load-balancing, but are ignorant enough to base decisions on the lab-notes I post on this blog, I would advice you to get in touch with a storage/network consultant. Won’t cost you that much and you will have a written confirmation that your infrastructure is going to work for your given application.
Leave a Comment