centos部署hexo+github+next主题博客

准备工作

  • 系统环境centos7
  • 用邮箱注册github帐号

    1.安装Node.js

  • 下载
    进入node.js官网找到最新版本,复制下载链接,下面以11.5.0版本为例
    1
    wget https://nodejs.org/dist/v11.5.0/node-v11.5.0-linux-x64.tar.xz
  • 解压

    1
    tar -xvJf node-v11.5.0-linux-x64.tar.xz #大写J
  • 重命令文件夹并移动文件夹到/usr/local/node目录下

    1
    mv node-v11.5.0-linux-x64.tar.xz  /usr/local/node/node
  • 配置环境变量

    1
    2
    echo "export PATH=$PATH:/usr/local/node/bin" >> /etc/profile
    source /etc/profile

2.安装Hexo

1
2
3
4
5
mkdir hexo
cd hexo
yum install git-core #安装git,已安装可跳过
npm install -g hexo-cli #安装Hexo
hexo init #初始化Hexo

3.安装Hexo插件 安装报错,安装慢请点击这里

1
2
3
4
5
6
7
8
9
10
11
12
13
npm install hexo-generator-index --save
npm install hexo-generator-archive --save
npm install hexo-generator-category --save
npm install hexo-generator-tag --save
npm install hexo-server --save
npm install hexo-deployer-git --save
npm install hexo-deployer-heroku --save
npm install hexo-deployer-rsync --save
npm install hexo-deployer-openshift --save
npm install hexo-renderer-marked --save
npm install hexo-renderer-stylus --save
npm install hexo-generator-feed --save
npm install hexo-generator-sitemap --save

5.部署github

  • 1.配置本机全局git环境,已配置可跳过
    1
    2
    git config --global user.email "example@exp.com"            #注册github的邮箱帐号
    git config --global user.name "username" #github用户名
  • 2.生成ssh密钥

    1
    2
    ssh-keygen -t rsa -C example@exp.com        #注册github的邮箱
    less ~/.ssh/id_rsa.pub #查看ssh公钥,并手动复制
  • 3.创建仓库
    进入github官网登陆github帐号,创建一个仓库,仓库名称必须为: 用户名.github.io

  • 4.添加ssh密钥到github
    点击链接https://github.com/settings/ssh 在key输入框粘贴刚才复制的ssh密钥,Title 随便填。

6.修改Hexo配置文件

1
vim _config.yml

#按照以下代码修改文件底端,将username替换成自己的github用户名

1
2
3
4
5
6
7
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: git@github.com:username/username.github.io.git
branch: master
message: '站点更新:{{now("YYYY-MM-DD HH/mm/ss")}}'

7.编译并上传代码到github仓库

1
2
hexo g         #编译
hexo d #上传

至此打开浏览器输入你的github仓库名就可访问到你的博客了。下一篇文章将会将如何切换主题以及主题优化