最重要的一点,一定要看环境的版本号,ccc

最简单的部署 hexo-script使用文档
Nodejs下载网址:淘宝源
坑总结:

  • 原因:node版本过高,我换成了12的版本
    (node:14124) Warning: Accessing non-existent property ‘lineno’ of module exports inside circular dependency
    (Use node --trace-warnings ... to show where the warning was created)
    (node:14124) Warning: Accessing non-existent property ‘column’ of module exports inside circular dependency
    (node:14124) Warning: Accessing non-existent property ‘filename’ of module exports inside circular dependency
    (node:14124) Warning: Accessing non-existent property ‘lineno’ of module exports inside circular dependency
    (node:14124) Warning: Accessing non-existent property ‘column’ of module exports inside circular dependency
    (node:14124) Warning: Accessing non-existent property ‘filename’ of module exports inside circular dependency
  • 比较详细的坑:来自简书的坑

安装过程

本地环境配置

环境准备:

  • git
  • node

安装Hexo

官方:文档|hexo

  1. CMD中:
    npm install -g hexo-cli

出现:npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\hexo-cli\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
原因:windows的正常现象(fsevent是mac系统的,在win或者Linux下使用了,所以会有警告,忽略即可。fsevent的作用是能够检测文件目录的修改,可以记录恶意软件的非法操作,获取恶意软件的完整路径,删除和修改日期) 处理方法

  1. 本地博客根目录安装目录打开Git Bash
    hexo init blog
    安装过程中,他会自动生成一个文件夹,这个文件夹就是Hexo的配置文件,名字为blog(可以在代码修改)
    完成本地部署
  1. 进入文件夹,用hexo s这个命令来启动Hexo
    输入它提示的网站 127.0.0.1:4000 进去之后就可以找到
    本地查看

  2. 常用命令
    hexo clean

云端

准备:云端centos7.6、本地win10

  1. 安装依赖库
    yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel

  2. 安装编译工具
    yum install gcc perl-ExtUtils-MakeMaker package

  3. 查看git的版本y
    git version

  4. 删除git
    yum remove git -y

  5. 下载解压最新版
    cd /usr/local/src #下载的目录
    wget https://www.kernel.org/pub/software/scm/git/git-2.28.0.tar.gz #下载最新版
    tar -zxvf git-2.28.0.tar.gz #解压到当前文件夹

  6. 编辑并安装
    cd git-2.28.0 #进入文件夹
    make prefix=/usr/local/git all #编译源码,有些慢需要等待
    make prefix=/usr/local/git install #安装路径

  7. 配置git的环境变量
    echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/bashrc

  8. 刷新环境变量
    source /etc/bashrc

  9. 查看版本号
    git --version
    不出错的话会返回

    [root@VM-8-4-centos git-2.28.0]# git –version
    git version 2.28.0

  10. 创建git用户并且修改权限
    adduser tkds
    passwd tkds #修改密码
    chmod 740 /etc/sudoers
    vim /etc/sudoers

    root ALL=(ALL) ALL
    fuchen ALL=(ALL) ALL

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

ssh-keygen -t rsa
12. 将本地创建id_rsa.pub中文件复制

su tkds
mkdir ~/.ssh
vim ~/.ssh/authorized_keys
13. 本地测试
ssh -v tkds@ip

key出错:
Host key verification failed.
解决方法: ssh-keygen -R ip

三、云服务器网站配置
1.创建网站目录并且设置权限

su root
mkdir /home/hexo
chown fuchen:fuchen -R /home/hexo
2.安装Nginx

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

[root@VM-8-4-centos ~]# rpm -qa|grep yum
yum-utils-1.1.31-54.el7_8.noarch
yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch
yum-langpacks-0.4.2-7.el7.noarch
yum-3.4.3-167.el7.centos.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64

rpm -ivh –force –nodeps https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm
rpm -ivh –force –nodeps https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
rpm -ivh –force –nodeps https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-langpacks-0.4.2-7.el7.noarch.rpm
rpm -ivh –force –nodeps https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
rpm -ivh –force –nodeps https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
3.修改Nginx配置文件

nginx
vim /etc/nginx/nginx.conf

38 server {
39 listen 80 default_server;
40 listen [::]:80 default_server;
41 server_name fuchenchenle.cn; #域名
42 root /home/hexo; #网站目录
4.重启服务器

systemctl restart nginx.service
5.建立git仓库

su root
cd /home/fuchen
git init –bare blog.git
chown fuchen:fuchen -R blog.git
6.同步网站根目录

vim blog.git/hooks/post-receive

#!/bin/sh
git –work-tree=/home/hexo –git-dir=/home/fuchen/blog.git checkout -f
7.修改权限

chmod +x /home/fuchen/blog.git/hooks/post-receive
8.在windows10本地hexo目录修改_config.yml文件

deploy:
type: git
repository: fuchen@49.232.59.235:/home/fuchen/blog.git #用户名@服务器Ip:git仓库位置
branch: master
9.在本机gitbash部署

hexo clean
hexo g -d
四、常见报错

  1. git-upload-pack: 未找到命令
    bash: git-upload-pack: command not found
    fatal: Could not read from remote repository.
    解决方法

sudo ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack
2.git-receive-pack: 未找到命令
bash: git-receive-pack: command not found
fatal: Could not read from remote repository.
解决方法

sudo ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack
3.无法远程连接获取
fatal: Could not read from remote repository.
解决方法

重试或者 删掉本地ssh公钥重新上传至服务器
4.key出错
Host key verification failed.
解决方法

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

来源: Fuchenchenle
文章作者: Fuchenchenle
文章链接: http://fuchenchenle.cn/2020/08/18/hexo%E9%83%A8%E7%BD%B2%E8%85%BE%E8%AE%AF%E4%BA%91/#toc-heading-2
本文章著作权归作者所有,任何形式的转载都请注明出处。