Cloning an Ubuntu
Translation of the original in Catalan. Read it in: CatalàCastellano
I had a server on a VMWare virtual machine that is in production and therefore it was not a good idea to shut it down. The idea was to set up another identical physical machine to put it in production for when the first one fails. So, I had to set up a machine identical to the production one with the same configuration as the server in production. The thing has taken me a little longer despite the steps being simple. Basically I came across silly problems that, because I am not used to using Ubuntu, took me more time than expected.
To begin with, from the production host we get a list of the installed packages, we launch the following command from the directory and as the root user:
dpkg --get-selections | grep -v deinstall > llista_paquets
Next we can do all the processes from the machine we are going to install. On the second machine I have installed an Ubuntu Server 6.06.1 LTS (Long Time Support) the same as on the first one, I have done a normal server configuration (not LAMP) configuring the hardware properly so that everything works. Once the installation is finished:
# Copiem configuració del APT de producció al nou servidor
rsync -cavz root@ip_produccio:/etc/apt/ /etc/apt/
# Actualitzem repositori
apt-get update
# Actualizem paquets bàsics de la distribució
apt-get dist-upgrade
# Copiem llistat de fitxers de producció
rsync -cvz root@ip_produccio:/root/llista_paquets /root/
# Marquem paquets a instal·lar en local
dpkg --set-selections < llista_paquets
# Entrem al gestor de paquets dselect
dselect
# Ara premem la tecla 'I' i després 'intro' perquè comenci la
# descarrega i instal·lació de paquets
# Finalment premem la tecla 'Q' i 'intro'
At this point we already have the same packages installed in production as on the new machine. Now we have to copy the configurations of the applications we have running. The idea is to copy all of /etc and all of /var. Although this must be done very carefully and must be debugged a lot, so as to be able to always know whether we have messed it up at some point. Because, for example, there is no need to copy all the log directories, although if we are on a LAN and they are not many megabytes it doesn't matter if we copy it. The most critical thing is not to overwrite files like /etc/fstab, which may vary according to the architecture of the machines. In my case there was not much more to take into account, but keep in mind that there are applications that have configuration files in unusual places and that should also be copied. Besides, it is vital that you do not forget that not only the files must be copied, but also their attributes, that is, permissions and owners.
A good idea to copy the /etc directory is to create a file with the list of files and/or directories that we do not want to copy, in my case: (exclude_list.txt)
/etc/fstab
/etc/modprobe.d
/etc/modutils
Then with the following command we synchronize the files and their permissions from the production server to the new server:
rsync -cavz --delete --exclude-from=exclude_list.txt root@ip_publica:/etc/ /etc/
The rest of the configurations can be copied with the same process.
6 comments
Comments from the old blog, as they were written. Comments are closed.
Javier Mart
Antes de llegar al final del articulo te iba a proponer el uso de rsync, pero veo que ya lo has hecho.
Un saludo
sabueso
[1] Rsync como unison no siempre es una buena solucion , sobre todo si los cambios de un fichero X estan haciendose al mismo tiempo q se sincronizan y los tamaños son muy bestias.
Provadlo con un acces.log de mas de 20 megas (no vale decir tira dentro del rotatelog una truncada de menos megas ...)
Y que tal un tar/star de todos ficheros a copiar ?
Igualmente , dependiendo de los entornos a veces acabas tirando hacia un init 1 o una knoppix para hacer la copia :-(
Slds y espero no haberos rallado ;)
plue
VMWare de per si ja suporta clonar maquines sense apagar l'ordenador. Aixi que no calia fer comandes de debian... :P
Mira el manual del vmware....
—
[3]
El que comentes és bona idea, però no soluciona el meu problema del tot. Ja que llavors el que hauria de clonar és el pròpi clon. Ja que obviament l'arquitectura de la màquina real no tenia res a veure amb la virtual. Per començar tenia un RAID amb 6 discos i dues CPUs.
Però com tu apuntes solucionaria el problema de tenir fitxers que es van omplint mentre els sincronitzo problema que realment no vaig tenir perquè vaig excloure de la sincronització.
Com a nota cmentar que avui he posat en producció la màquina clonada i només he tingut un petit problema de permisos en un directori que se'm va oblidar de canviar.
SuNbiT
Nomes comentar que ara fa poc vaig fer uns instalacio en un debian basade en un get-selections, pero en aquest cas, les fonts dels paquets eren d'un fitxer sources.list bastant gros. El resultat va ser que hi havien els mateixos pauquets a les 2 bandes, pero no les mateixes versions. Sembla que el get-selections no te en compte les versions. Sabeu alguna manera de conservar les versions?
—
[5]
Però el source.list dels dos paquets eren iguals????
Si això és així i fas un apt-get update i després el apt-get dist-upgrade de la màquina de producció tindràs la última versió dels paquets. Així quan facis el mateix en la màquina nova tindràs la mateixa versió també, o sigui, la útlima.
Si el que vols és aconseguir la mateixa versió, però no la última la cosa ja es complica una mica més. Perquè no has de fer el update ni el dist-upgrade a la nova màquina a més d'assegurar-te que els paquetes marcats al dselect usin les mateixes fonts que la màquina de producció, cosa que ja requereix una mica més d'elavoració en el procés.
Sincerament, la meva opinió seria actualitzar tot a la nova versió en la màquina nova, després de comprobar que tot va, la posaria en producció i l'antiga màquina de producció també l'actualitzaria.