部署hexo到github


部署hexogithub

1. 申请github账号

  1. 进入https://github.com/申请,我这里申请的用户名是lmwings
  2. 建立个人仓库,仓库名为lmwings.github.io,这个是规则是固定的,一个账号只有一个github page页面. 即<用户名>.github.io

2. 上传

把本地验证好的hexo个人网站,上传到lmwings.github.io仓库中

  1. windows安装好git

  2. 打开Git Bash,输入github相关账号

    git config --global user.name "你的GitHub用户名"
    git config --global user.email "你的GitHub注册邮箱"
  3. 生成ssh密钥文件

    ssh-keygen -t rsa -C "你的GitHub注册邮箱"

    直接一直回车即可,然后找到生成的.ssh文件夹中的id_rsa.pub文件,把内容全部复制

    https://github.com/settings/keys页面中新建new SSH Key,标题随便起。

  4. 验证密钥是否成功

    git bash中输入ssh git@github.com

    Administrator@JIKXYRXHZ8CSKUY MINGW64 /e/work/hexo_blog
    $ ssh git@github.com
    PTY allocation request failed on channel 0
    Hi lmwings! You've successfully authenticated, but GitHub does not provide shell access.
    Connection to github.com closed.
    
    Administrator@JIKXYRXHZ8CSKUY MINGW64 /e/work/hexo_blog
    
  5. hexo一些命令

    # 新建文章
    hexo n 新建文章1
    # 新建页面
    hexo page categorys
    # 生成
    hexo g
    # 启动服务预览
    hexo s
    # 部署
    hexo d
    # 清除缓存
    hexo clean
  6. 修改本地hexo代码根目录下的_config.ymal配置

    deploy:
      type: git
      repo: https://github.com/lmwings/lmwings.github.io.git
      branch: master
  7. 按照部署插件

    npm install hexo-deployer-git --save
  8. 推送部署

    hexo clean
    hexo g
    hexo d
  9. 访问验证

    lmwings.github.io

部署到其他平台

部署到coding

由于github是国外的,在国内访问较慢,所以我同时部署到giteecoding上面。

步骤大部分和github上面部署是一样的,下面做简单的记录

  1. 部署到coding

    首先https://coding.net/申请账号

    这里会要求先创建团体,再创建用户,可以按自己随便起,里面可以修改。

    然后,创建一个和自己的用户名一样的项目仓库, 注意: 启用README.md文件初始化项目 ,最好打钩,否则可能找不到master分支

    ,配置ssh公钥,这个步骤就是github部署时候的第3步,电脑中生成的id_rsa.pub文件即为公钥,为了能在多个代码托管平台工作,需要生成一个新的。这里输入的coding就是生成是公钥文件名

    # Windows默认生成的路径
    $ cd /c/Users/Administrator/.ssh
    
    # 生成公钥文件,后面邮箱是我注册的邮箱地址,输入文件名为 coding即会生成 coding.pud文件
    $ ssh-keygen -t rsa -b 4096 -C 1321559220@qq.com
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): coding

    然后把coding.pub的内容填写到https://lmwings.coding.net/user/account/setting/keys

    测试一下是否设置正常

    ssh -T git@e.coding.net

    发现测试失败, 提示git@git.coding.net: Permission denied (publickey).

    这个要么就是git账号错误,要么就是ssh -T命令输入错误了.

  2. 配置hexo根目录下的_config.yml

    deploy:
      type: git
      repo: 
        github: https://github.com/lmwings/lmwings.github.io.git,master
        coding: https://e.coding.net/lmwings/lmwings.git,master
  3. 推送部署

    hexo clean
    hexo g
    hexo d
  4. 需要在condig.net

    需要实名认证后才允许使用pages功能,触发机制可以选择手动部署和自动部署

    构建与部署--静态网站--立即部署

  5. 访问上面的地址

    https://722tv0.coding-pages.com/

部署到gitee

  1. 申请gitee账号

    https://gitee.com/

  2. 创建项目

    项目名和用户名,还有范围地址中的最好是相同的,这个可以保证可以通过<用户名>.gitee.io进行访问,否则会多一级目录,我这里就填写lmwings,然后创建

  3. 到项目中,选择服务--Gitee Pages,部署分支选择master即可,部署目录可以不用填,启用以后会有网站地址,我的地址为https://lmwings.gitee.io/blog

  4. 生成ssh-key公钥,这个和上面方法一样

    # Windows默认生成的路径
    $ cd /c/Users/Administrator/.ssh
    
    # 生成公钥文件,后面邮箱是我注册的邮箱地址,输入文件名为 coding即会生成 coding.pud文件
    $ ssh-keygen -t rsa -b 4096 -C 1321559220@qq.com
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): rsa_gitee

    然后把rsa_gitee.pub填写到

    https://gitee.com/profile/sshkeys (我自己使用一般直接设置账号的,不设置仓库的)

    测试一下是否正常

    ssh -T git@gitee.com
  5. 部署更新后,到gitee Pages手动更新一下

    付费版本gitee Pages Pro,可以支持自定义域名,支持推送后自动部署,普通不行

  6. 访问一下

    https://lmwings.gitee.io/

部署到gitlab

  1. 申请gitlab账号

    https://gitlab.com/

  2. 创建项目, 名称规则同github, 即 <用户名>.gitlab.io

  3. 生成ssh-key公钥,方法一样

    # Windows默认生成的路径
    $ cd /c/Users/Administrator/.ssh
    
    $ ssh-keygen -t rsa -C 1321559220@qq.com
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): rsa_gitlab
    

    然后把rsa_gitlab.pub填写到

    https://gitlab.com/profile/keys

    测试一下是否正常

    ssh -T git@gitlab.com
  4. 这个和其他的不一样,

    没有显示的gitlab pages设置界面,主要是gitlabgitlab ci, 如果项目中存在.gitlab-ci.yml的文件,就会自动触发gitlab runner来执行这个脚本,所以和其他发布不一样,这个仓库中需要上传的是本地的hexo源码

  5. .gitlab-ci.yml脚本编写可以参考

    (暂时还未来得及验证。)

    https://hexo.io/zh-cn/docs/gitlab-pages

    https://www.cnblogs.com/zhangnan35/p/10709252.html

一键部署

可以利用Traivs CI等持续集成平台进行部署

参考https://hexo.io/zh-cn/docs/one-command-deployment


文章作者: Wang Kang
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Wang Kang !
评论
 上一篇
同一电脑多个ssh-key管理 同一电脑多个ssh-key管理
Windows上多git账号/多ssh-key管理1. 说明主要是用于多个代码托管平台,常见的有github、coding、gitee等 在设置ssh公钥时候,一般一个平台生成一封文件夹有平台标识的公钥文件, 一般默认路径为.ssh/*.p
2020-02-05
下一篇 
搭建个人的Hexo静态网站 搭建个人的Hexo静态网站
搭建个人Hexo网站1. 环境安装需要依赖node.js环境,下载node.js安装包,安装好以后会自动安装js和npm环境. 安装nodejs 下载node.js安装包,选择对应系统和版本,如果是win7,需要用nodejs 12的版本;
2020-02-04
  目录