导读 实际工作中经常会遇到想把系统迁移到另外的机房或者迁移到云平台,今天给大家介绍一种简单的迁移方法。


实验环境:
系统:centos7
ip:172.16.1.101
server1部署nginx,再装一台新的server2 和server1一样的环境但是不部署软件,实验要求迁移之前访问server1的nginx可以访问,访问server2的nginx可以访问。

server1部署nginx
[root@localhost ~]# tar xf nginx-1.11.2.tar.gz
[root@localhost ~]# ./configure
[root@localhost ~]# make
[root@localhost ~]# make install
编辑index.html

[root@localhost html]# cat index.html
aaaaaaaaa
this is a test!

测试nginx
[root@localhost html]# curl  172.16.1.101
aaaaaaaaa
this is a test!
将重要目录打包

--exclude 指定的目录不打包 --warning 略过报错

[root@localhost ~]# cd /
[root@localhost /]# tar cvpzf backup.tgz / --warning=no-file-changed --exclude=/proc --exclude=/mnt --exclude=/sys --exclude=/dev --exclude=/tmp --exclude=/backup.tgz
登录server2进行迁移

可以用拷贝的方式,我这里先在server配置成172.16.1.102 通过scp传过来
cd /

[root@localhost html]# scp root@172.16.1.101:/backup.tgz .
[root@localhost /]# cd /
[root@localhost /]# 
[root@localhost /]# tar xvpfz backup.tgz -C /
[root@localhost /]# restorecon -Rv /
测试

关闭server1 重启server2访问172.16.1.101 的nginx

[root@localhost /]# curl  172.16.1.101
aaaaaaaaa
this is a test!

实验环境不同,可能会有差异可以考虑uuid或者挂载方面的问题。

总结

这就是一种简单的迁移方式,还有其他的方法后面再跟大家介绍

本文原创地址:https://www.linuxprobe.com/centos-qianyi.html编辑:王华超,审核员:逄增宝