@mritd
2015-12-30T09:32:42.000000Z
字数 4718
阅读 2741
Linux CentOS Hexo 博客
操作环境为虚拟机中 CentOS_6.7 , 阿里镜像源
Node.js 点我下载
tar -zxvf node-v4.2.4-linux-x64.tar.gz /usr/local/node
# 编辑 /etc/profile (使用vim)vim /etc/profile# 在底部添加 PATH 变量export PATH=$PATH:/usr/local/node/bin# 最后保存并使其生效即可source /etc/profile
mkdir hexo
# 切换目录cd hexo# 安装Git(已安装可跳过)yum install git-core# 安装 Hexonpm install -g hexo-cli# 初始化 hexohexo init
# 启动测试hexo server# 此时控制台应该打印 如下语句INFO Hexo is running at http://0.0.0.0:4000/. Press Ctrl+C to stop.# 测试访问 http://IP:4000 ,效果如下

Hexo 提供了其他许多扩展插件,比如 git插件、快捷命令插件等
npm install hexo-generator-index --savenpm install hexo-generator-archive --savenpm install hexo-generator-category --savenpm install hexo-generator-tag --savenpm install hexo-server --savenpm install hexo-deployer-git --savenpm install hexo-deployer-heroku --savenpm install hexo-deployer-rsync --savenpm install hexo-deployer-openshift --savenpm install hexo-renderer-marked@0.2 --savenpm install hexo-renderer-stylus@0.2 --savenpm install hexo-generator-feed@1 --savenpm install hexo-generator-sitemap@1 --save
hexo/source/_post 下生成对应.md 文件)
hexo n “文章名称”
hexo/public 目录)
hexo g
hexo s
hexo d
直接上配置文件 (
hexo/_config.yml),里面包括主题、github等参数设置,主题、Github配置请看下面
# Hexo Configuration## Docs: http://hexo.io/docs/configuration.html## Source: https://github.com/hexojs/hexo/# Site 站点相关配置title: 烟雨平生subtitle: 一蓑烟雨任平生,也无风雨也无晴。description: 记录生活点滴,不断学习,每走一步,在这里印下足迹。author: mritdlanguage: zh-CNtimezone:# URL 网站URL## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'url: http://www.mritd.meroot: /permalink: :year/:month/:day/:title/permalink_defaults:# Directory 相关文件夹设置source_dir: sourcepublic_dir: publictag_dir: tagsarchive_dir: archivescategory_dir: categoriescode_dir: downloads/codei18n_dir: :langskip_render:# Writing 文章设置new_post_name: :title-:year-:month-:day.md # 新文章(post)生成为文件名default_layout: posttitlecase: false # Transform title into titlecaseexternal_link: true # Open external links in new tabfilename_case: 0render_drafts: falsepost_asset_folder: falserelative_link: falsefuture: truehighlight:enable: trueline_number: trueauto_detect: truetab_replace:# Category & Tagdefault_category: uncategorizedcategory_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-DDtime_format: HH:mm:ss# Pagination## Set per_page to 0 to disable paginationper_page: 10pagination_dir: page# Extensions## Plugins: http://hexo.io/plugins/## Themes: http://hexo.io/themes/theme: yilia #主题设置stylus:compress: true# Deployment## Docs: http://hexo.io/docs/deployment.htmldeploy: #部署插件设置(目前只自动部署到github)type: gitrepo: git@github.com:mritd/mritd.github.io.gitbranch: mastermessage: '站点更新: {{ now("YYYY-MM-DD HH:mm:ss") }}'

1、 无论什么主题,先 Download 到本地,拿 yilia 为例,由于其托管于github,直接git clone即可
# 任意目录下执行会生成 yilia 文件夹git clone https://github.com/litten/hexo-theme-yilia.git yilia
2、 根据作者教程更改一些参数,主要更改 主题目录 下的 _config.yml文件 (yilia/_config.yml),我的配置样例如下
# Headermenu:主页: /所有文章: /archives随笔: /categories/随笔IT: /categories/IT相册: /tags/相册# SubNavsubnav:github: "https://github.com/mritd/"#weibo: "#"#rss: "#"#zhihu: "#"#douban: "#"mail: "mailto:mritd1234@gmail.com"#facebook: "#"google: "https://plus.google.com/u/0/111440014763883747104"#twitter: "#"#linkedin: "#"rss: /atom.xml# Contentexcerpt_link: morefancybox: truemathjax: true# 是否开启动画效果animate: true# 是否在新窗口打开链接open_in_new: false# Miscellaneousgoogle_analytics: ''favicon: /favicon.ico#你的头像urlavatar: /logo.jpeg#是否开启分享share: trueshare_addthis: false#是否开启多说评论,填写你在多说申请的项目名称 duoshuo: duoshuo-key#若使用disqus,请在博客config文件中填写disqus_shortname,并关闭多说评论duoshuo: 'mritd4hexo'#是否开启云标签tagcloud: true#是否开启友情链接#不开启——#friends: false#开启——friends:HelloDog: http://wsgzao.github.io/咚门: http://www.dearzd.com/DBlog/Coding云: http://www.codingyun.com/伯乐在线: http://blog.jobbole.com/#是否开启“关于我”。#不开启——#aboutme: false#开启——aboutme: 社会三好青年,祖国未来栋梁,世界未来领袖......前面都是吹牛逼的,我就是个逗比......
3、配置完成后将主题目录复制到
hexo/themes目录下
cp -r yilia hexo/themes
4、修改hexo主配置文件为对应的主题
## Themes: http://hexo.io/themes/theme: yilia #主题名称stylus:compress: true
5、重新生成静态文件 访问测试
hexo clean # 清除缓存hexo g # 生成静态文件hexo s # 启动服务器预览

首先注册 Github 账户,这里掠过,然后创建一个新项目,项目名称为 用户名.github.io ,比如我的Github用户名是mritd,则创建的项目名为
mritd.github.io

服务器生成秘钥;如果在
$HOME/.ssh下有 id_rsa、id_rsa.pub 则可忽略创建过程
# 执行以下命令然后一路回车 创建秘钥ssh-keygen# 复制 公钥内容 稍后加入Github 账户的 sshkey中less ~/.ssh/id_rsa.pub
登录 Github后访问 https://github.com/settings/ssh,选择
Add SSH key,取个名字然后把内容粘进去,保存即可。

修改 Hexo 配置文件即可 如下
# Deployment## Docs: http://hexo.io/docs/deployment.htmldeploy: #部署插件设置(目前只自动部署到github)type: gitrepo: git@github.com:mritd/mritd.github.io.git # 你新建的Github项目地址(用户名.github.io)branch: mastermessage: '站点更新: {{ now("YYYY-MM-DD HH:mm:ss") }}' #每次部署后更新信息
# 执行以下命令将自动更新到Githubhexo d