0%

迁移博客到腾讯云

说明

  • 之前博客在gitee pages写,最近老是抽风说我的内容出现违规文字,然后又不提示具体哪些内容违规,因此迁移到腾讯云上
  • 需要提前准备:腾讯云主机和已经备案的域名
  • 核心流程其实就算本地写博客内容,最终把source目录下面的静态内容推送到远程服务器上(腾讯云,gitee page)

腾讯云配置

安装git

  • 安装依赖库
1
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel 
  • 安装编译工具
1
yum install gcc perl-ExtUtils-MakeMaker package
  • 选择一个目录来存放下载下来的 git 安装包。这里选择了/usr/local/src 目录
1
cd /usr/local/src
  • 到官网找一个新版稳定的源码包下载到 /usr/local/src 文件夹里
1
[root@VM-24-13-centos src]# wget --no-check-certificate  https://www.kernel.org/pub/software/scm/git/git-2.16.2.tar.gz
  • 解压编译git
1
2
3
tar -zvxf git-2.16.2.tar.gz
cd git-2.16.2
make all prefix=/usr/local/git
  • 安装 git 到 /usr/local/git 目录下
1
make install prefix=/usr/local/git
  • 配置git环境变量
1
2
3
4
echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/bashrc
source /etc/bashrc
[root@VM-24-13-centos git-2.16.2]# git --version
git version 1.8.3.1
  • 创建 git 仓库,用于存放博客网站资源,在 home/git 的目录下,创建一个名为hexoBlog的裸仓库(bare repo)。
1
2
3
mkdir /home/git/
chown -R $USER:$USER /home/git/
chmod -R 755 /home/git/
  • 然后,执行如下命令
1
2
3
4
cd /home/git/
[root@VM-24-13-centos git]# git init --bare hexoBlog.git
Initialized empty Git repository in /home/git/hexoBlog.git/

  • 创建一个新的 git 钩子,用于自动部署,在 /home/git/hexoBlog.git 下,有一个自动生成的 hooks 文件夹。我们需要在里边新建一个新的钩子文件 post-receive
1
vi /home/git/hexoBlog.git/hooks/post-receive
  • 在该文件中添加两行代码(将下边的代码粘贴进去),指定 Git 的工作树(源代码)和 Git 目录(配置文件等)
1
2
#!/bin/bash
git --work-tree=/home/hexoBlog --git-dir=/home/git/hexoBlog.git checkout -f
  • 修改文件权限,使得其可执行
1
chmod +x /home/git/hexoBlog.git/hooks/post-receive
  • 到这里,我们的 git 仓库算是完全搭建好了。下面进行 Nginx 的配置。

nginx

  • 安装nginx
1
yum install -y nginx
  • 启动发现报错了
1
systemctl start nginx
  • 查看下撒情况
1
2
systemctl status nginx.service
Feb 25 09:20:06 VM-24-13-centos systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
  • 我之前转过httpd服务,默认用的也是80端口,把httpd服务停掉即可
1
2
3
4
[root@VM-24-13-centos git]# systemctl stop httpd
[root@VM-24-13-centos git]# systemctl start nginx
[root@VM-24-13-centos git]#

  • 测试nginx,wget http://127.0.0.1
1
2
3
4
5
6
root@VM-24-13-centos git]# wget http://127.0.0.1
--2022-02-25 09:24:52-- http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4833 (4.7K) [text/html]
Saving to: ‘index.html’
  • 配置 Nginx 托管文件目录,创建 /home/hexoBlog目录,用于 Nginx 托管
1
2
3
mkdir /home/hexoBlog/
chown -R $USER:$USER /home/hexoBlog/
chmod -R 755 /home/hexoBlog/
  • 查看 Nginx 的默认配置的安装位置
1
2
3
4
root@VM-24-13-centos git]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

  • 修改Nginx的默认配置,其中 cd 后边就是刚才查到的安装位置
1
vi /etc/nginx/nginx.conf

将其中的 root 值改为 /home/hexoBlog (刚才创建的托管仓库目录)。将 server_name 值改成你的域名。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
user root; #我这里改为了root


server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/hexoBlog; #需要修改

server_name www.shikun.work; #需要修改

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
  • 重启nginx服务
1
systemctl restart nginx

至此,服务器端配置就结束了。接下来,就剩下本地 hexo 的配置更改了。

修改hexo配置

  • 打开你本地的 hexo 博客所在文件,打开站点配置文件(不是主题配置文件),做以下修改。
1
2
3
4
deploy:
type: git
repo: root@ip:/home/git/hexoBlog
branch: master
  • 打开hexo根目录执行,输入密码即可提交到云服务器
1
hexo cl && hexo g && hexo d

image-20220225102722571