实际工作中经常会遇到想把系统迁移到另外的机房或者迁移到云平台,今天给大家介绍一种简单的迁移方法。
实验环境
系统: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@localhosthtml]# cat index.html
aaaaaaaaa
thisis a test!
测试nginx
[root@localhosthtml]# curl172.16.1.101
aaaaaaaaa
thisis 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@localhosthtml]# 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/]# curl172.16.1.101
aaaaaaaaa
thisis a test!
实验环境不同,可能会有差异可以考虑uuid或者挂载方面的问题。
总结
这就是一种简单的迁移方式,还有其他的方法后面再跟大家介绍
如有错误或其它问题,欢迎小伙伴留言评论、指正。如有帮助,欢迎点赞+转发分享。
我是运维小明,微信公众号:九零后运维小明,一个爱折腾的IT技术老司机,欢迎关注我,我们一起学习,共同成长!!
转载:Linux就该这么学











网友评论