博客服务器迁移

为什么迁移???
》》》老账号已经购买过 200元/3年(2核4G内存),
》》》3年后,服务器到期,就不能使用新用户特惠购买了,续费1500元/1年,太贵,续费不起,
》》》
》》》采取方案:老账号解绑微信,使用微信注册新账号,再联系淘宝(自己购买不行,因为自己没有活动链接),购买575元/4年(2核2G内存)。

1
2
3
4
5
6
7
8
9
10
11
2024-12-18 20:59:20 迁移完毕

《坑》
--------------------------------
1. * 博客 Nginx IP 忘记更换
2. 对 DNS、SSL、CDN 不太了解,从头捋了一遍
对于腾讯云的 HTTPS 搞了好久,试错,一点点摸索出来了
* 开启 HTTPS、就不要设置 443 Nginx 了
3. 关于 MySQL、PG 迁移,
一开始想着 data 目录文件迁移,
* 因为过大,scp传输慢,后面才转换了思路 SQL文件迁移

注册新账号

1
2
3
4
5
6
7
解绑关联微信
主账号 解绑微信、绑定MFA

新微信注册
绑定大王卡
个人认证 - 微信扫码
MFA

购买服务器

1
2
3
4
5
6
7
淘宝购买 2c2g - 4年 - 575
到期时间 2028-12-17 12:07:27

设置密码 腾讯云密码
公网 124.223.207.153

防火墙配置(仿照以前)

Linux初始化

参考:我的 Linux 初始化

yum

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 更新 yum 源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum -y update

# ifconfig netstat
yum -y install net-tools
# ping
yum -y install iputils
# telnet
yum -y install telnet
# ip
yum -y install iproute
# 压缩/解压 zip
yum -y install zip unzip
# Coreutils 软件包包括一整套基本的 shell 工具。
# 是GNU提供了一整套比较基本的工具软件包,是这些工具的集合。
# 其本身是需要依赖shell程序的。
yum -y install coreutils
# wget
yum -y install wget
# curl
yum -y install curl
# scp
# 远程的东西 -> 本地 scp -r 用户名@主机名:远程路径 本地路径
# 本地的东西 -> 远程 scp -r 本地路径 用户名@主机名:远程路径
yum -y install openssh-clients
# vim
yum -y install vim
# man 中文
yum -y install man-pages-zh-CN
# 命令补全
yum -y install bash-completion
# sz-rz
yum -y install lrzsz

交换内存

1
2
3
4
5
6
7
8
# 查看交换内存
swapon -s

# 查看交换内存(第二行 swap)
free -h

# 禁用交换内存
sudo swapoff -a

语言

1
2
echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf
source /etc/profile.d/lang.sh

时区

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 查看时间
date
hwclock

# 同步上海时间
rm -rf /etc/localtime ; ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# 同步阿里服务器时间
yum -y install ntp ntpdate
ntpdate ntp1.aliyun.com

# 软硬时间同步
/sbin/hwclock --systohc

# 再次查看
date
hwclock

diy.sh

1
2
3
4
5
6
7
8
9
10
11
vim /etc/profile.d/diy.sh

# 16个 - 减号
PS1=----------------

# 文件显示时间格式 yyyy-MM-dd HH:mm:ss
export TIME_STYLE='+%Y-%m-%d %H:%M:%S'

# history 大小(10w,默认1k)
export HISTFILESIZE=100000
export HISTSIZE=100000

vim

1
2
3
4
5
6
7
8
yum -y install vim

cat > ~/.vimrc << 'EOF'
set nu " 显示行号
set autoindent " 自动缩排(回车后,会自动与上一行对齐)

" 注释 这个文件的注释符合是英文双引号 ",而不是井号 #
EOF

防火墙

1
2
3
4
5
6
# 停止,并永久禁用
systemctl stop firewalld && systemctl disable firewalld

# 安装再停止
yum -y install iptables-services
systemctl stop iptables && systemctl disable iptables

selinux

1
2
3
4
5
6
7
# Redhat使用了SELinux来增强安全,关闭的办法为:
# 永久有效
# 修改 /etc/selinux/config 文件中的 SELINUX=enforcing ===> SELINUX=disabled,然后重启。
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

## 临时生效
setenforce 0

Docker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 0. 更新 yum(这个会久一点,如果卡死了,就重新执行此命令)
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum -y update

# 1. 安装工具
yum -y install yum-utils

# 2. 添加软件源信息 #===> 执行其中一个就行了,第一个是官网,第二个是阿里云
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 3. 安装新版 Docker #===> 如果下载太慢,结束命令,换个镜像源再进行下载
yum -y install docker-ce docker-ce-cli containerd.io

# 4. 添加镜像加速
mkdir -p /etc/docker/
cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": [
"https://docker.1ms.run",
"https://hub.rat.dev",
"https://docker.1panel.live"
]
}
EOF

# 5. 重新加载配置文件
systemctl daemon-reload

# 6. 启动 Docker,并设置开机自启动
systemctl restart docker ; systemctl enable docker

# 7. 关闭防火墙,并永久禁用
systemctl stop firewalld ; systemctl disable firewalld
# 安装再停止
yum -y install iptables-services
systemctl stop iptables && systemctl disable iptables

# 8. docker 命令 tab 补全
yum -y install bash-completion

source /usr/share/bash-completion/bash_completion ; source /usr/share/bash-completion/completions/docker

# 9. 查看版本
docker -v

Git Blog

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 安装Node.js   ===>   https://nodejs.org/zh-cn/download/package-manager/
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
exit # 重启终端
nvm install 12
nvm alias default 12
node -v
npm -v

npm config set registry http://registry.npm.taobao.org
npm -g install hexo-cli@4.2.0
hexo -v

yum -y install git
git --version
git config --global http.sslverify false
git config --global https.sslverify false
ssh-keygen -t rsa -C "18574150851" # 回车三次
cat /root/.ssh/id_rsa.pub # 把内容复制,添加公钥 https://gitee.com/taopanfeng/blog/deploy_keys

mkdir -p /app/git/ ; cd /app/git/
git clone https://gitee.com/taopanfeng/blog.git # 大王卡、YY密码
cd blog/
rm -rf node_modules && npm install --force # 报错也不用管
hexo s -p 80

vi /app/git/blog/.git/config
#[remote "origin"]
# url = https://大王卡:YY密码@gitee.com/taopanfeng/blog.git

脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cat > /root/hexo.sh << 'EOF'
# 进入目录
cd /app/git/blog

# 更新数据
git pull

# 杀死进程
#kill -9 $(netstat -atlunp | grep 4000 | awk '{print $7}' | cut -d '/' -f 1)
hexo_pid=$(ps aux | grep hexo | grep -v grep | grep -v sh | awk '{print $2}')
kill -9 ${hexo_pid}

# 重新生成 index(搜索 algolia)
export HEXO_ALGOLIA_INDEXING_KEY="fd04620183f122e80ec0d57ea40bfb2f";hexo algolia

# 重新后台启动(默认 4000端口)
hexo s &

EOF

DNS、SSL、CDN

阿里云 域名解析 DNS
腾讯云 CDN
腾讯云 SSL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
阿里云
- 域名解析 - 删除所有记录
老腾讯云
- 删除所有证书、证书托管
- 删除CDN解析
新腾讯云
1. 充值5元
2. SSL
- 申请免费
- 填写域名 taopanfeng.com
- 手动验证
- 阿里云 域名解析 - 添加一条记录
- 验证
3. CDN
- 加速区域 全球
- 加速域名 添加1 taopanfeng.com 添加2 www.taopanfeng.com
- 加速类型 CDN网页小文件
- 自有源、HTTP、源地址 124.223.207.153 80
- 回源HOST taopanfeng.com

- 推荐配置 - 跳过

- 配置 CNAME - 验证生效(也可以使用下面方式验证)
nslookup -qt=cname taopanfeng.com
nslookup -qt=cname www.taopanfeng.com

- 再修改:
[HTTPS配置] 开启HTTPS
[HTTPS配置] 配置证书 - 选择托管证书
[HTTPS配置] 开启HTTPS 2.0
[HTTPS配置] 强制跳转 - http->https 301-永久跳转 携带头部-是
[回源配置] 回源跟随301/302配置 - 开启

- 等待 显示部署完成

Nginx

1
2
3
4
5
6
7
8
9
10
11
# 老服务器
yum -y install openssh-clients # scp命令
scp -r /app/docker/nginx root@124.223.207.153:/app/docker # 记得新服务器 放开22端口、提前创建好 /app/docker 目录



docker run --name nginx01 -p 80:80 -p 443:443 \
-v /app/docker/nginx/conf/:/etc/nginx/ \
-v /app/docker/nginx/html/:/usr/share/nginx/html \
-v /app/docker/nginx/log/:/var/log/nginx \
-d nginx:1.21.5

ssl.conf
(1、注意ip的配置)
(2、CDN配置 HTTPS 证书后,这里 Nginx 就不用配置 443了,我一直失败,最后才知道)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
server {
listen 80;
server_name taopanfeng.com;
location / {
proxy_pass http://10.0.16.16:4000;
}

# -------------------------------------------------------------------------------
location /todo {
alias /usr/share/nginx/html/todo/dist/;
index index.html index.html;
try_files $uri $uri/ /todo/index.html;
}# 001-小黑记事本
location /find-job-record {
alias /usr/share/nginx/html/find-job-record/dist/;
index index.html index.html;
try_files $uri $uri/ /find-job-record/index.html;
}# 002-面经-基础版
location /taopanfeng-shopping {
alias /usr/share/nginx/html/taopanfeng-shopping/dist/;
index index.html index.html;
try_files $uri $uri/ /taopanfeng-shopping/index.html;
}# 003-智慧商城
location /big-event-admin {
alias /usr/share/nginx/html/big-event-admin/dist/;
index index.html index.html;
try_files $uri $uri/ /big-event-admin/index.html;
}# 004-大事件
location /xtx {
alias /usr/share/nginx/html/xtx/dist/;
index index.html index.html;
try_files $uri $uri/ /xtx/index.html;
}# 005-小兔鲜
location /uni-app-rabbit-shop {
alias /usr/share/nginx/html/uni-app-rabbit-shop/dist/;
index index.html index.html;
try_files $uri $uri/ /uni-app-rabbit-shop/index.html;
}# 006-uni-app小兔鲜
# -------------------------------------------------------------------------------
}

MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# --------------------------------------------------------------------
# 1. 新服务器 启动 MySQL(替换密码)
docker run --name mysql01_tencent_password -p 3306:3306 \
-v /app/docker/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=腾讯云密码 -d mysql:8.0 \
--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

docker exec -it mysql01_tencent_password bash

mysql -uroot -p腾讯云密码

alter user 'root'@'%' identified with caching_sha2_password by '腾讯云密码';

exit

exit

# dbeaver 连接 --- 设置 allowPublicKeyRetrieval=TRUE

# --------------------------------------------------------------------
# 2. 老服务器 备份sql(数据库 全量复制)
docker exec -it mysql01_tencent_password bash
mysqldump -uroot -p --all-databases > /mysql.sql
exit
docker cp mysql01_tencent_password:/mysql.sql /tmp
scp -r /tmp/mysql.sql root@124.223.207.153:/tmp

# --------------------------------------------------------------------
# 3. 新服务器 导入sql(数据库 全量复制)
docker cp /tmp/mysql.sql mysql01_tencent_password:/
docker exec -it mysql01_tencent_password bash
mysql -uroot -p < /mysql.sql
exit
# dbeaver 检查一下

PG

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# --------------------------------------------------------------------
# 1. 新服务器 启动 PG(替换密码)
docker run -d \
--name postgresql01_tencent_password \
-e POSTGRES_PASSWORD="腾讯云密码" \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v /app/docker/pg:/var/lib/postgresql/data \
--net host \
--restart always \
postgres:17

# dbeaver 检查一下

# --------------------------------------------------------------------
# 2. 老服务器 备份sql(数据库 一个个复制)
docker exec -it postgresql01_tencent_password bash
pg_dump -U postgres -F p -b -v -f /pump_energy.sql pump_energy
pg_dump -U postgres -F p -b -v -f /student.sql student
exit
docker cp postgresql01_tencent_password:/pump_energy.sql /tmp
docker cp postgresql01_tencent_password:/student.sql /tmp
scp -r /tmp/pump_energy.sql root@124.223.207.153:/tmp
scp -r /tmp/student.sql root@124.223.207.153:/tmp

# --------------------------------------------------------------------
# 3. 新服务器 导入sql(数据库 一个个复制)
docker cp /tmp/pump_energy.sql postgresql01_tencent_password:/
docker cp /tmp/student.sql postgresql01_tencent_password:/
docker exec -it postgresql01_tencent_password bash
createdb -U postgres pump_energy
createdb -U postgres student
psql -U postgres -f /pump_energy.sql pump_energy
psql -U postgres -f /student.sql student
exit