martes, 21 de abril de 2020

Linux clone a server

HOT CLONE A CENTOS SERVER WITH RSYNC

Hot Clone Linux Server with Rsync
Hot Clone is the term used to describe to completely clone a Linux server using r-sync across the network. This is useful in situations which you would like to create a clone with little to no downtime that would be typical of taking the original server offline. You can use this to perhaps move a single server in to a cluster environment or certain situation in which you want to upgrade or reduce drives etc.

THIS GUIDE MAKES A COUPLE ASSUMPTIONS:

First both servers need to have the same disk configuration. Either both servers use hardware raid, software raid, or single disks. They typically need to match.
The new server should have the same major install release as the source server.  So both servers would be CentOS 6.x or both need to be 7.x.
The new server has hard drive partitions in a the same format as the old server and they are either the same size or can accommodate all of the used space on the source system.
Services which are writing data should be stopped at the time of the sync (ie mail, databases etc).

PREPARE THE SYSTEMS:

Install needed software packages on both servers:
yum install -y rsync
On the server you want to copy from perform the following:
Create and edit /root/exclude-files.txt and add the following:
/boot
/dev
/tmp
/sys
/proc
/backup
/etc/fstab
/etc/mtab
/etc/mdadm.conf
/etc/sysconfig/network*
This excludes files which directly pertain to the source system and should not be copied to the new system.

HOT CLONE THE SERVER:

Once you have saved that file you can go ahead and rsync to the server you want to copy to:
rsync -vPa -e 'ssh -o StrictHostKeyChecking=no' --exclude-from=/root/exclude-files.txt / DESTINATIONIP:/
This will rsync over everything from the source system to the new system. The size of the drives and load on the servers will determine how long the copy will take.  Be sure to update DESTINATIONIP with the IP address or hostname of the server you are copying to.
After the rsync has completed you can reboot the freshly copied system to have it load everything that has been copied. If you were going to replace the old system with the new system and wanted the same IP addresses, host name etc to be used,  you would then remove /etc/sysconfig/network* from the exclusion file.
Once the new server is back up from the reboot. Go ahead and login using the old servers login credentials and verify everything is working as expected.
----------------------------------------------------


Hotcloning: cloning a running server

There are various ways to clone a machine. Make an image, and restore the image on other hardware. However, if you want to move your server to new hardware, with very little downtime (within some minutes), you can use the description is this article. The article assumes a Debian Linux system, but this will work with most open source operating systems.

Install a base system

You will need a couple of things before you can start hotcloning:
  • a running minimal Debian install (should take you max. 10 minutes)
  • a running network card
  • disks and partitions mounted the way you want them
  • ssh and rsync installed
  • No other running services (except for sshd, if you do this remote like I do). stop inetd, atd, crond, klogd, syslogd

Synchronize the data

Using rsync we can synchronize old_machine to new_machine. Rsync only transfers differences, so you can stop and restart rsync any time, and you can also resync several days later without starting all over again, or rerun rsync to transfer all changed files.

Exclude patterns for rsync

Some files should not be transferred because they are hardware specific, or are available by default, or auto-generated.
These are specific for your hardware and your partition setup:
/boot/
/lib/modules
/etc/modules
/etc/lilo.conf
/etc/fstab
/etc/mtab
These are already available. /proc is a virtual filesystem provided by the running kernel, /dev is the device tree from the base install, lost+found are directories created during partition formatting:
/proc
/dev
lost+found/
These are excluded because you want to keep the logs separate for each machine, and you want (for now) to have a different network setup for each machine:
/var/log
/etc/network/interfaces
An exclude file contains all these entries, every entry on a new line. Click here for an exclude file. Warning: if you have network mounts you need to exclude them too!!!

Sync data

rsync -e ssh -avz --exclude-from=/root/hotclone_exclude old_server:/ /

Switch servers!

  • stop services on old_server
  • rerun rsync (should not take long since most transfers are done already)
  • update /etc/network/interfaces on new_server to contain the IP address of the old_server
  • run ifdown -a on old_server
  • run ifdown -a on new_server
  • run ifup -a on new_server
You're up and running!!!!!!!!!

No hay comentarios:

Publicar un comentario