想來想去仍是想試試把個人博客轉成Jekyll, 一方面爲了git管理, 另外一方面實在是感受請求過多速度太慢, 可改造性太差. 通過遷移後, 默認主題, 速度槓槓的, 顯示時間不到
500ms
哦~
本文在CentOS7環境下操做.
目前最新穩定版本是2.5.0
, CentOS自帶源的版本比較老, 咱們須要第三方源rbenv
來安裝最新穩定版, 安裝方法以下:
安裝rbenv
和Ruby
依賴的組件php
# yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel
安裝rbenv
和rub-build
(務必在非root用戶的home下面操做)html
# cd ~ # git clone git://github.com/sstephenson/rbenv.git .rbenv # echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile # echo 'eval "$(rbenv init -)"' >> ~/.bash_profile # git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build # echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile # source ~/.bash_profile
查看當前可安裝的Ruby版本node
# rbenv install -l
安裝目前最新穩定版本2.5.0
python
# rbenv install -v 2.5.0 # rbenv rehash
rbenv rehash
的做用是有多個Ruby版本的時候要執行的mysql
檢查安裝是否成功nginx
# rbenv versions
設置爲全局(不然ruby
命令沒法使用?)並檢測版本是否正確c++
# rbenv global 2.5.0 # ruby -v
可選/必選安裝bundle
, 由於參考的安裝資料包含Rails
, 因此這個是否必須安裝尚不肯定, 若是同時須要Rails
, 能夠查看底部的參閱文檔.git
# gem install bundler
實際上整個安裝過程已經把
RubyGems
安裝好了?
參閱:github
其它:sql
NodeJS
這個比較簡單, 直接安裝就行了
# yum install nodejs
$ gem install jekyll
接下來在當前用戶的目錄下建立一個博客站點並開啓服務
# cd ~ # jekyll new blog # cd blog # jekyll serve --host 0.0.0.0
此時打開瀏覽器訪問[server ip]:4000
便可.(例如http://118.0.156.000:4000/
)
示例頁面: http://daily.whidy.net/
參閱: http://jekyllcn.com/docs/inst...
官方有遷移文檔, 支持不少種類型的博客遷移, 因此看起來也就比較簡單了, 官方文檔 Import your old & busted site or blog for use with Jekyll., 咱們來嘗試Wordpress遷移.
先按照他的示例, 按照本身的網站進行修改, 大體以下
$ ruby -rubygems -e 'require "jekyll-import"; JekyllImport::Importers::WordPress.run({ "dbname" => "yourWordpressDatabaseName", "user" => "root", "password" => "IcannotTellYou", "host" => "localhost", "port" => "3306", "socket" => "", "table_prefix" => "wp_", "site_prefix" => "", "clean_entities" => true, "comments" => true, "categories" => true, "tags" => true, "more_excerpt" => true, "more_anchor" => true, "extension" => "html", "status" => ["publish"] })'
保證配置無誤後, 回車, 執行報錯!
Traceback (most recent call last): 1: from /home/whidy/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require' /home/whidy/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- ubygems (LoadError)
蛋疼, 查了下資料說多是rubygems的bug, 參閱[Ruby [SOLVED]: After ruby update to 2.5.0, require 'bundler/setup' raise exception](http://www.cloudypoint.com/Tu... 而後看了下, 貌似真的是的, 立馬升級
$ gem update --system
我說gem安裝很是坑爹, 毫無提示, 都不知道是否是正在處理執行的命令, 其實已經在執行了, 根據網絡狀況多等待一下. 接着唰唰唰的出來一大段, 一直到出現RubyGems system software updated
, 就更新完了, 咱們再嘗試遷移命令... 又報錯!!!
Traceback (most recent call last): 2: from -e:1:in `<main>' 1: from /home/whidy/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require' /home/whidy/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- jekyll-import (LoadError)
蛋疼, 上次不是裝了嗎, 仍是我記錯了. 好吧再裝一遍
$ gem install jekyll-import
而後再執行, 反覆報錯... 因而反覆執行各類依賴包... 總結以下
$ gem install sequel $ gem install unidecode $ gem install mysql2
這裏說要mysql2
, 而後執行上面的命令報錯, 又說要mysql-devel
, 服了- -, 那隻能一步步試試看了.
$ yum install mysql-devel
接着試
$ gem install mysql2
再跑遷移命令, 繼續報錯... 信息以下
1: from /home/whidy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gem /home/whidy/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/mysql2-0.5.0/li 111) (Sequel::DatabaseConnectionError)
查到說是要填寫剛纔遷移命令裏面的socket, 這個填啥呢, 我查了半天有各類各樣的, 好比/var/run/mysqld/mysqld.sock
, /tmp/mysql.sock
等等, 多是他們都是mysql
, 而我是MariaDB, 爲了從根本問題上下手, 仍是看看個人MariaDB的配置文件裏面怎麼寫的吧.
這裏須要說明的是, 個人Wordpress數據庫和要遷移到的Jekyll都在同一服務器上, 所以host
這裏填寫的是localhost
$ sudo vi /etc/my.cnf
查到socket=/var/lib/mysql/mysql.sock
, 那麼修改遷移配置以下:
$ ruby -rubygems -e 'require "jekyll-import"; JekyllImport::Importers::WordPress.run({ "dbname" => "yourWordpressDatabaseName", "user" => "root", "password" => "IcannotTellYou", "host" => "localhost", "port" => "3306", "socket" => "/var/lib/mysql/mysql.sock", "table_prefix" => "wp_", "site_prefix" => "", "clean_entities" => true, "comments" => true, "categories" => true, "tags" => true, "more_excerpt" => true, "more_anchor" => true, "extension" => "html", "status" => ["publish"] })'
慢慢的, 從前面十幾條錯誤, 減小到了最後一條
Could not require 'htmlentities', so the :clean_entities option is now disabled.
看來仍是比較成功的... 那就裝一個試試看吧
$ gem install htmlentities
安裝後, 再次執行遷移命令, 搞得心都要碎了... 複製粘貼回車...
額, 沒. 有. 任. 何. 反. 應. 的. 結. 束. 了... 難道成功了?
在安裝Jekyll的目錄下編譯一下看看...
[whidy@VM_0_3_centos blog]$ jekyll b
又報錯...
Configuration file: /home/whidy/blog/_config.yml Source: /home/whidy/blog Destination: /home/whidy/blog/_site Incremental build: disabled. Enable with --incremental Generating... ...此處省略字數 哈哈哈... Build Warning: Layout 'nav_menu_item' requested in _posts/2012-11-27-1132.html does not exist. Liquid Exception: Liquid syntax error (line 40): Variable '{{$r['catid']}}' was not properly terminated with regexp: /\}\}/ in /home/whidy/blog/_posts/2012-11-29-phpcms-page-solution.html jekyll 3.7.3 | Error: Liquid syntax error (line 40): Variable '{{$r['catid']}}' was not properly terminated with regexp: /\}\}/
查了下大概是說Liquid
的正則規則, 面對{{
這種玩意就掛了. 把它改爲{ {
, 參閱: Liquid Exception: Variable '{{ {0}' was not properly terminated with regexp: /}}/ in #466, 而後我就去_posts
目錄把這篇文章手動改了... 再jekyll b
一下.
[whidy@VM_0_3_centos blog]$ jekyll b Configuration file: /home/whidy/blog/_config.yml Source: /home/whidy/blog Destination: /home/whidy/blog/_site Incremental build: disabled. Enable with --incremental Generating... ... 幾十條這樣的信息開始... Build Warning: Layout 'nav_menu_item' requested in _posts/2012-11-27-1107.html does not exist. ... 幾十條這樣的信息結束... Build Warning: Layout 'bnfw_notification' requested in _posts/2018-01-16-%e8%af%84%e8%ae%ba.html does not exist. Build Warning: Layout 'nav_menu_item' requested in _posts/2018-02-26-3119.html does not exist. done in 9.708 seconds. Auto-regeneration: disabled. Use --watch to enable.
這樣就算完成了? 刷新一下我才配置的Nginx二級域名頁面, 方法大體如原文, 我靠, 昨天不是搞好了403
錯誤嗎? 咋又來, 不過不怕, 已經知道是權限問題了, 咱們在分析下哪裏出問題. (而後一陣胡亂修改權限後就行了- -,), 我認爲估計有效的命令是這一條
# chmod 755 -R /home/whidy/blog/
而後刷新頁面, 就行了. 固然我這是裸奔的Jekyll, 沒有主題, 因此看起來很樸素. 不過仍是有些問題的.
好比, 以前加密的單頁面被放在導航上了. 文章列表中有一些帶數字的文章, 還有評論, 這些本不應存在- -, 因此遷移後的優化也是少不了的, 不過至此關於Wordpress遷移到Jekyll的工做已經完成.
遷移完成後, 也有一些問題是須要解決的, 大體想到的以下
若是你也想把wordpress站點內容遷移至Jekyll, 閱讀該文中發現錯誤, 或者經過該文示例過程當中的嘗試發生了一些沒法解決的問題, 歡迎留言~