Create a test server using clone/backup snapshot

I'm trying to figure out a repeatable process for setting up a test server that resembles a point in time snapshot of my production server. I have specific settings and modules set up on my production server (CentOS 5.8, Apache, PHP 5.2 running Aegir and several open atrium sites) that would take days to build up manually.

I want there to be zero variation between current production and this new test Linode. Linode's clone/backup features seem to make this possible in theory, but I'm stuck in the mud with launching my test server given that all it's configurations are set to my production site. I What I did so far is pretty simple:

1. Restored my production linode volumes/profile to a new linode VPS (same data center)

2. Through GoDaddy I have pointed the test domain name to the Linode VPS address.

I understand I can't just boot my test linode server (different IP address) from the restored volumes of my production server because all the settings match my production site and bad things would happen such as SQL on the test site trying to connect to my production site, etc. Perhaps I should boot in recovery mode and change conf settings through SSH. If so, where/how?

Taking a step back, the only thing that's different here is my IP address… It's kind of like making an exact copy of a guy named 'Bill', and renaming him 'Tom', but everything else about the two is the same. So is there an easy way for this to happen, or is the dream too much of a headache than it's worth. Seems like it would be a pretty awesome thing to accomplish that a lot of people would want to do.

Thoughts? Steps involved? Thanks!

9 Replies

@Ramanonos:

Perhaps I should boot in recovery mode and change conf settings through SSH. If so, where/how?
Yes, that's the way I'd suggest doing it, as it avoids making the new machine live until you've "corrected" any duplication of the production system you need to change. Boot your new Linode into rescue mode (with the Finnix image), log in over Lish (or enable ssh on the rescue system), and then mount any volumes you need to tweak and make your changes. During this time it's the Finnix kernel that is running and not your actual system so you won't have any conflicts with the production system.

Simplest way to do the recovery boot is on the rescue tab in the manager - see also http://library.linode.com/rescue-and-rebuild - which essentially creates a dynamic profile that assigns your existing disk images to devices in the rescue system. Alternatively you can define your own profile that boots into Finnix as the boot image and keep a static assignment of disk images to devices. For Lish, see also http://library.linode.com/troubleshooti … node-shell">http://library.linode.com/troubleshooting/using-lish-the-linode-shell, or the prior library references uses the ssh approach from within the Finnix system.

I usually make the minimum number of changes with this approach (such as IP address, and perhaps to disable any automatically started services I'm not yet ready to enable) and then boot normally and do the rest of the configuration on the actual system.

-- David

If you want to do "a repeatable process", and I assume a repeatable one, I'd suggest one of two things.

One is invasive to the production system; make the places in code that right now contain directly-coded IP addresses, hostnames, and stuff to automatically choose the prod or test settings on some basis (like the public IP address of the server).

Upside to that is that in the future, all you need to do is to clone the disk and boot it as the other Linode, and the code is 100% the same between them; downside is that you need to change the production files, and sometimes it takes one or another trick to make this possible (eg. when a config file doesn't allow for an external include).

I'm using that one.

Other option is to keep a small prepared boot profile in your test Linode, that boots to a tiny distro that automatically mounts the disk, does the necessary changes, and reboots back into it.

This one lets you "not touch" the production at all; however you need to make sure to keep the auto-alteration script up to date.

Both options should allow you to just about completely automate the cloning process in the future, with help of Linode API.

Thanks. I suppose with either approach I'd have to first know which files I need to change IP settings. I can't believe how mysterious it really is to change a IP address of a clone… I thought it was as simple as pointing a test domain name at the test linode ip address, adding a couple name servers, and pasting in the new IP address into etc/sysconfig/network-scripts/ifcfg-eth0 . Right? wrong… Ugh i think the first clue was that I didn't have a static IP inside ifcfg-eth) file.. Instead it said BOOTPROTO=dhcp

I changed to the new domain name in /etc/sysconfig/network

I changed to the new IP address in var/aegir/config/server_master/apache/vhostd/example.com

I changed to the new IP address in /etc/httpd/conf.d/aegir.conf

Still, nothing… Maybe it's a CentOS thing or an Aegir thing. But I've been at this for two days and can't access the site under a different domain. It's such a basic thing I want to do here, yet I can't get it work for the life of me. Linode support says clone feature was great for what I wanted to do, but once we looked at few things, support admitted being totally stumped. A guide here would be useful. I actually chose Linode service because I thought Clone looked really powerful and useful. It's too bad because the Linode's clone feature would be really awesome if I could actually use it.

Anyways, unless anyone has any clues, I'm going to just build up a test site from scratch.

Thanks again.

By default Linode uses DHCP for IP addresses so unless you've changed your configuration you shouldn't need to change anything IP related. This http://library.linode.com/networking/co … interfaces">http://library.linode.com/networking/configuring-static-ip-interfaces may help you sort your IP configuration.

Right, that's exactly what I assumed with how DHCP works… The DNS resolvers should take care of themselves. The name servers look good in resolv.conf. I don't know what to blame. Maybe CentOS, maybe Aegir. Both are getting long in the tooth. Still, Linode's Clone feature is feeling more and more like a pipe dream. I did have to manually go into each of my virtual hosts and change to the new IP address manually: var/aegir/config/server_master/apache/vhostd/EXAMPLE.com That wasn't much of a bother because I had 10 subdomains being served under each vhost. I can SSH in, but no dice on launching the web page. Wish I could just launch webmin or phpmyadmin… I'm sure there's some other change I need to make somewhere, but I can't find what it is. Do I need to rename my database too? Running out of options and kinda sad about linode clone being a dud :(

The "Clone" operation isn't the dud, your system is the dud. Clone does nothing magic aside from copying the entire filesystem from one machine to another. So, something on there is likely hard-coded to an IP address / MAC address / etc.

Alas, I have nothing else useful to contribute (other than my usual "good luck!" from past experience with CentOS and Aegir, and assurances that it works just fine without CentOS or Aegir.)

@Ramanonos:

Thanks. I suppose with either approach I'd have to first know which files I need to change IP settings. I can't believe how mysterious it really is to change a IP address of a clone… I thought it was as simple as pointing a test domain name at the test linode ip address, adding a couple name servers, and pasting in the new IP address into etc/sysconfig/network-scripts/ifcfg-eth0 . Right? wrong… Ugh i think the first clue was that I didn't have a static IP inside ifcfg-eth) file.. Instead it said BOOTPROTO=dhcp

I changed to the new domain name in /etc/sysconfig/network

I changed to the new IP address in var/aegir/config/server_master/apache/vhostd/example.com

I changed to the new IP address in /etc/httpd/conf.d/aegir.conf

Still, nothing… Maybe it's a CentOS thing or an Aegir thing. But I've been at this for two days and can't access the site under a different domain. It's such a basic thing I want to do here, yet I can't get it work for the life of me. Linode support says clone feature was great for what I wanted to do, but once we looked at few things, support admitted being totally stumped.

You said you can get in via SSH (presumably by IP or hostname?), so let's assume the clone is running and DNS is working. Maybe I'm misreading your post but it sounds like you can't load the web sites on the cloned Linode, which narrows it down to Apache. Are your ServerName or ServerAlias directives set to listen for the correct hostnames? If your original site was http://www.mysite.com and you've set an A record for dev.mysite.com pointing to your clone, the browser will hit your clone asking Apache to serve up dev.mysite.com. If you haven't switched www.mysite.com to dev.mysite.com on the clone, (i.e., if there's no ServerName matching that requested host name), Apache will either serve up "It Works", nothing, or the wrong site, depending on your configuration.

I'm probably misunderstanding what you're trying to do and the problem, but that was what came to mind when you said you couldn't access the sites under a different domain.

You also don't necessarily need to hard-code IP addresses in VirtualHost directives; if your configuration allows it just use VirtualHost *:80 and then you don't have to many so many changes between the production and clone conf files.

Thanks haus. Yes you are correct. I can SSH in just fine using the same password as my production. But I can't load the web sites (test.com) on the cloned Linode, which does seem to narrow it down to Apache. I think you're sniffing up the right tree on the Apache side. But there may also be some funk associated with Aegir, which might be getting in the way here. Or maybe the fact that the prod site was SSL? I've looked in all the obvious places/files with Apache. I'm not seeing anything hardwired in.

To be sure, I ran the command to recursively cahnge any instance of old IP (123.456.789.012) with my new IP address (555.55.555.55)

find ./ -type f -exec sed -i 's/123\.456\.789\.012/555\.55\.555\.55/' {} \;

Not sure if that did anything. But I still can't access www.test.com. yes, I restarted networking and httpd services..

I suppose the only stones I may have left unturned is on what you're suggesting with matching my servername matching requested hostname. I'm not I'm fully understanding what to check here, and/or what to change. Any thoughts?

BTW- I'll be happy to document this whole thing with pretty pics if I get this working. I have to imagine there's a ton of CentOS/Aegir on Linode people out who would love to to do what I'm trying to do.

I don't know anything about Aegir so I'm not able to comment there. To the extent that it integrates with Apache you may indeed have some "funk" in Aegir configuration. But to my knowledge if Apache is serving up virtual hosts, each virtual host has an entry in a conf file. From the description Aegir may integrate itself somewhat into this process so I don't know how specific I can get. But maybe this will help.

I have a very old, very outdated CentOS box running cPanel, so this info may not be the same for you, but my virtual host directives are in /etc/httpd/conf/httpd.conf. For each virtual host, you must have a ServerName or ServerAlias directive matching the host name (wildcards are OK) that the browser is sending to Apache with each request.

For example, one of my vhost entries starts like this:

 <virtualhost 111.111.111.111:80="">ServerName mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /home/me/public_html
    ServerAdmin webmaster@mydomain.com
    UseCanonicalName Off
    ...</virtualhost> 

That vhost will respond to the URL "mydomain.com" or "www.mydomain.com" typed into a browser. On your clone, change one of those to match the test/private name you want the server to respond to and the same as your A record in DNS.

Sounds like you're using a completely different domain name instead of a subdomain, so if your vhost is looking for http://www.live.com and you want to change it to http://www.test.com, make the change in DNS and in the vhost directive, then restart apache or reload the Apache config.

If you can get this working, I'd suggest eliminating the IPs from the vhost directives (if you can) and set up wildcard vhost ServerNames like .mydomain.com (obviously don't do something to break any existing subdomain vhosts on your production server though). Then you could just point an A record for "dev.mydomain.com" to the clone IP and leave the existing DNS for the domain intact. Then by the DNS records, the clone Apache will respond to "dev.mydomain.com" and the production server will still respond to "www.mydomain.com" and they can both use the same vhost configuration file - hence the easy aspect of cloning. You can clone your production Linode until you're blue in the face and it will always work since DNS points you to the correct server. There are a million ways you can set this up based on what you want, though. You can also use your local hosts (/etc/hosts) file if you only plan on doing development on one machine and you don't want to publish DNS records for a development server that happens to be connected to the Internet.

Hope that helps some.

* Not advising security through obscurity here, but sometimes providing less information isn't a bad thing. If you don't the world accessing your dev clone, you could deny all and then allow from your own IP address, or use htpasswd, etc. to block access to the clone.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct