linux下部署hexo搭建利用github空间的个人博客(二)

书接上一回linux下部署hexo搭建利用github空间的个人博客(一),把hexo安装好之后呢,就要开始进行hexo的配置等等了,一路上看似简单,却遇到了无数的坑,跟大家分享一下吧!
不得不说,一开头就遇坑了,明明装好的hexo,上次已经init过的了,也没问题了,隔了几天,一打开命令,吓哭有木有:为什么会变酱紫!!??可以说是hexo命令失效了吧。

gg5d@gg5d-Lenovo-V480:~$ sudo hexo
Usage: hexo <command>

Commands:
  help     Get help on a command.
  init     Create a new Hexo folder.
  version  Display version information.

Global Options:
  --config  Specify config file instead of using _config.yml
  --cwd     Specify the CWD
  --debug   Display all verbose messages in the terminal
  --draft   Display draft posts
  --safe    Disable all plugins and scripts
  --silent  Hide output on console

For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/

一、hexo命令失效解决办法:

1 检查_config.yml中的内容,特别注意:后面需要有一个空格。
2 检查`package.json’中的内容,注意添加hexo信息用来标识这是一个hexo目录:

{
  "hexo": {
    "version": ""
  }
}

3 如果还是有问题,可以更新hexo之后,在新的文件夹中重新进行hexo init。(在初始化之后,以后要使用hexo的所有命令,都是要进入你init的那个文件夹之后才会生效)

// gg5dblog为你要创建的文件夹的名字
sudo hexo init gg5dblog
// 进入该文件夹
cd gg5dblog
//node.js安装所有的依赖包
npm install

咳咳,果不其然,到了npm install又报错了,不急,让我们看看错误是怎样的

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! Linux 4.8.0-58-generic
npm ERR! argv "/home/gg5d/.nvm/versions/node/v7.4.0/bin/node" "/home/gg5d/.nvm/versions/node/v7.4.0/bin/npm" "install"
npm ERR! node v7.4.0
npm ERR! npm  v4.0.5
npm ERR! path /home/gg5d/gg5dblog/node_modules/.staging
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/home/gg5d/gg5dblog/node_modules/.staging'
npm ERR!  { Error: EACCES: permission denied, mkdir '/home/gg5d/gg5dblog/node_modules/.staging'
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/home/gg5d/gg5dblog/node_modules/.staging' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Linux 4.8.0-58-generic
npm ERR! argv "/home/gg5d/.nvm/versions/node/v7.4.0/bin/node" "/home/gg5d/.nvm/versions/node/v7.4.0/bin/npm" "install"
npm ERR! node v7.4.0
npm ERR! npm  v4.0.5
npm ERR! path npm-debug.log.2835091910
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open

npm ERR! Error: EACCES: permission denied, open 'npm-debug.log.2835091910'
npm ERR!  { Error: EACCES: permission denied, open 'npm-debug.log.2835091910'
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'open',
npm ERR!   path: 'npm-debug.log.2835091910' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/gg5d/gg5dblog/npm-debug.log

先忽略上面的WARN,看看ERR信息,勾重点,可以看到

npm ERR! Error: EACCES: permission denied, mkdir '/home/gg5d/gg5dblog/node_modules/.staging'
npm ERR!  { Error: EACCES: permission denied, mkdir '/home/gg5d/gg5dblog/node_modules/.staging'
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/home/gg5d/gg5dblog/node_modules/.staging' 

判断为命令执行的权限问题,加个sudo在前面试试

sudo npm install

可以看到,WARN依然出现,但是不再报ERR,就是执行成功了。

gg5d@gg5d-Lenovo-V480:~/gg5dblog$ sudo npm install
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.1.2

二、配置_config.yml文件

接下来就是最关键的地方,_config.yml文件的配置。
_config.yml文件就在你设置的文件夹下面

第一步,修改网站信息

title: gg5d
subtitle: try my best
description: ML,DL,HIT_CS
author: gg5d
language: zh-CN
timezone: Asia/Shanghai

依次是题目,副标题,网站描述,作者,语言,时区,注意,所有配置都要在:之后加上一个空格

第二步,配置个人域名

url: http://gg5d.com
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:

这里我们只修改url,其他保持原来的

第三步,git部署的配置

deploy:
  type: git
  repo: https://github.com/junjunwudi/junjunwudi.github.io.git
  branch: master

这里采用https的方式,有时候https不行,可以改为ssh推送,就先不讲了可以查找有关的教程。这里一定要注意,中间两个都是你的名字,一定要保持一致,最后不能漏了git,分支一般都是选master

2017-07-21 20-59-23屏幕截图.png

三、md文件的生成和本地服务

初始化成功,接下来试着生成一个.md文件

sudo hexo new first
//Created: ~/gg5dblog/source/_posts/first.md

打开本地服务器看看文件出来的效果

sudo hexo server

当然,我们也可以手动添加Markdown文件在source->_deploy文件夹下。
问题来了,怎么让这些网页在网络上显示呢,就是要部署推送啦

//生成generate
sudo hexo g
//部署deploy
sudo hexo d

咳咳,果然马上又遇到问题了,

ERROR Deployer not found: git

怎么办,缺啥补啥呗

sudo npm install hexo-deployer-git --save

然后就可以继续hexo deploy部署了
又报错,,,,

四、git初始化

INFO  Deploying: git
INFO  Setting up Git deployment...
初始化空的 Git 仓库于 /home/gg5d/gg5dblog/.deploy_git/.git/

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'root@gg5d-Lenovo-V480.(none)')
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: 
*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'root@gg5d-Lenovo-V480.(none)')

    at ChildProcess.<anonymous> (/home/gg5d/gg5dblog/node_modules/hexo-util/lib/spawn.js:37:17)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:821:16)
    at Socket.<anonymous> (internal/child_process.js:319:11)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at Pipe._onclose (net.js:469:12)

可以看到,意思就是git没初始化好,注意这里--global一定不能漏

gg5d@gg5d-Lenovo-V480:~/gg5dblog$ git init
重新初始化现存的 Git 仓库于 /home/gg5d/gg5dblog/.git/
gg5d@gg5d-Lenovo-V480:~/gg5dblog$ git config --global user.name junjunwudi
gg5d@gg5d-Lenovo-V480:~/gg5dblog$ git config --global user.email 986320586@qq.com
gg5d@gg5d-Lenovo-V480:~/gg5dblog$ git add *
下列路径根据您的一个 .gitignore 文件而被忽略:
node_modules
public
使用 -f 参数如果您确实要添加它们。
gg5d@gg5d-Lenovo-V480:~/gg5dblog$ git add * -f

五、遇到的一些坑。

接下来,继续deploy,又报错。。

fatal: unable to access 'https://github.com//junjunwudi/junjunwudi.github.io.git/': The requested URL returned error: 400
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: fatal: unable to access 'https://github.com//junjunwudi/junjunwudi.github.io.git/': The requested URL returned error: 400

    at ChildProcess.<anonymous> (/home/gg5d/gg5dblog/node_modules/hexo-util/lib/spawn.js:37:17)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:821:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

尝试改为ssh方式,继续报错

gg5d@gg5d-Lenovo-V480:~/gg5dblog$ sudo hexo deploy
INFO  Deploying: git
INFO  Clearing .deploy_git folder...
INFO  Copying files from public folder...
INFO  Copying files from extend dirs...
位于分支 master
无文件要提交,干净的工作区
The authenticity of host 'github.com (192.30.255.113)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.255.113' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: Warning: Permanently added 'github.com,192.30.255.113' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

    at ChildProcess.<anonymous> (/home/gg5d/gg5dblog/node_modules/hexo-util/lib/spawn.js:37:17)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:821:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

试着看看ssh有没有配置好

gg5d@gg5d-Lenovo-V480:~/gg5dblog$ ssh git@github.com
Warning: Permanently added the RSA host key for IP address '192.30.255.112' to the list of known hosts.
PTY allocation request failed on channel 0
Hi junjunwudi/junjunwudi.github.io! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

ssh没问题,改回https又试了一次,还是出错,我要疯了。
不慌,继续分析,感觉还是得回到_config.yml文件,检查发现,_config.yml文件第一步修改网站信息的时候,在思考副标题写些什么,结果后面漏写了subtitle的内容,大写的囧,补上之后,试一下,成功了。我的天。

六、遇到github同名仓库博客主页能显示网页,个人域名报404怎么办?

gg5d@gg5d-Lenovo-V480:~/gg5dblog$ sudo hexo d
INFO  Deploying: git
INFO  Clearing .deploy_git folder...
INFO  Copying files from public folder...
INFO  Copying files from extend dirs...
位于分支 master
无文件要提交,干净的工作区
Username for 'https://github.com': junjunwudi
Password for 'https://junjunwudi@github.com': 
To https://github.com/junjunwudi/junjunwudi.github.io.git
 + 36bbf5a...cd3fbf2 HEAD -> master (forced update)
分支 master 设置为跟踪来自 https://github.com/junjunwudi/junjunwudi.github.io.git 的远程分支 master。
INFO  Deploy done: git

打开github,东西都推送好了,

2017-07-21 21-19-04屏幕截图.png

点击github博客主页,成功,没毛病老铁。


结果,打开自己的域名时候,我又被打击了一发。

七、浏览器缓存导致个人域名显示404,换个浏览器试试呗~

2017-07-21 21-21-52屏幕截图.png

这个404伤透了我的心,查了很多方法都没效果,分析问题,域名解析没出错,文件已经成功推送并且在自己的仓库网址可以看到,那什么问题呢?后面在知乎看到有个老哥说可能跟浏览器缓存有关,那就换个浏览器试试呗,将firefox换成chromium,结果就好了,我的苍天啊!终于折腾完了,呜呜呜。

2017-07-21 21-24-51屏幕截图.png

看到终于弄成了,心里还是美滋滋滴~~
补充:最后版本的config.yml文件(修改了主题为cyanstyle)

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: gg5d
subtitle: try my best
description: ML,DL,HIT_CS
author: gg5d
language: zh-CN
timezone: Asia/Shanghai

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://gg5d.com
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: true
  line_number: true
  auto_detect: false
  tab_replace:

# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
  path: ''
  per_page: 10
  order_by: -date

# Category & Tag
default_category: uncategorized
category_map:
tag_map:
# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: cyanstyle

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: https://github.com/junjunwudi/junjunwudi.github.io.git
  branch: master

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,242评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,769评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,484评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,133评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,007评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,080评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,496评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,190评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,464评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,549评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,330评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,205评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,567评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,889评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,160评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,475评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,650评论 2 335

推荐阅读更多精彩内容