玩命加载中 . . .

heexo 部署到腾讯云


目前就是部署完了,就等备案通过了。

一、部署环境与准备

1.环境

本地:Windows10操作系统

腾讯云:Cenots7.6服务器

2.准备

Hexo 本地博客

Xshell 链接到你的服务器

二、云服务器配置Git

1.安装依赖库

1
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel 

2.安装编译工具

1
yum install gcc perl-ExtUtils-MakeMaker package

3.查看git的版本

1
git version

4.删除git

1
yum remove git -y

5.下载解压最新版

1
2
3
cd /usr/local/src    #下载的目录
wget https://www.kernel.org/pub/software/scm/git/git-2.31.1.tar.gz #下载最新版,可以去https://www.kernel.org/pub/software/scm/git/查看最新版本号,后面进行相应修改
tar -zxvf git-2.31.1.tar.gz #解压到当前文件夹

6.编辑并安装

1
2
3
cd git-2.31.1    #进入文件夹
make prefix=/usr/local/git all #编译源码
make prefix=/usr/local/git install #安装路径

7.配置git的环境变量

1
echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/bashrc

8.刷新环境变量

1
source /etc/bashrc

9.查看版本号

1
git --version

10.创建git用户并且修改权限

1
2
3
4
5
6
7
8
adduser BTMuli #这里的"BTMuli"是用户名
passwd BTMuli #这里的"BTMuli"是用户名
chmod 740 /etc/sudoers
vim /etc/sudoers
# "i"进入编辑模式,修改为如下代码:
root ALL=(ALL) ALL
BTMuli ALL=(ALL) ALL
# "Esc"退出编辑,按":wq"保存

11.本地windows10使用Gitbash创建密钥

1
ssh-keygen -t rsa

12.将本地创建id_rsa.pub中文件复制

1
2
3
4
5
su BTMuli
mkdir ~/.ssh
vim ~/.ssh/authorized_keys
# "i"进入编辑模式,把sshkey粘贴进来
# "Esc"退出编辑,按":wq"保存

13.本地测试

1
ssh -v BTMuli@服务器ip

三、云服务器网站配置

1.创建网站目录并且设置权限

1
2
3
su root
mkdir /home/MyBlog
chown BTMuli:BTMuli -R /home/MyBlog

2.安装Nginx

1
2
yum install -y nginx
systemctl start nginx.service #启动服务

3.修改Nginx配置文件

1
2
3
4
5
6
7
vim /etc/nginx/nginx.conf 
# 按"i"进入编辑模式,修改为如下代码:
38 server {
39 listen 80 default_server;
40 listen [::]:80 default_server;
41 server_name btmuli.site; #域名
42 root /home/MyBlog; #网站目录

4.重启服务器

1
systemctl restart nginx.service

5.建立git仓库

1
2
3
4
su root
cd /home/BTMuli
git init --bare blog.git
chown BTMuli:BTMuli -R blog.git

6.同步网站根目录

1
2
3
4
vim blog.git/hooks/post-receive
# "i"进入编辑模式,把sshkey粘贴进来
#!/bin/sh
git --work-tree=/home/MyBlog --git-dir=/home/BTMuli/blog.git checkout -f

7.修改权限

1
chmod +x /home/BTMuli/blog.git/hooks/post-receive

8.在windows10本地heexo目录修改_config.yml文件

1
2
3
4
5
6
deploy:
type: git
repository:
- https://github.com/BTMuli/BTMuli.github.io
- BTMuli@81.71.129.119:/home/BTMuli/blog.git #用户名@服务器Ip:git仓库位置
branch: main

9.在本机gitbash部署

1
2
hexo clean
hexo g -d

四、常见报错

1. git-upload-pack: 未找到命令

1
2
bash: git-upload-pack: command not found
fatal: Could not read from remote repository.

解决方法

1
sudo ln -s  /usr/local/git/bin/git-upload-pack  /usr/bin/git-upload-pack

2.git-receive-pack: 未找到命令

1
2
bash: git-receive-pack: command not found
fatal: Could not read from remote repository.

解决方法

1
sudo ln -s /usr/local/git/bin/git-receive-pack  /usr/bin/git-receive-pack

3.无法远程连接获取

1
fatal: Could not read from remote repository.

解决方法

1
重试或者 删掉本地ssh公钥重新上传至服务器

4.key出错

1
Host key verification failed.

解决方法

1
ssh-keygen -R 你要访问的IP地址

参考文章:


Author: 目棃
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source 目棃 !
评论
评论
评论
评论
评论
  TOC
过节
福到
小程序