一、本地安装 hexo
初始化安装
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
| npm install -g hexo-cli
hexo init blog
cd blog && npm install
npm install hexo-theme-next hexo-generator-searchdb --save
vim _config.yml language: zh-CN theme: next url: https://<your_website>.com new_post_name: :year-:month-:day-:title.md
cp node_modules/hexo-theme-next/_config.yml _config.next.yml
vim _config.yml search: path: search.xml field: post format: html limit: 1000
vim _config.next.yml local_search: enable: true
hexo server
|
部署已有 hexo
1 2 3 4 5
| npm install -g hexo-cli git clone git@github.com:wanglongbiao/blog.git cd blog && npm i hexo server
|
二、发布到 服务器
通过在服务器上配置一个 git 服务器,实现自动部署。
服务器端设置
服务器可以使用 nginx,也可以使用宝塔面板。宝塔比较方便。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| useradd git && passwd git
mkdir /var/www/hexo chown -R git:git /var/www/hexo
su git && cd git init --bare blog.git
vim blog.git/hooks/post-receive #!/bin/sh git --work-tree=/var/www/hexo --git-dir=/var/repo/blog.git checkout -f
chmod +x blog.git/hooks/post-receive
|
本地配置
1 2 3 4 5 6 7 8 9 10 11 12 13
| cd blog npm install hexo-deployer-git -g
deploy: type: git repo: git@x.x.x.x:blog.git
ssh-copy-id git@x.x.x.x
hexo deploy --generate
|
顺利的话,到这里就完成了。
遇到的问题
1 2 3 4 5 6 7 8 9 10 11 12 13
| 问题:更换默认主题后,执行 `hexo server` 时报错 err: Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed 解决:npm install hexo-renderer-pug hexo-renderer-stylus
问题:Authentication refused: bad ownership or modes for file 解决:删除 authorized_keys,重新 ssh-copy-id
问题:服务器的端口不是 22 解决:vim ~/.ssh/config,在这个文件中配置端口 Host x.x.x.x Port yyyy
npm install hexo-renderer-pug hexo-renderer-stylus
|