主機(jī)要求:必須是centos環(huán)境版本可以不一樣,假如你用的是其他版本的linux系統(tǒng)悲酷,只不過是命令不太一樣套菜。
Tips:這里提前說下,對(duì)于Ubuntu來說设易,以下類似操作必須要用戶家目錄中逗柴,這樣你才能夠給權(quán)限,自其它目錄中顿肺,還沒有辦法給hexo或者git讀寫權(quán)限的戏溺。
這里首先提供三個(gè)鏈接地址,當(dāng)你創(chuàng)建完成博客后挟冠,對(duì)一個(gè)很low的界面會(huì)抱怨的于购,作為一個(gè)視覺黨,這簡直是不能忍受的知染,所以這里推薦一個(gè)有著超級(jí)詳細(xì)的教程的主題肋僧,里面有詳細(xì)的設(shè)置。后面的設(shè)置都是和主題有關(guān)的,小編在這里只是寫出來怎么搭建博客嫌吠,和怎么上傳到github上止潘。
hexo的官方地址: https://hexo.io/
github的官方地址:https://github.com/
github-theme-next主題界面https://github.com/iissnan/hexo-theme-next
mkdir /app/blog
# 創(chuàng)建一個(gè)單獨(dú)屬于blog的文件夾,名字自己隨便
cd /app/blog
wget https://nodejs.org/dist/v6.11.1/node-v6.11.1-linux-x64.tar.xz
# 從網(wǎng)上下載最新班的node.js軟件辫诅,這個(gè)是必須的環(huán)境
tar Jxvf node-v6.11.1-linux-x64.tar.xz
# 解壓`node-v6.11.1-linux-x64.tar.xz`文件
mv node-v6.11.1-linux-x64 node
# 修改一下名字名字太長寫的麻煩
修改全局變量凭戴,加入全局變量文件中
vim /etc/profile
export PATH=$PATH:/app/blog/node/bin
# 這個(gè)隨便添加到哪里都行,一般我都加到最后
source /etc/profile
# 重新加載環(huán)境配置文件
# 創(chuàng)建目錄
mkdir hexo
# 切換目錄
cd hexo
安裝Git(已安裝可跳過)
yum install git-core
安裝 Hexo
npm install -g hexo-cli
初始化 Hexo
hexo init 初始化安裝
假如錯(cuò)誤的話炕矮,這里提供解決方案
npm install
hexo init(不過這里會(huì)提示你文件夾不是空的么夫,所以你需要把原來的文件夾刪除,重新創(chuàng)建)
啟動(dòng)hexo
[root@VinnyWang testgithub.io]# hexo server
INFO Start processing
INFO Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.
這里我們不關(guān)閉終端肤视,我們直接點(diǎn)擊打開鏈接档痪,一個(gè)你將來的博客界面就會(huì)出現(xiàn)了,假如失敗的話邢滑,重頭來腐螟,最簡單的辦法,要不然就排錯(cuò)困后,錯(cuò)誤很多乐纸,這里就不一一寫出來了。
到了這里摇予,我們就是把環(huán)境搭建成功了汽绢,到時(shí)候吧本地的升值同步到github上就好了。但是這里我們先不需要著急趾盐,我們剛才生成的只不過是hexo為我們提供的模板網(wǎng)頁庶喜,里邊還是會(huì)有很多信息需要修改的,下面我們進(jìn)入配置文件進(jìn)行修改救鲤,最主要我們修改的地方有兩個(gè)地方久窟,一個(gè)是開頭一個(gè)是結(jié)尾。
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site # 站點(diǎn)信息
title: Hexo # 標(biāo)題
subtitle: # 副標(biāo)題
description: # 站點(diǎn)描述本缠,這個(gè)地方會(huì)被搜索引擎收錄
author: John Doe # 作者斥扛,可以把John Doe改成自己
language: # 語言類型,看你選擇什么主題丹锹,里面會(huì)有設(shè)置的稀颁,一般情況下寫 zh-CN
timezone: # 時(shí)區(qū) 有的主題文件會(huì)有需要的
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com # 網(wǎng)址
root: / # 根目錄,這個(gè)地方在你準(zhǔn)備同步到網(wǎng)上時(shí)候,修改成你的庫名字楣黍,比如我的是vinnywang.github.io就寫這個(gè)名字
permalink: :year/:month/:day/:title/ # 文章的鏈接格式
permalink_defaults: # 默認(rèn)鏈接
# Directory
source_dir: source # 源文件生成目錄
public_dir: public # 生成網(wǎng)頁文件目錄
tag_dir: tags # 標(biāo)簽?zāi)夸?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 # 新標(biāo)題
default_layout: post # 默認(rèn)的模板post匾灶、page、photo租漂、draft(文章阶女、頁面颊糜、照片、草稿)
titlecase: false # Transform title into titlecase # 標(biāo)題是否轉(zhuǎn)換為大寫
external_link: true # Open external links in new tab # 新的tab打開頁面
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight: # 語法高亮
enable: true # 是否啟用
line_number: true # 顯示行號(hào)
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 # 分類標(biāo)簽
default_category: uncategorized # 默認(rèn)
category_map:
tag_map:
# Archives
2: 開啟分頁
1: 禁用分頁
0: 全部禁用
archive: 2
category: 2
tag: 2
# Date / Time format # 日期時(shí)間格式
## 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 # 默認(rèn)設(shè)置的格式
time_format: HH:mm:ss
# Pagination # 分頁
## Set per_page to 0 to disable pagination
per_page: 10 # 每頁為10篇文章
pagination_dir: page
# Extensions # 擴(kuò)展插件
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape # 主題 裝機(jī)完成之后秃踩,默認(rèn)為landscape
# Deployment # 開發(fā)后面部署到github上時(shí)會(huì)使用到衬鱼,不要填錯(cuò)了
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo:git@github.com:mocorochio/micorochio.github.io.git # 這個(gè)是填你自己生成的庫的鏈接地址
branch: master
message: '站點(diǎn)更新:{{now("YYYY-MM-DD HH/mm/ss")}
上面的repo
可能會(huì)有很多人不知道怎么填寫,這里給個(gè)地址憔杨,是紅色箭頭所指的網(wǎng)址鸟赫。
![image](https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1501594422&di=8708ec1bcaf0ae34bae44185b351c635&imgtype=jpg&src=http://b.hiphotos.baidu.com/image/pic/item/71cf3bc79f3df8dcf09c2d1bc711728b46102892.jpg)
[root@VinnyWang testgithub.io]# git config --global user.email "20843205@qq.com"
輸入你的email賬號(hào),和你注冊(cè)時(shí)候的email相同消别,不要填錯(cuò)了
[root@VinnyWang testgithub.io]# git config --global user.name "vinnywan"
這里填上你的用戶名抛蚤,和你注冊(cè)時(shí)候的一樣哦
[root@VinnyWang testgithub.io]# less ~/.ssh/id_rsa.pub
/root/.ssh/id_rsa.pub: No such file or directory
這個(gè)地方是檢查你有沒有key文件,有的話略過下邊的操作寻狂。
[root@VinnyWang testgithub.io]# ssh-keygen -t rsa -C 20843205@qq.com
這個(gè)操作是生成key文件霉颠,假如你們有的話,需要生成荆虱,一路回車就好了。
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
64:a7:2d:64:97:a9:27:51:9d:22:c1:07:a8:74:8d:ac 20843205@qq.com
The key's randomart image is:
+--[ RSA 2048]----+
| . =oo.. . |
| . = +.ooo |
| . + *o=. |
| E = B |
| S o |
| + |
| |
| |
| |
+-----------------+
vim /root/.ssh/id_rsa.pub
然后把這個(gè)文件上的全部復(fù)制出來,等下有用朽们。
現(xiàn)在我們本地的環(huán)境已經(jīng)搭建完成了怀读,但是我們還沒有同步到網(wǎng)上,所以這個(gè)地方我們需要?jiǎng)?chuàng)建一個(gè)github賬號(hào)骑脱,最上面提供的有g(shù)ithub的官方網(wǎng)址菜枷,點(diǎn)擊進(jìn)去就好了。
創(chuàng)建用戶賬戶就不用我教了吧叁丧,按照提示一步一步做下去就好了啤誊。但是這里先提前說下,不要亂填拥娄,用戶名不要起的太奇葩蚊锹,后面還要用到。這里只是給提供一些創(chuàng)建賬號(hào)之后的步驟稚瘾。但你登錄github賬號(hào)之后是這個(gè)樣子的牡昆。
![登陸之后界面](https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1501593797&di=3a33b2424914dcfc81f73c6b1d720eda&imgtype=jpg&src=http://f.hiphotos.baidu.com/image/pic/item/6f061d950a7b0208fe34996b68d9f2d3562cc8bf.jpg)
我們點(diǎn)擊 start a project
之后會(huì)彈出這個(gè)界面
![創(chuàng)建庫](https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1501593865&di=3b53f047df9b93819562069aefaeddc9&imgtype=jpg&src=http://c.hiphotos.baidu.com/image/pic/item/d009b3de9c82d158c62ff83b8a0a19d8bd3e428e.jpg)
這個(gè)上面我用紅色箭頭指出來的千萬不要亂寫,格式是:用戶名.github.io
寫完之后摊欠,直接點(diǎn)擊最下面的 create repository
創(chuàng)建完成庫了丢烘,我們需要吧本地的文件同步到github上,但是同步的話些椒,怎么認(rèn)證呢播瞳?這個(gè)時(shí)候就需要用到,我們之前生成的key文件了免糕。
![image](https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1501594162&di=7486dd1f9351c566a2f4fbdfd3a3eda6&imgtype=jpg&src=http://g.hiphotos.baidu.com/image/pic/item/58ee3d6d55fbb2fbd570fb98454a20a44723dce5.jpg)
按照順序點(diǎn)擊赢乓,反正也點(diǎn)不錯(cuò)忧侧。之后還有一個(gè)界面。
![image](https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1501594220&di=2c1002607b968f26c244dfdb9137bdf8&imgtype=jpg&src=http://a.hiphotos.baidu.com/image/pic/item/f11f3a292df5e0fe61882a8b566034a85fdf72ac.jpg)
按照順序填寫骏全,記得一定要選擇sshkey不要用另外一個(gè)苍柏。把我們上面生成的key里面的內(nèi)容復(fù)制到中間的空白處,隨便給個(gè)名字就好了姜贡。
好了上面的我們做完了试吁,現(xiàn)在就需要將本地和網(wǎng)絡(luò)上同步起來
git init
git add . # 將本地文件添加到緩沖區(qū)中
git commit -m "提交文件" # 給想要提交的動(dòng)作一個(gè)名字 引號(hào)內(nèi)部內(nèi)容隨便
git remote add origin https://github.com/vinnywan.github.io
指明你遠(yuǎn)程的庫是什么
git push -u origin master
將緩沖區(qū)添加的文件同步到庫中,速度看網(wǎng)速了楼咳。
這個(gè)時(shí)候可能會(huì)出現(xiàn)一些問題熄捍,所以這里提供了兩個(gè)解決的辦法
1.使用強(qiáng)制push的方法:
git push -u origin master -f
這樣會(huì)使遠(yuǎn)程修改丟失,一般是不可取的母怜,尤其是多人協(xié)作開發(fā)的時(shí)候余耽。
2.push前先將遠(yuǎn)程repository修改pull下來
git pull origin master
git push -u origin maste
這里給些常用的命令:
git add *#跟蹤新文件
git rm -f * #強(qiáng)制刪除所有文件
git commit#提交更新
git commit -m "注釋文本" #添加注釋
git commit -a #跳過使用暫存區(qū)域,把所有已經(jīng)跟蹤過的文件暫存起來一并提交
git commit --amend #修改最后一次提交
git push origin "resposbilty"
hexo g # 部署
hexo d # 提交