hugo-teek is loading...

更换云服务器后需要做的事儿

最后更新于:

数据迁移-更换云服务器后需要做的事儿

image-20241209173907674

目录

[toc]

背景

自己之前在阿里云买的ecs过6天就到期了,无语的是,最近一次扩容系统盘到100g,导致我没法使用每年99优惠价了,裂开。。。

因此,需要马上新找一台云服务器,来迁移数据。

重要的数据就是ecs里的md图床,docusaurus博客,其它没啥了。

其实过程非常简单,稍微配置下就OK了,欢迎大家交流。😜

等后续安稳一点了,决定利用nas来部署自己的业务,云服务器太贵了,来回切数据也麻烦。。。。

环境

1老服务器:云服务器ip
2新服务器:云服务器ip
3
4centos7.9
5win10

1、部署Nginx

(1)安装nginx软件

 1#vim /etc/yum.repos.d/nginx.repo
 2[nginx]
 3name=nginx repo
 4baseurl=https://nginx.org/packages/centos/$releasever/$basearch/
 5gpgcheck=0
 6enabled=1
 7
 8
 9yum install nginx -y
10systemctl start nginx
11systemctl enable nginx
12systemctl status nginx

(2)拷贝源服务器nginx配置文件到新服务器

 1#/etc/nginx/conf.d/ 下所有内容
 2#/etc/nginx/cert2 公钥/私钥
 3
 4#新服务器上
 5mkdir -p /etc/nginx/cert2 #ssl目录
 6mkdir /images #图床目录
 7#配置权限为root(必须配置,否则ngix报403错误,淦,这个坑了我好久时间。。。)
 8#vim /etc/nginx/nginx.conf
 9user  root;
10
11
12#老服务器上:复制nginx配置文件及ssl
13cd /etc/nginx/conf.d/
14scp * root@云服务器ip:/etc/nginx/conf.d
15
16cd /etc/nginx/cert2
17scp * root@云服务器ip:/etc/nginx/cert2
18
19#复制网站监控信息到md
20scp /root/monitor.sh  root@云服务器ip:/root
21
22#传输防盗链图片
23scp /FdangDaoLianImages  root@云服务器ip:/root
24
25nginx -t

2、部署rsync

(1)安装rsync

 1# 如果没有安装的话,进行安装
 2yum install rsync -y
 3
 4# 将 rsync 设置成开启自启,并启动
 5systemctl enable rsyncd
 6systemctl start rsyncd
 7systemctl status rsyncd
 8
 9
10
11
12#新服务器上
13rm -rf /etc/rsyncd.conf
14
15#老服务器上
16scp /etc/rsyncd.conf root@云服务器ip:/etc
17scp /etc/rsyncd.passwd root@云服务器ip:/etc
18
19#新服务器上
20systemctl restart rsyncd
21systemctl status rsyncd

(2)同步/images数据

 1#(1)先把源服务器最新图床数据同步下来
 2#云服务器-->本地:(不含delete)
 3rsync.exe -avPzruh  --port 8730 --password-file=/cygdrive/D/docusaurus/resource/shell/password.txt  root@47.100.215.163::cmi-MdImages/ /cygdrive/D/BaiduSyncdisk/backup/rsync_local/cmi-MdImages-local
 4
 5
 6#(2)从本地向新服务器同步图床数据(本地winodws往云服务器上同步,速度很快哦,6.2G数据,大概30min基本同步完了)
 7#本地-->云服务器:(含delete)(这个推荐只执行一次,特别注意:有时推送时可能会卡主,我们多执行几次就好;6G的数据大概30min;)
 8rsync.exe -avPzruh --delete --port 8730 --password-file=/cygdrive/D/docusaurus/resource/shell/password.txt /cygdrive/D/BaiduSyncdisk/backup/rsync_local/cmi-MdImages-local root@云服务器ip::cmi-MdImages/
 9
10
11#记得处理下
12cd /images/cmi-MdImages-local
13mv * /images/
14cd /images/
15rm -rf cmi-MdImages-local
16
17
18#最新linux-->winodws
19rsync.exe -avPzruh  --port 8730 --password-file=/cygdrive/D/docusaurus/resource/shell/password.txt  root@云服务器ip::cmi-MdImages/ /cygdrive/D/BaiduSyncdisk/backup/rsync_local/cmi-MdImages-local
20
21
22##说明:
23`--delete`:删除目标目录中不在源中存在的文件和目录。

3、更新cdn配置

域名解析保持不变:

image-20241209173526665

这里只配置下cdn就好:

image-20241209173549062

image-20241209173603382

image-20241209173618055

4、更新项目信息

(1)拉取 home3.0项目

1yum install -y git
2cd /root
3git clone https://gitee.com/onlyonexl/home3.0.git
4ls /root/home3.0

(2)推送本地docusaurus静态文件

1mkdir -p /root/rsync/rsync-docusaurus
2
3#推送数据
4rsync.exe -avPzruh --delete --port 8730 --password-file=/cygdrive/D/docusaurus/resource/shell/password.txt /cygdrive/D/docusaurus/build root@云服务器ip::cmi-docusaurus/

(3)利用vscode来替换本地docusaurus里原来ecs ip

image-20241209181120215

image-20241209181146050

win里的vscode这里记得做对新服务器的免密:

1##win10和ecs做免密,方便本地win10 脚本执行相关命令:
2ssh-keygen
3ssh-copy-id -i ~/.ssh/id_ed25519.pub root@云服务器ip ##输入ecs密码
4ssh root@云服务器ip date

5、配置docus Algolia搜索

部署docker

 1#初始环境
 2systemctl stop firewalld
 3systemctl disable  firewalld
 4
 5systemctl stop NetworkManager
 6systemctl disable  NetworkManager
 7
 8setenforce 0
 9sed -i s/SELINUX=enforcing/SELINUX=disabled/ /etc/selinux/config
10
11yum install -y net-tools
12yum install -y vim
13yum install -y wget
14yum install -y lrzsz
15
16yum clean all
17yum makecache
18
19yum remove docker \
20                  docker-client \
21                  docker-client-latest \
22                  docker-common \
23                  docker-latest \
24                  docker-latest-logrotate \
25                  docker-logrotate \
26                  docker-engine
27                  
28yum install -y yum-utils device-mapper-persistent-data lvm2
29yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
30yum makecache
31
32#yum install docker-ce -y
33yum install -y yum install docker-ce-19.03.9 docker-ce-cli-19.03.9 containerd.io #指定需要安装的版本号
34systemctl start docker && systemctl enable docker
35
36docker version
37docker info
38
39
40sudo mkdir -p /etc/docker
41sudo tee /etc/docker/daemon.json <<EOF
42{
43    "registry-mirrors": [
44        "https://hub.uuuadc.top",
45        "https://docker.anyhub.us.kg",
46        "https://dockerhub.jobcher.com",
47        "https://dockerhub.icu",
48        "https://docker.ckyl.me",
49        "https://docker.awsl9527.cn"
50    ]
51}
52EOF
53
54
55cat /proc/sys/net/ipv4/ip_forward
56echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf 
57sysctl -p
58cat /proc/sys/net/ipv4/ip_forward
59
60systemctl daemon-reload
61systemctl restart docker
  • 部署docusaurus aligo搜索
 1#新服务器安装服务
 2yum install -y epel-release
 3yum install -y jq
 4
 5#从老服务器上拷贝数据
 6[root@docusaurus-wiki ~]#scp -r /root/Algolia/ root@云服务器ip:/root
 7#下载镜像
 8docker pull uhub.service.ucloud.cn/onedayxyy/docsearch-scraper:latest
 9docker tag uhub.service.ucloud.cn/onedayxyy/docsearch-scraper:latest algolia/docsearch-scraper:latest
10
11
12#执行
13cd /root/Algolia/
14#docker run -it --env-file=.env -e "CONFIG=$(cat docsearch.json | jq -r tostring)" algolia/docsearch-scraper
15
16#crontab -e
170 1,7,13,19 * * * /root/Algolia/docker.sh >> /var/log/crontab.log 2>&1

部署docker-copmose

1mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
2chmod +x /usr/local/bin/docker-compose #添加执行权限
3docker-compose --version

验证

https://onedayxyy.cn/

https://wiki.onedayxyy.cn/

image-20241209173958591

完美。😜(又可以白嫖1年了)

其它服务

这2个是单独的部署服务。(本次先不配置,文档已有,就是麻烦哈哈)😂

image-20241209181616315

关于我

我的博客主旨:

  • 排版美观,语言精炼;
  • 文档即手册,步骤明细,拒绝埋坑,提供源码;
  • 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!

🍀 微信二维码

x2675263825 (舍得), qq:2675263825。

image-20230107215114763

🍀 微信公众号

《云原生架构师实战》

image-20230107215126971

🍀 csdn

https://blog.csdn.net/weixin_39246554?spm=1010.2135.3001.5421

image-20230107215149885

🍀 知乎

https://www.zhihu.com/people/foryouone

image-20230107215203185

往期推荐

QQ群

《玩转Typora+Docusuaurus+起始页》交流群:(欢迎小伙伴一起探讨有趣的IT技术,来完成一些漂亮的项目)

开源项目:

项目名称我的文档我的demo作者demo
1、玩转Typorahttps://wiki.onedayxyy.cn/docs/typorahttps://wiki.onedayxyy.cn/docs/typorahttps://typoraio.cn/#
2、玩转Docusaurushttps://wiki.onedayxyy.cn/docs/mogai-docusaurushttps://wiki.onedayxyy.cn/https://www.docusaurus.cn/
3、个人主页home3.0https://wiki.onedayxyy.cn/docs/home3.0https://onedayxyy.cn/https://github.com/hsBUPT/hsBUPT.github.io
4、家庭相册filesite-iohttps://wiki.onedayxyy.cn/docs/filesite.io-photot-install-fullhttps://photo.onedayxyy.cn/https://demo.jialuoma.cn/

https://wiki.onedayxyy.cn/docs/OpenSource

image-20241007221810896

  • typora皮肤

https://wiki.onedayxyy.cn/docs/typora

image-20241007221846691

  • 起始页

https://onedayxyy.cn/

image-20240814230557697

  • 知识库/博客

https://wiki.onedayxyy.cn/

  • 个人相册

https://photo.onedayxyy.cn/

image-20241028072523651

最后

好了,关于本次就到这里了,感谢大家阅读,最后祝大家生活快乐,每天都过的有意义哦,我们下期见!

推荐使用微信支付
微信支付二维码
推荐使用支付宝
支付宝二维码
最新文章

文档导航