Methods to Migrate a Linux Server To New {Hardware}

Methods to Migrate a Linux Server To New {Hardware}


Shutterstock/asharkyu

Whether or not you’re upgrading to extra highly effective servers, shifting to new areas, or including new cases, migrating a Linux server could be made simpler by implementing the right methods and realizing the fitting instructions. We’ll talk about how one can transfer your server to a brand new machine with minimal trouble.

Migration Methods

The only and best technique is a blue inexperienced deployment—get the brand new server up and working, after which when it’s manufacturing prepared, swap site visitors over to it, and take away the outdated server when you’ve verified there are not any points.  With load balancing this course of can occur incrementally, additional lowering possibilities of availability issues.

A blue-green deployment entails copying over all of the information, packages, and code on the outdated server over to the brand new one. This may be so simple as manually putting in the required packages, akin to an NGINX internet server, after which copying over configuration from the present server. You can even do a full disk backup, and create a brand new server from that.

After all, now is an ideal time to contemplate whether or not you need to use containers or auto-scaling. Docker containers could be simply stopped, began, and migrated by copying the underlying knowledge volumes (or utilizing a shared knowledge retailer like EFS). Auto Scaling differs relying on suppliers, however if you happen to’re including a brand new copy of your server to fulfill rising demand, it could be proper for your small business. You can even use auto-scaling with Docker containers on many platforms like AWS ECS.

The setup for each containers and auto-scaling requires you to do a lot of the identical work you’ll must do to switch the server manually, akin to automating putting in packages and your individual code, so if you happen to plan on migrating once more sooner or later, it is best to contemplate now if you happen to’d be higher off switching to containers, or organising auto-scaling.

For those who’re concerned with containers, you’ll be able to learn our information to getting started with Docker to be taught extra, or learn our information to utilizing auto-scaling on AWS or Google Cloud Platform.

RELATED: How to Package Your Application’s Infrastructure with Docker

Putting in Packages

For those who’re not fairly positive what you might have put in on the outdated server, the very best technique to verify is to get an inventory of all of the put in companies. This may present many of the main belongings you’ll want to put in:

service --status-all

The rationale for prefering itemizing companies is as a result of the checklist of put in packages could be very lengthy, with each minor dependency additionally being put in. My Ubuntu check server had over 72000 packages put in, so the checklist of them isn’t very helpful contemplating they’ll all get put in anyway when putting in the main companies the brand new server wants.

In order for you, you’ll be able to checklist all of them with the next command:

sudo apt checklist --installed

The search the bundle checklist for a selected bundle, you need to use:

sudo apt -qq checklist program_name --installed

Both manner, you’ll need to make an inventory of the packages it is advisable to set up, and set up them on the brand new server.

Transferring The Server’s Disk With rsync

You could possibly archive the disk with tar, however tar is usually meant to archive single information or directories, not a whole disk. For those who’re shifting loads of knowledge, you might not have sufficient house to make a backup regionally (maybe that’s even the rationale for the improve!).

On this case, you’ll need to use the rsync command to add up the info on to the goal server. rsync will join over SSH and sync up the 2 directories; on this case, we need to push the native listing to the distant server, like so:

rsync -azAP /and so on/nginx username@remote_host:/and so on/nginx

That’s the entire command—it is best to see a progress bar because it transfers (utilizing compression with the -z flag), and when it’s executed, you’ll see the information within the goal listing on the brand new server. You might have to run this a number of occasions to repeat every listing; you need to use this online rsync command generator to generate the command for every run.

In order for you, you’ll be able to strive copying the complete root filesystem to the brand new server, excluding some system information:

sudo rsync -azAP / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/misplaced+discovered"} username@remote_host:/

For those who’re simply seeking to make a backup of some directories, you need to use a easy tar command as an alternative to generate a single file archive:

tar -czvf nginxconfig.tar.gz /and so on/nginx

This outputs one file that you could switch to the goal server with scp or over FTP. Then, extract the file to the goal listing:

tar -xzvf nginxconfig.tar.gz -C /and so on/nginx

Transferring a Database

If it is advisable to switch a database, you’ll need to backup and dump the supply database. For MySQL, that may be:

mysqldump -uUser -pPass -hHost --single-transaction database > backup.bak

For MongoDB, that may be:

mongodump --host=mongodb.instance.internet --port=27017

You then’ll want to revive the database on the goal server. For MySQL, that may be:

mysql -u [user] -p [database_name] < [filename].sql

and for MongoDB, that may be:

mongorestore <choices> <connection-string> <listing or file to revive>

For different databases, it is best to be capable to discover the related instructions on-line.

Switching IPs To The New System

After all, you’ll need to confirm that all the things works as supposed earlier than continuing, however as soon as it’s, you’ll need to swap site visitors over to the brand new server.

The only manner to do that is to alter your DNS information. As soon as up to date, shoppers and companies shall be despatched to the brand new server. This occurs unexpectedly although, so when you’ve got a load balancer, it could be higher to slowly transition site visitors to the brand new occasion.

For those who’re on AWS, or an identical supplier with Elastic IP addresses, you’ll be able to swap over the handle to level to the brand new server, which received’t require a DNS replace. From the Elastic IPs tab within the EC2 console, Motion > Affiliate Elastic IP Tackle.

Change association on elastic IP address

This may can help you modify the affiliation, which can immediately swap site visitors to the brand new occasion.



Source link

Uncategorized