最近在搭建本身的我的網站,準備在上面內置一個博客模塊,把以前或者之後雜七雜八的總結都放裏邊。html
大體查了一下在WordPress和Hexo間選用了Hexo,體量較小一點。node
先貼上Hexo的官方文檔:Hexo安裝文檔linux
首先在使用Hexo以前須要在服務器上安裝git
咱們須要首先在系統中安裝git,hexo主題基本都託管在github上,使用git版本管理工具能夠很方便地下載更換主題。此外最後咱們也能夠將博客託管在github並使用Github Pages服務,實現遠程訪問。github
關於git的安裝咱們能夠直接使用命令:shell
sudo apt-get install git
安裝後使用 git --version 查看是否成功。npm
接下來須要對咱們的git進行配置。vim
git config --global user.name "Your Name" git config --global user.email "youremail@domain.com"
關於SSH Keys的添加咱們放在後面來講。瀏覽器
對於node的安裝咱們最好使用node的版本管理工具nvm,可是經過官方文檔裏的鏈接下載時出現了錯誤,後來用了git clone的方法安裝成功:安全
git clone http://github.com/creationix/nvm.git .nvm
安裝完成後輸入
nvm -v
能夠在窗口中打印出
Node Version Manager Note: <version> refers to any version-like string nvm understands. This includes: - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1) - default (built-in) aliases: node, stable, unstable, iojs, system - custom aliases you define with `nvm alias foo` Any options that produce colorized output should respect the `--no-colors` option. Usage: nvm --help Show this message nvm --version Print out the latest released version of nvm nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number> --lts When installing, only select from LTS (long-term support) versions --lts=<LTS name> When installing, only select from versions for a specific LTS line nvm uninstall <version> Uninstall a version nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available. nvm uninstall --lts=<LTS name> Uninstall using automatic alias for provided LTS line, if available. nvm use [--silent] <version> Modify PATH to use <version>. Uses .nvmrc if available --lts Uses automatic LTS (long-term support) alias `lts/*`, if available. --lts=<LTS name> Uses automatic alias for provided LTS line, if available. nvm exec [--silent] <version> [<command>] Run <command> on <version>. Uses .nvmrc if available --lts Uses automatic LTS (long-term support) alias `lts/*`, if available. --lts=<LTS name> Uses automatic alias for provided LTS line, if available. nvm run [--silent] <version> [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available --lts Uses automatic LTS (long-term support) alias `lts/*`, if available. --lts=<LTS name> Uses automatic alias for provided LTS line, if available. nvm current Display currently activated version nvm ls List installed versions nvm ls <version> List versions matching a given <version> nvm ls-remote List remote versions available for install --lts When listing, only show LTS (long-term support) versions nvm ls-remote <version> List remote versions available for install, matching a given <version> --lts When listing, only show LTS (long-term support) versions --lts=<LTS name> When listing, only show versions for a specific LTS line nvm version <version> Resolve the given description to a single local version nvm version-remote <version> Resolve the given description to a single remote version --lts When listing, only select from LTS (long-term support) versions --lts=<LTS name> When listing, only select from versions for a specific LTS line nvm deactivate Undo effects of `nvm` on current shell nvm alias [<pattern>] Show all aliases beginning with <pattern> nvm alias <name> <version> Set an alias named <name> pointing to <version> nvm unalias <name> Deletes the alias named <name> nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version nvm unload Unload `nvm` from shell nvm which [<version>] Display path to installed node version. Uses .nvmrc if available nvm cache dir Display path to the cache directory for nvm nvm cache clear Empty cache directory for nvm Example: nvm install v0.10.32 Install a specific version number nvm use 0.10 Use the latest available 0.10.x release nvm run 0.10.32 app.js Run app.js using node v0.10.32 nvm exec 0.10.32 node app.js Run `node app.js` with the PATH pointing to node v0.10.32 nvm alias default 0.10.32 Set default node version on a shell Note: to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)
表示安裝成功
接下來咱們就可使用npm直接安裝node:
nvm install stable
nvm會自動下載最新的穩定版node,完成後驗證node和附帶安裝的npm的版本號:
$ node -v v7.6.0$ npm -v 4.1.2
證實已經安裝成功。
可是在接下來使用npm安裝hexo時遇到了問題:
npm install -g hexo-cli
試了幾回一直提示node npm未得到許可:
sh: 1: node: Permission denied > hexo-util@0.6.0 postinstall /root/.nvm/versions/node/v7.6.0/lib/node_modules/hexo-cli/node_modules/hexo-util > npm run build:highlight sh: 1: npm: Permission denied /root/.nvm/versions/node/v7.6.0/lib └── (empty) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/hexo-cli/node_modules/chokidar/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: dtrace-provider@0.8.0 (node_modules/hexo-cli/node_modules/dtrace-provider): npm WARN optional SKIPPING OPTIONAL DEPENDENCY: dtrace-provider@0.8.0 install: `node scripts/install.js` npm WARN optional SKIPPING OPTIONAL DEPENDENCY: spawn ENOENT npm ERR! Linux 3.13.0-86-generic npm ERR! argv "/root/.nvm/versions/node/v7.6.0/bin/node" "/root/.nvm/versions/node/v7.6.0/bin/npm" "install" "-g" "hexo-cli" npm ERR! node v7.6.0 npm ERR! npm v4.1.2 npm ERR! file sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn npm ERR! hexo-util@0.6.0 postinstall: `npm run build:highlight` npm ERR! spawn ENOENT npm ERR! npm ERR! Failed at the hexo-util@0.6.0 postinstall script 'npm run build:highlight'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the hexo-util package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! npm run build:highlight npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs hexo-util npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls hexo-util npm ERR! There is likely additional logging output above. npm ERR! Please include the following file with any support request: npm ERR! /root/software/node/npm-debug.log
在網上查瞭解決方案說權限問題的提示用 sudo npm install 試試,可是也不行,本身原本也是用root帳號操做的,最後在一篇博文裏找到了解決方法,博文連接
npm config set user 0 npm config set unsafe-perm true
查看安裝結果:
root@iZ28zkldm3zZ:~/software/node# hexo -v hexo-cli: 1.0.2 os: Linux 3.13.0-86-generic linux x64 http_parser: 2.7.0 node: 7.6.0 v8: 5.5.372.40 uv: 1.11.0 zlib: 1.2.11 ares: 1.10.1-DEV modules: 51 openssl: 1.0.2k icu: 58.2 unicode: 9.0 cldr: 30.0.3 tz: 2016j
接下來能夠進行一些初始化操做
安裝 Hexo 完成後,請執行下列命令,Hexo 將會在指定文件夾中新建所須要的文件。
(<folder>替換爲須要在裏面新建文件的文件夾路徑)
hexo init <folder> cd <folder> npm install
新建完成後,指定文件夾的目錄以下:
新建完成後使用命令啓動本地測試
hexo s
由於是阿里雲的雲服務器,因此在瀏覽器中輸入 http://服務器IP:4000/ 可進入Hello World 頁面
預覽完成後可按 Ctrl+C 退出,本身有遇到過預覽過程當中 Putty 意外退出的狀況,這時候能夠查看佔用4000端口的進程,記下 PID 以後殺掉進程就能夠。
hexo默認的是內置的 landscape 主題,咱們能夠在官方主題列表中找到想引用的主題樣式
我嘗試過 Next:https://github.com/iissnan/hexo-theme-next 和 Yilia:https://github.com/litten/hexo-theme-yilia ,最後選擇了yilia,github裏有預覽博客地址,能夠先看一下效果。
選擇好須要的主題後(接下來都用yilia爲例),咱們複製好主題的地址
隨後轉到hexo目錄下執行clone命令:
git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia
後面的字段是主題的存放地址。等待克隆完成,再打開 hexo/_config.yml 找到以下字段:
# Extensions ## Plugins: https://hexo.io/plugins/ ## Themes: https://hexo.io/themes/ theme: yilia exclude_generator:
將theme修改成咱們剛剛下載的主題名稱,保存退出,使用 hexo s 命令預覽效果。
修改成咱們須要的主題以後,能夠對主題的默認配置進行修改。
cd themes/yilia
轉到主題資源文件目錄,這個就是咱們下載的主題資源包。打開_config.yml,在裏面能夠對主題進行個性化配置
# Header menu: 主頁: / 隨筆: /tags/隨筆/ # SubNav subnav: github: "#" weibo: "#" rss: "#" zhihu: "#" #qq: "#" #weixin: "#" #jianshu: "#" #douban: "#" #mail: "mailto:litten225@qq.com" #facebook: "#" #google: "#" #twitter: "#" #linkedin: "#" rss: /atom.xml # 是否須要修改 root 路徑 # 若是您的網站存放在子目錄中,例如 http://yoursite.com/blog, # 請將您的 url 設爲 http://yoursite.com/blog 並把 root 設爲 /blog/。 root: # Content # 文章太長,截斷按鈕文字 excerpt_link: more # 文章卡片右下角常駐連接,不須要請設置爲false show_all_link: '展開全文' # 數學公式 mathjax: false # 是否在新窗口打開連接 open_in_new: false # 打賞 # 請在須要打賞的文章的md文件頭部,設置屬性reward: true # 打賞基礎設定:0-關閉打賞; 1-文章對應的md文件裏有reward:true屬性,纔有打賞; 2-全部文章均有打賞 reward_type: 2 # 打賞wording reward_wording: '謝謝你請我吃糖果' # 支付寶二維碼圖片地址,跟你設置頭像的方式同樣。好比:/assets/img/alipay.jpg alipay: # 微信二維碼圖片地址 weixin: # Miscellaneous baidu_analytics: '' google_analytics: '' favicon: /favicon.png #你的頭像url avatar: #是否開啓分享 share_jia: true #是否開啓多說評論,填寫你在多說申請的項目名稱 duoshuo: duoshuo-key #若使用disqus,請在博客config文件中填寫disqus_shortname,並關閉多說評論 duoshuo: false # 樣式定製 - 通常不須要修改,除非有很強的定製慾望… style: # 頭像上面的背景顏色 header: '#4d4d4d' # 右滑板塊背景 slider: 'linear-gradient(200deg,#a0cfe4,#e8c37e)' # slider的設置 slider: # 是否默認展開tags板塊 showTags: false # 智能菜單 # 如不須要,將該對應項置爲false # 好比 #smart_menu: # friends: false smart_menu: innerArchive: '全部文章' friends: '友鏈' aboutme: '關於我' friends: 友情連接1: http://localhost:4000/ 友情連接2: http://localhost:4000/ 友情連接3: http://localhost:4000/ 友情連接4: http://localhost:4000/ 友情連接5: http://localhost:4000/ 友情連接6: http://localhost:4000/ aboutme: 很慚愧<br><br>只作了一點微小的工做<br>謝謝你們
做者對配置項基本都作了註釋,也很好理解,咱們修改對應的條目就能夠。隨後保存看看預覽效果。
Github Pages服務能夠給咱們提供一個靜態網頁的託管,以便遠程瀏覽咱們的博客內容。
首先咱們須要在本機生成一個公鑰以便跟github創建安全鏈接,使用命令:
$ ssh-keygen -t rsa -C "youremail@domain.com"
這裏的郵箱就是咱們安裝git時配置的郵箱,隨後複製公鑰內容:
vim ~/.ssh/id_rsa.pub
全選後按 P 鍵複製,登錄github,進入Settings->SSH and GPG keys->New SSH key->粘貼
隨後進入系統測試鏈接是否成功:
ssh -T git@github.com
根據提示輸入yes,若是成功創建鏈接就能夠進行接下來的操做了。
接下來咱們使用咱們須要在github上建立一個倉庫repository,注意倉庫名稱必須爲 【page名稱】.github.io ,後面的.github.io必須保留
新建好咱們的倉庫以後就能夠從本地用git將資源推送到github上。
由於博客是做爲我個站的一部分,因此區分了 主頁和博客主頁 ,不須要能夠刪除便可。
以後進入阿里雲申請一個域名,設置域名解析將映射IP填寫爲咱們建立的Github Pages的IP便可(這個IP咱們能夠經過 ping 命令得到),以後咱們就能夠經過咱們的域名訪問博客啦~
歡迎你們光臨個人博客哦^_^