Hexo

服务器Git部署

前提条件:本地ssh公匙(C:\Users\Reiki.ssh\id_rsa.pub),已配置服务器:

1
2
3
adduser git
chmod 740 /etc/sudoers
vim /etc/sudoers

root ALL=(ALL) ALL 下面添加

1
git    ALL=(ALL)   ALL

改回权限,设置git用户密码

1
2
chmod 400 /etc/sudoers
passwd git
1
2
3
su git
mkdir ~/.ssh
vim ~/.ssh/authorized_keys

粘贴 本地ssh公匙

本地测试

1
ssh -v git@111.1111.111.111

若免密登录,成功!

###准备两个目录

1.网站目录

1
2
mkdir /www/wwwroot/hexo
chmod -R 755 /www/wwwroot/hexo

2.git仓库目录

1
2
3
mkdir /home/git/repo
chown -R git:git /home/git/repo
chmod -R 755 /home/git/repo

创建git钩子

1
2
cd /home/git/repo
git init --bare hexo.git

创建钩子文件

1
vim /home/git/repo/hexo.git/hooks/post-receive

粘贴以下代码

1
2
#!/bin/bash
git --work-tree=/www/wwwroot/hexo --git-dir=/home/git/repo/hexo.git checkout -f

改权限钩子文件两个目录

1
2
3
4
5
chown -R git:git /home/git/repo/hexo.git/hooks/post-receive
chmod +x /home/git/repo/hexo.git/hooks/post-receive

chown -R git:git /www/wwwroot/hexo
chown -R git:git /home/git/repo

本地配置

_config.yml

1
2
3
4
5
deploy:
type: git
repo: git@1.1.1.1:22/home/git/repo/hexo.git
branch: master

1.1.1.1:22 为服务器IP + SSH访问端口

配置RSS

前置条件

  1. 安装 hexo-generator-feed

    1
    npm install hexo-generator-feed --save
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# rss 生成插件 hexo-generator-feed
feed:
enable: true
generator: true
type: atom
path: atom.xml
limit: false
hub:
content: true
# content_limit: 140
# content_limit_delim: ' '
order_by: -date
# icon: icon.png
# autodiscovery: true
# template:


social:
# 其他社交按钮
RSS: /atom.xml || fa fa-rss
# 与配置文件 链接保持一致
fas fa-rss: https://xxx.xx/atom.xml

本地启动推送

前置条件

  1. 安装 NodeJs,可使用 NVM 进行管理

  2. npm install -g hexo-cli
    
1
2
hexo clean
hexo g -d

主题升级

主题目录下

1
2
3
git stash
git pull
git stash pop

若git仓库不安全报错

1
git config --global --add safe.directory E:/blog/Hexo/themes/butterfly