首先你需要一臺(tái)Lunix主機(jī)——一臺(tái)連上外網(wǎng)的Lunix的電腦。
我在CONOHA買的VPS,相同配置下,性價(jià)比比DO和VULTR好那么一丟丟。
買到主機(jī)后的配置我就pass不寫(xiě)了纺腊,直接來(lái)說(shuō)在終端狀態(tài)下,然后搭建Hexo+Gitlab博客
安裝請(qǐng)時(shí)刻注意自己在什么目錄下茎芭!我是在root用戶下完成的揖膜!因?yàn)閚ode安裝需要高級(jí)權(quán)限。
1.安裝Node.js
- 下載
找到最新的下載地址梅桩,用wget命令下載到本地
wget https://nodejs.org/dist/v4.4.4/node-v4.4.4-linux-x64.tar.xz
解壓命令壹粟,是xz文件。SO
xz -d node-v4.4.4-linux-x64.tar.xz
tar -xvf node-v4.4.4-linux-x64.tar
或者
tar -xvJf node-v4.4.4-linux-x64.tar.xz
文件就被解壓到當(dāng)前文件夾下了
mv node-v4.4.4-linux-x64 node-v4.4.4
mv node-v4.4.4 /usr/local/node
- 配置環(huán)境變量
# 編輯 /etc/profile (使用vim)
vim /etc/profile
# 在底部添加 PATH 變量
export PATH=$PATH:/usr/local/node/bin
# 保存退出宿百,先按exit鍵趁仙,再按shift+:
wq
# 最后保存并使其生效即可
source /etc/profile
2.安裝Hexo
這里我是在 /User/Zing目錄下操作的!Zing是我的用戶名垦页!
# 創(chuàng)建目錄
mkdir hexo
# 切換目錄
cd hexo
# 安裝Git(已安裝可跳過(guò))
yum install git-core
# 安裝 Hexo
npm install -g hexo-cli
# 初始化 Hexo
hexo init
- 安裝插件
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
- 修改Hexo配置文件
提示:key對(duì)應(yīng)沒(méi)有值的時(shí)候雀费,冒號(hào)后面一定要有空格!否則會(huì)報(bào)錯(cuò)
例如: timezone:會(huì)報(bào)錯(cuò)痊焊,timezone:?則不會(huì)盏袄。
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site 站點(diǎn)信息設(shè)置
title: Zing's Blog #站名
subtitle: 不忘初心 方得始終 #副標(biāo)題
description: #站描述
author: Zing #作者
language: zh-CN #語(yǔ)言
timezone:
# URL 鏈接設(shè)置
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://blog.prozin.xyz
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: true
tab_replace:
# 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 分頁(yè)
## Set per_page to 0 to disable pagination
per_page: 20
pagination_dir: page
# Extensions 擴(kuò)展
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape
# Deployment 這里設(shè)置了Git獲
#這里一定要注意不要寫(xiě)錯(cuò)了忿峻,否則部署到Github上會(huì)出問(wèn)題
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: git@github.com:mocorochio/micorochio.github.io.git
branch: master
message: '站點(diǎn)更新:{{now("YYYY-MM-DD HH/mm/ss")}}'
3.部署到GitHub
- 1.配置本機(jī)全局git環(huán)境(如果已經(jīng)配置過(guò)請(qǐng)忽略)
首先請(qǐng)使用郵箱注冊(cè)github賬號(hào),否則會(huì)影響下面操作辕羽,記住你注冊(cè)的郵箱逛尚。
另外,請(qǐng)?jiān)赩PS上設(shè)置你的git
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
- 2.生成SSH秘鑰
先確定你的VPS 有沒(méi)有生成過(guò)ssh的key刁愿,
驗(yàn)證
less ~/.ssh/id_rsa.pub
如果報(bào)錯(cuò)
執(zhí)行下面代碼
# -C后面跟住你在github的用戶名郵箱绰寞,這樣公鑰才會(huì)被github認(rèn)可
ssh-keygen -t rsa -C example@126.com
# 查看 公鑰內(nèi)容 稍后加入Github 賬戶的 sshkey中
less ~/.ssh/id_rsa.pub
你會(huì)看到一堆代碼
如果沒(méi)有報(bào)錯(cuò)
# -C后面跟住你在github的用戶名郵箱,這樣公鑰才會(huì)被github認(rèn)可
ssh-keygen -t rsa -C example@126.com
# 回車后酌毡,輸入一個(gè)文件夾名字克握,存儲(chǔ)新的SSH 秘鑰
.ssh/github
# 查看 公鑰內(nèi)容 稍后加入Github 賬戶的 sshkey中
less ~/.ssh/id_rsa.pub
當(dāng)然,也有可能遇到這種情況枷踏,你可以選擇覆蓋(確認(rèn)沒(méi)有人使用當(dāng)前的SSH秘鑰),或者不覆蓋 (如圖)
- 3.創(chuàng)建博客工程
博客工程創(chuàng)建要注意P袢洹!旷坦!,看看 漠然 怎么說(shuō)的
創(chuàng)建一個(gè)新項(xiàng)目掏熬,項(xiàng)目名稱為 用戶名.github.io ,比如我的Github用戶名是mritd秒梅,則創(chuàng)建的項(xiàng)目名為 mritd.github.io
用戶名是你的github用戶名哦旗芬!千萬(wàn)別弄錯(cuò)了,不然訪問(wèn)不到的捆蜀!
所以我的是git@github.com:mocorochio/micorochio.github.io.git
- 4.將ssh秘鑰添加到github中
生成后疮丛,需要將秘鑰放到github上去,登錄你的github賬號(hào)
進(jìn)入秘鑰設(shè)置面板:https://github.com/settings/ssh
在執(zhí)行less ~/.ssh/id_rsa.pub
你會(huì)看到一堆長(zhǎng)密碼
這一段密碼全部復(fù)制到github上
- 5.配置Hexo,編譯與部署
還記得我們?cè)赺config.yml里最后一段的配置嗎锰茉?
# Deployment 這里設(shè)置了Git獲
#這里一定要注意不要寫(xiě)錯(cuò)了呢蔫,否則部署到Github上會(huì)出問(wèn)題
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: git@github.com:mocorochio/micorochio.github.io.git
branch: master
message: '站點(diǎn)更新:{{now("YYYY-MM-DD HH/mm/ss")}}'
這里,repo就是你創(chuàng)建的博客工程
最后一步飒筑,編譯片吊,上傳靜態(tài)代碼
# 編譯
hexo generate
# 在主機(jī)的hexo目錄下 執(zhí)行以下命令將自動(dòng)更新到Github
hexo d
4.修改主題和配置配置文件
- 4.1安裝主題NexT
ps:我們現(xiàn)在在目錄hexo下
git clone https://github.com/iissnan/hexo-theme-next themes/next
并在目錄hexo下的_config.yml中
# 找到 theme: 修改后面的參數(shù),默認(rèn)是 landscape
theme: next
4.2配置主題
源碼拷貝出來(lái)太多了协屡,所以貼出next的使用說(shuō)明供大家參考4.3找主題
https://hexo.io/themes/
訪問(wèn):
看俏脊,現(xiàn)在通過(guò) 昵稱.github.io
可以訪問(wèn)靜博客了
http://micorochio.github.io
最后感謝漠然-mrtid
本文參考了以下站點(diǎn)文章:
Github 搭建 Hexo 靜態(tài)博客
Hexo 主題 next