I need to replace an aging webserver which runs a busy website. I have the new hardware up and running, all software is installed. There's only one problem left where I'm looking for a solution:
When I change the A record for the domain in DNS, it takes a while for the change to propagate through the internet due to DNS caching. During that time, some users will hit the new server, and some will hit the old one, leading to data inconsistencies because there are now two databases. How can I switch everyone over instantly? I do not run the DNS server and cannot change anything but the A and CNAME records, but I could setup my own if that helps.
I can probably have an hour or two of downtime when moving overnight.
Thanks, Simon
edit: Thank you for all your answers. I'm accepting SmallClanger's answer because it's a viable solution, and I'm upvoting Brian because his answer gave me a new idea: Follow SmallClanger's solution up to the database migration, and then replace the old apache with an HTTP proxy which proxies all requests to the new server. I'd configure the proxy to address the new server by IP address, and it does not involve a temporary subdomain which might (despite the 302 code) end up in some bookmark directory, social network or browser cache.
You could configure the old web server to redirect all requests to the new IP. This can be done with mod_rewrite in apache.
The fundamental problem you have is of maintaining database consistency during the switch. To have zero downtime, you'll have no choice but to set the two servers up in an active/active cluster. (even assuming, for the moment, that the cluster setup would involve no downtime itself, which is a bit of a stretch.).
Given that you can't change the TTL, you best step is to minimise downtime:
www2.example.com
), but make it answer towww.example.com
, too. Point the DNS forwww2
at the new server only.www
record.www2.example.com
This will make sure all traffic goes to the new site during the DNS propagation, regardless of which server they go to initially, though it assumes your site is capable of being served from multiple domain names at the same time.
For a single-server LAMP stack (if that's what you've got), then this is your route to minimal (but not zero) downtime.
You could lower the TTL of your zone one or two days before the migration to a small value. After you've changed the A resource record you can raise the TTL again to its old value.
You have to migrate first all data files on the new server (apache and mysql files) . After that when you have 2 houres to stop server you can synchronize all datafiles with rsync. LIke that rsync -avz /var/www/sites (old-server) user@hosts2:/var/www/sites (new-servers) . And export import all datafiles on sql server from server 1 to new server . Then swich server 2
and stop old server if you have some problem start again server 1 and repear errors on newserver .
But before you start new server check for errors make own test.
lower the TTL, and put up under maintance sign on old page?
I thing TTL is bad idea. Becouse if old server is alive , some user meybe will connect on old server and another users meybe will use new server. If you really have 2 hours use syn and export inport all from sql to sql then swich on new server Am sure all will be fine with mu solutions
You could use the old server IP for your new server.