首页 > 系统相关 >Linux 服务器迁移步骤

Linux 服务器迁移步骤

时间:2024-11-14 14:09:56浏览次数:1  
标签:VPS 步骤 new server etc migration Linux 服务器 your

Learn how to migrate your Linux VPS from an old server to a new one with this step-by-step guide. Discover essential techniques, tools, and best practices for a smooth server migration.

When it comes to migrating your VPS, there are numerous approaches available, ranging from simple to highly complex. The ideal migration method depends on your specific setup, technical expertise, and the nature of your hosted content. This guide presents one of the simpler methods to execute a VPS migration, but it’s crucial to understand that it’s just one option among many.

Table of Contents

This guide is suitable for users who have a grasp of Linux fundamentals and are comfortable with basic server management tasks. To successfully follow along with this tutorial, you should:

  • Be familiar with connecting to & using SSH, and have basic comfort with the command line interface
  • Know how to use a simple text editor like nano
  • Be able to copy and paste commands into the SSH terminal
  • Understand the nature and intricacies of your server environment

While more extensive Linux knowledge can be beneficial, it’s not essential for this guide. We provide clear, step-by-step instructions throughout the process, making this an ideal migration tutorial even for those who are still building their Linux expertise.

Other Migration Methods

The method we are about to show you copies almost everything 1:1 (except system-specific configuration files) from one server to another, using a tool called rsync and should be an effective migration method for 90% of use-cases. However, when it comes to migrating from one VPS to another, it’s important to recognize that there’s no one-size-fits-all solution. The ideal migration method can vary dramatically depending on your specific use case, software stack, hosted content, and technical expertise. Here are some key points to consider:

1. Tailored Approaches: You don’t always need to migrate everything. Sometimes, a targeted approach focusing on specific components can be more efficient.

2. Built-in Tools: Many hosting control panels like cPanel, DirectAdmin, and Plesk offer built-in transfer tools designed for seamless migrations within their ecosystems.

3. Specialized Solutions: Depending on your setup, you might benefit from specialized migration tools or services tailored to specific applications or environments.

4. Partial Migrations: In some cases, you might opt for a partial migration, transferring only essential files/data, while setting up the rest of the environment from scratch on the new server.

5. Environment-Specific Methods: The nature of your environment – whether it’s a LAMP stack, a Node.js application, or a complex microservices architecture – can dictate the most appropriate migration method.

Remember, every environment is unique. What works best for one setup might not be ideal for another. Only you or the person who set up your server would know the intricacies of your environment, and can determine the most suitable migration method.

When planning your migration, consider the specific components that need to be transferred, and any dependencies between different parts of your system. Ultimately, the best migration strategy is one that aligns with your specific needs, minimizes risk, and ensures the continuity of your services. Don’t hesitate to consult with an experienced Linux system administrator or your designated IT professional if you’re unsure about the best approach for your unique situation.

Prerequisites

Before you begin, ensure you have the following ready:

1. Your source VPS (the one you wish to migrate from)

2. Your destination VPS (the one you’re migrating to). Make sure the destination VPS is a fresh install of the same OS version as your source VPS (there should be nothing installed or running on the new destination VPS – it should be a fresh instance).

3. Both servers accessible via SSH

4. Important: Ensure rsync is installed on both servers. If it’s not already installed, you can install it using these commands:

   – For CentOS, AlmaLinux, or Rocky Linux:

sudo yum install rsync -y

   – For Ubuntu or Debian:

sudo apt-get update && sudo apt-get install rsync -y

5. Critically important! Ensure that the new VPS has the exact same operating system version as the old one. If not, issues may arise. Take the time to double-check this closely. You can run the command `cat /etc/os-release` on both servers to ensure an exact match.

Creating the Exclusion List

Before we start the migration, we’ll create an exclusion list. This list helps optimize the migration process by identifying directories and files that don’t need to be transferred to the new VPS. 

You’ll need to decide which directories to exclude based on your specific setup. Exclusions are beneficial for several reasons:

1. Reducing transfer time and bandwidth usage by skipping unnecessary files.

2. Avoiding the transfer of system-specific files that could cause conflicts on the new server.

3. Preventing the overwriting of crucial system files on the destination VPS.

The exact list may vary from system to system, depending on your particular configuration and needs. However, we’ve compiled a list of commonly excluded directories and files that should work for most cases. Feel free to modify this list based on your specific requirements.

Here’s how to create and populate the exclusion list:

1. On your source server, create a plain text file by typing:

sudo nano /root/excludedfiles.txt

2. Once the file is open, copy and paste the following list. This serves as a starting point, covering many standard exclusions:

/etc/fstab
/etc/sysconfig/network-scripts/*
/etc/systemd/network/*
/etc/network/*
/etc/netplan/*
/etc/NetworkManager/*
/etc/resolv.conf
/etc/hostname
/etc/hosts
/etc/machine-id
/var/lib/dbus/machine-id
/proc/*
/tmp/*
/sys/*
/dev/*
/mnt/*
/boot/*
/boot/grub/*
/etc/default/*
/run/*
/var/run/*
/var/lock/*
/media/*
/lost+found
/swapfile
/swap.img
/var/lib/rpm/*
/var/lib/yum/*
/etc/sysconfig/iptables
/etc/iptables/rules.v4
/etc/iptables.rules
/var/lib/iptables/rules-save
/etc/ssh/*
/var/crash/*
/var/log/*
/var/cache/apt/*
/var/lib/apt/lists/*
/var/lib/cloud/*
/sys/class/dmi/id/product_uuid
/etc/udev/*
/lib/modules/*
/lib/firmware/*
/lib64/modules/*
/lib64/firmware/*

3. Save the file by hitting the CTL + X keys on your keyboard, followed by y, and enter. You will then be directed back to the SSH prompt for your source VPS.

This list excludes system-specific directories, temporary files and caches, log files, and other data that either shouldn’t be transferred and/or has already been generated on the new system. It also excludes some configuration files that are typically unique to each server and might cause conflicts if transferred.

Remember, while this list is a good starting point for most environments, you may need to adjust it based on your particular setup. If you’re unsure about any specific exclusions, it’s best to consult with a Linux systems administrator familiar with your configuration.

Performing the Migration

Now we’ll perform the actual migration (as a reminder, before we begin, make sure that rsync is installed on both servers, as covered in the “Prerequisites” section of this post).

1. First, copy the following command to a notepad on your local computer so that we can adjust it accordingly to your values.

sudo rsync -vPa -e 'ssh -p 22 -o StrictHostKeyChecking=no' --exclude-from=/root/excludedfiles.txt / root@REMOTE-IP-OF-THE-NEW-SERVER:/

Within your notepad document, replace `REMOTE-IP-OF-THE-NEW-SERVER` with your destination VPS’s IP address (your new server IP). If needed, replace ‘22’ with your SSH port if you have a custom SSH listening port set up.

2. After editing, copy the entire command from your notepad to your clipboard by selecting all and doing CTL + C, and then paste it onto your SSH window (note: make sure you are logged into the source VPS at this time).

You will be prompted to enter the password for the destination VPS (new server), so that your old server can communicate with your new server. Go ahead and enter it, and then press enter.

3. This process may take some time depending on the amount of data being transferred. Once it’s complete, you’ll notice something similar to the below screenshot, and you’ll also notice that your SSH session is back to a ready prompt:

4. At this point, shut down your old source server, and reboot your destination server. Typically, these functions should be available in your provider’s VPS control panel area. For example, if you’re using RackNerd, you can perform these actions via the SolusVM control panel (also referred to as “NerdVM”).

5. After rebooting the destination server and allowing a couple minutes for it to come back online after the reboot, connect to your new server (the destination server) using SSH. Important: Use the IP address of your new server to connect, but enter the root password from your old server to log in. This is because the migration process copied over the user and password configurations from the old server to the new one. Don’t mix up the passwords – you’re essentially logging into the new server with the old server’s credentials.

6. You can verify the transfer by logging into your destination VPS and checking that your files are present.

Post-Migration Steps

After the migration is complete:

1. Update your DNS records to point to your new VPS IP address if applicable.

2. Review and update any configuration files that might reference your old VPS IP address.

3. Restart any services that were running on your old VPS on the new one.

4. Test your websites and applications to ensure they’re functioning correctly on the new VPS.

Important Caveats

While this method provides a quick and simple way to migrate your VPS, it’s important to understand its limitations. This approach isn’t 100% set-and-go, and its effectiveness depends entirely on your software stack and environment.

For example, if you’re using a hosting control panel like cPanel, this method may not be ideal due to the numerous dependencies involved and could potentially cause issues. For such environments, it’s advisable to follow the software stack’s recommended migration procedure. cPanel/WHM, for instance, has its own transfer tool feature designed specifically for migrations.

Additionally, some configurations that reference your old VPS IP may be transferred during this process (such as web server software configurations). You may need to adjust these accordingly to your new VPS IP after migration.

The effectiveness of this migration method can vary greatly depending on your specific setup. If you’re not sure about the best way to proceed, it’s highly recommended to consult with an experienced Linux systems administrator and/or your IT team before proceeding with any migration.

Conclusion

This guide presents a simple method for performing a near 1:1 migration of your Linux server from one server to another using the rsync tool. However, we strongly recommend consulting with an experienced Linux systems administrator or your designated IT professional to determine the best migration methods for your specific use case.

RackNerd does not assume any responsibility for your migration configuration or methods. The approach outlined here is just one of many possible solutions, and may not be suitable for all situations. Always ensure your migration strategy aligns with your specific environment and software stack, and consider any and all intricacies

标签:VPS,步骤,new,server,etc,migration,Linux,服务器,your
From: https://www.cnblogs.com/managechina/p/18545863

相关文章

  • navicat连接远程服务器docker的mysql容器时连不上报错
    报错:1130-HostxxxisnotallowedtoconnecttothisMySQLserver1.原因是root账户没有远程访问权限,先进mysql容器dockerexec-it你的容器id/bin/bash2.连接数据库,输入你的密码mysql-uroot-p3.切换到mysql数据库usemysql;4.更新用户表:(其中%的意思是允许所有的......
  • 在云服务器搭建 GitLab
    操作场景GitLab是使用Ruby开发的开源版本管理系统,以Git作为代码管理工具并实现自托管的Git项目仓库,可通过Web界面访问公开或私人的项目。本文介绍如何在腾讯云云服务器上安装并使用GitLab。示例版本GitLab:社区版14.6.2本文使用的云服务器配置如下:vCPU:2核内存:4......
  • linux下安装docker
    ****************docker****************docker是一个快速构建、运行、管理应用的工具。****************镜像和容器****************当我们利用docker安装应用时,docker会自动搜索并下载应用镜像(image)。镜像不仅包含应用本身,还包含应用运行所需要的环境、配置、系统函数库。do......
  • Linux平台Oracle开机自启动设置
    网上和官方文档已经有不少介绍如何设置开机启动Oracle实例的文章(Linux平台),不过以sysvinit和service这种方式居多。最近遇到了UAT环境的服务器打补丁后需要重启服务器的情况,需要DBA去手工启动Oracle实例的情形,和同事讨论,决定将UAT环境的Oracle实例启停设置成systemd服务,使其开机......
  • Linux-vscode-c++-slambook2-库文件找不到路径
    Linux-vscode-c++-slambook2-库文件找不到路径分享所遇到的困难,填补这些坑洞,希望后来者能够如履平地。首先已经在c_cpp_properties.json中已经添加了相关的文件,"includePath":["${workspaceFolder}/**","/usr/include/eigen3"......
  • 通过 AWR报告查看oracle 数据库服务器的负载(load average)异常高的原因
    要诊断Oracle数据库服务器的负载(loadaverage)异常高的原因,通过AWR(AutomaticWorkloadRepository)报告可以帮助你识别潜在的瓶颈或负载源。AWR报告提供了数据库的详细性能数据,涵盖了系统负载、SQL执行、I/O性能、内存使用等多方面的信息。以下是通过AWR报告查看和诊断高负......
  • awk是一种在 Linux 和 Unix 系统中非常强大且常用的文本处理工具
    一、awk介绍awk是一种在Linux和Unix系统中非常强大且常用的文本处理工具,它的名字来源于其三位创始人AlfredAho、PeterWeinberger和BrianKernighan的姓氏首字母。awk可以对文本文件(或来自标准输入的文本流)按行进行扫描,并根据用户指定的规则来处理文本,比如提取特......
  • 109.Linux环境如何测试磁盘读写性能.md
    目录一.为什么要测试磁盘读写性能二.如何测试磁盘读写性能1.测试读2.测试写三.其他一.为什么要测试磁盘读写性能当我们编写程序时,尤其是服务端程序,有时需要关注程序性能,磁盘的读写性能会对程序性能产生影响,所以我们就要测试磁盘读写性能。二.如何测试磁盘读写性能......
  • 云服务器搭建及Docker使用---清风
    声明!通过学习 泷羽sec的个人空间-泷羽sec个人主页-哔哩哔哩视频,做出的文章,如涉及侵权马上删除文章,笔记的只是方便各位师傅学习知识,以下网站只涉及学习内容,其他的都与本人无关,切莫逾越法律红线,否则后果自负.文章为个人学习笔记。想学习更多知识,请认准泷羽secdocker安装su......
  • 【Linux】Github 仓库克隆速度慢/无法克隆的一种解决方法,利用 Gitee 克隆 Github 仓库
    Github经常由于DNS域名污染以及其他因素克隆不顺利。一种办法是修改hostssudogedit/etc/hosts加上一行XXX.XXX.XXX.XXXgithub.comXXX位置的IP可以通过网站查询IP/服务器github.com的信息-站长工具这种方法比较适合本身可以克隆,但是速度很慢的情况,可以提......