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

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

gg5d@gg5d-Lenovo-V480:~$ sudo hexo
Usage: hexo 

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 [email protected]: 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: [email protected]

二、配置_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

linux下部署hexo搭建利用github空间的个人博客(二)_第1张图片
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 "[email protected]"
  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 "[email protected]"
  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. (/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. (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 [email protected]
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. (/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. (/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 [email protected]
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://[email protected]': 
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,东西都推送好了,

linux下部署hexo搭建利用github空间的个人博客(二)_第2张图片
2017-07-21 21-19-04屏幕截图.png

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

linux下部署hexo搭建利用github空间的个人博客(二)_第3张图片

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

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

linux下部署hexo搭建利用github空间的个人博客(二)_第4张图片
2017-07-21 21-21-52屏幕截图.png

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

linux下部署hexo搭建利用github空间的个人博客(二)_第5张图片
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

你可能感兴趣的:(linux下部署hexo搭建利用github空间的个人博客(二))