Simple MySQL replication cluster with load balancer on the slaves
Scenario
Background
This post is a follow on from my previous post on how to setup a load balanced high availability Apache cluster and uses the same network setup and heartbeat setup. For the purposes of testing and to save on resource I am using the web servers from the previous guide as the MySQL servers in this guide. Obviously in a real world setup this would be doing it wrong
End Goal
You will be able to connect to 1 IP address and port with MySQL client and be routed to 1 of many MySQL servers. The machine doing the routing will be in a high availability setup with another machine.
Server Roles
bhlabs1/6 will load balance mysql queries through mysql-proxy
bhlabs2 will be the master replication server
bhlabs3-5 will be mysql slaves
I’m separating this guide into 3 sections:
- MySQL Replication Cluster
- mysql-proxy Setup
- Usage with heartbeat
Using cron to create website and MySQL backups that rotate nicely over a week
I wrote this for a PHP/MySQL site that needed to have it’s databases backed up hourly and the whole site including uploads backed up daily. They wanted all databases going back 24 hours every hour, and then all content going back 7 days every day. This creates a directory structure that looks like the following:
In this scenario assume the following:
- /mnt/backup/servername is an NFS mounted location I am backing up to
- /var/www is the location where the website is stored
Firstly for the impatient, here is the 2 lines you need to put into crontab:
0 0 * * * mkdir -p /mnt/backup/servername/`date +\%A`; mysqldump -uUser -pPassword --all-databases > /mnt/backup/servername/`date +\%A`/all-databases-daily.sql; tar -czf /mnt/backup/servername/`date +\%A`/www.tar.gz /var/www/ 0 * * * * mysqldump -uUser -pPassword --all-databases > /mnt/backup/servername/all-databases-hourly-`date +\%H`.sql
For the less impatient I’ll explain how it works. (more…)
Compiling PHP with Oracle support on CentOS 5.2
Getting PHP and oracle to play nice is a massive pain, so this post is more a log for myself next time I have to do it more than anything else!
The procedure requires you to compile PHP from source, so if thats not your thing or your easily scared don’t bother continuing!
Firstly an enormous yum install command to get everything we need in one go:
# yum install openssh-server httpd httpd-devel apxs libx openssl-devel curl-devel libpng-devel\ oci8-devel libxml libxml2 libxml2-devel libjpeg libXpm libXpm-devel libpng libxslt libxslt-devel\ freetype freetype-devel
Go and grab the instant client from the oracle website and install it with RPM:
# rpm -i oracle-instantclient11.1-basic-11.1.0.7.0-1.i386.rpm # rpm -i oracle-instantclient11.1-devel-11.1.0.7.0-1.i386.rpm
And then get the PHP source (substitute for whatever the latest version is at your compile time obviously):
# wget http://uk.php.net/get/php-5.2.8.tar.gz/from/this/mirror # tar -xzf php-5.2.8.tar.gz # cd php-5.2.8
And finally configure it all together:
# ./configure --with-apxs2=/usr/sbin/apxs --with-zlib --without-gdbm --enable-force-cgi-redirect\ --enable-ftp --enable-xml --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin\ --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib\ --libexecdir=/usr/libexec --localstatedir=/var --mandir=/usr/share/man --infodir=/usr/share/info\ --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-pear --enable-pdo\ --with-oci8=instantclient,/usr/lib/oracle/11.1/client/lib --with-pdo-oci=instantclient,/usr,11.1\ --with-xsl --with-curl --with-openssl --enable-soap --enable-sockets --enable-sigchild --enable-xdebug\ --with-jpeg-dir --with-xpm-dir --with-png-dir --with-freetype-dir --with-ttf --enable-gd-native-ttf --with-gd
And with a bit of luck you should be up and running. Obviously now you have to do battle with Oracle itself which is a minefield of confusion!
How to quickly setup a load balanced, high availability, Apache cluster
I wanted to find a simple to maintain and expand soultion for load balancing a web cluster with high availability. I have found my solution in HAProxy.
Scenario
This demo scenario is in the following enviroment:
- Network Configuration
- Network: 192.168.11.0
- Subnet Mask: 255.255.255.0
- Gateway: 192.168.11.254 (Although this is irrelavant)
- 1 x Shared IP for the Load Balancers
- 192.168.11.40
- 2 x Load Balancers
- BHLabs1 – 192.168.11.30
- BHLabs6 – 192.168.11.39
- 4 x Web Servers
- BHLabs2 – 192.168.11.35
- BHLabs3 – 192.168.11.36
- BHLabs4 – 192.168.11.37
- BHLabs5 – 192.168.11.38
At the start of this setup all machines are running Ubuntu 8.04 Server from a standard install with openssh-server installed and the root password set. All setup commands are run as root or with sudo. (more…)
New Browsers vs. Acid test
So how does the current generation of Browsers fair on the current generation of Acid test?
Safari 4 a clear winner! I’m supprised about Internet Explorer 8, being the newest of the bunch. I had high hopes for them at least trying in this release!
Make working via PuTTY and Vim a bit nicer
If you’re used to working in a nice IDE or some kind of GUI when programming, this may be of interest to you.
The common complaint I hear about when people have to work from the command line such as on remote servers is that there is no nice editor. To me this sounds ludicrous just because I’m used to using Vi all day, but I can see how it would be a problem to those used to a prettier interface
(more…)
Storing lots of data in a Home/Small Office enviroment
OK so me and my housemate have a problem. We have accumulated to much stuff over the years between us, we’ve pretty much run out of solutions to hold it all without buying an enterprise style SAN, but keeping it all in the same volume. Obviously this is to expensive for a home user! We’re looking at finding a home for ~3.5 terabytes of data, including music, backups, films, TV, iTunes mounts etc. I’ve decided to post this on here because it’s also useful to SOHO and medium business who need a storage solution.
We looked at various methods of achieving loads of storage, but have settled on a stand alone NAS. The main reason for this is power consumption; we calculated having a server running with a load of hard disks was going to cost us £30 per month whereas a NAS would only cost us £4 per month!
These are the solutions we rulled out:
- OpenFiler – Way to restrictive on it’s own with sharing and user management
- OpenFiler + iSCSI + Windows 2003 Server – Gets around the restriction above, but costs a fortune having to run 2 servers!
- Windows 2003 Software RAID alone – Unstable, and slow. We actually ran with this for a while but it kept resynching which would take transfer speed down to <6Mb/s. Also there is no expansion option!
- Windows 2003 with a motherboard RAID solution – Most of these come down to runing it off a motherboard unless you spend silly money. On board RAID was usually fine until you wanted to change anything. You can’t move the disks around, it’s slow to rebuild, you can’t expand, etc etc. You are also limited to the number of ports on your motherboard.
- Windows 2003 with PCI-E RAID Card – We could get a seperate RAID card but there is really only 2 SATA2 RAID cards out there and they cost a fortune. You can get cheap SCSI cards, but SCSI disks are both expensive and small capacity.
So we settled on the fact it’s going to be easiest, most economic, and most reliable to buy a standalone NAS appliance. This however throws up the question: which one! There are loads on the market, so we trawled the web and found the most popular, and drew up the following chart to compare them all (PDF version beneath). We are torn between the QNAP TS-509 with 1TB disks and TS-409 with 1.5TB disks. That’s up to next months bank balance I guess!
New edge routing service for Amazon S3
Amazon have launched Amazon Cloudfront today with an announcment on their blog as a service to layer on top of S3. Cloudfront allows you to serve content through Amazon’s edge cache which is located around the world in key locations. When you request content through the assigned domain name, it automatically routes you to the physically closest location to retrieve content. If the content is not yet there, Cloudfront will fetch it from S3 and cache it.
One of the most important services this provides is Asian based distribution points for content on S3; previously only available in Europe or USA. This should increase uptake of AWS in Asia, and with a larger uptake hopefully Amazon will look to make other services worldwide such as DevPay and mechanical Turk (currently only available in the USA).
For a full description including the list of locations Cloudfront distributes through take a look at the detailed description on the official Cloudfront page.
In at the deep end with Cloud Computing
Scenario: You’re new to the cloud infrastructure market but like the idea of flexible billing, rapid rollout (or termination) zero commitments and the possibility for inifite expansion.
These four blog articles all posted today take you through the basics of understanding what you need to get started in a non-vendor biased way:
First, is it right for you? Of course it probabaly is, but this explains why:
Next, how do you identify what makes a cloud providor a cloud providor?
http://www.redmonk.com/jgovernor/2008/11/12/15-ways-i-am-wrong-about-enterprise-cloud-computing/
Then, how do you choose which provider to us? Some are limited to certain technologies, whereas some are so open you can treat your cloud instance however you like.
http://www.manyniches.com/cloudcomputing/cloud-strategy-a-question-of-motivations/
And finally, how do you pitch to your customer that it’s safe? The traditional idea of “this website is on this server” is a hard idea to shake for some people and this could make them doubt the reliability or stability of something that doesn’t physically exist. This blog post covers SLAs in cloud computing:
http://www.technewsworld.com/story/Cloud-Computing-Part-3-SLA-Spirit-in-the-Sky-65137.html
Cloud computing is such a hot topic right now that with the most minimal of effort you can find all the resources, contacts and knowledge you need to get started quickly with cloud computing. A quick search in twitter for example produces a hive of chit chat on the topic with relevant links, experiences and tutorials.






