在debian中安装octopress

前面讲了如何在heroku中部署octopress,不过heroku毕竟不在自己的手上,对于用户来说是一个遗憾,贝多芬说了:要扼住命运的咽喉。因此自己的博客就要部署在自己的VPS上。下面讲一下如何在debian squeeze中部署git+ruby+nginx+octopress。

git

git的安装很简单:

# apt-get update
# apt-get install git-core
# git config --global user.name "alfie chan"
# git config --global user.email admin@linuxabc.net.cn

ruby

ruby的版本众多,安装和管理比较复杂。另外,debian开发者对ruby的代码树管理很不满
已经决定终止对ruby进行打包,这使得ruby在debian上的安装更为麻烦,目前squeeze中ruby的版本是1.9.1(用户通过apt-cache search会看到一个ruby 1.9.2,但那是虚拟包,不是真正的1.9.2),然而ocotpress对ruby的版本要求是1.9.2,因此我先是采用rvm,但是遇到一些问题,最后决定手工编译的方式进行安装。

# bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  994k  100  994k    0     0  45792      0  0:00:22  0:00:22 --:--:-- 41842

Installing RVM to /usr/local/rvm/
    Creating RVM system user group 'rvm'

# RVM:  Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.io/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Cheatsheet: http://cheat.errtheblog.com/s/rvm/
# Screencast: http://screencasts.org/episodes/how-to-use-rvm

# In case of any issues read output of 'rvm requirements' and/or 'rvm notes'

Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask g+w`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

# root,
#
#   Thank you for using RVM!
#   I sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne


rvm 1.13.0 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [h
ttps://rvm.io/]

根据上面的提示,执行:

# source /etc/profile.d/rvm.sh

然后:

# rvm install 1.9.2

出现错误,根据/usr/local/rvm/1.9.2/extract.log的错误提示,原来安装的过程中还需要用到makebzip2这两个工具。

于是:

# aptitude install make bzip2

接着:

# rvm install 1.9.2
Fetching yaml-0.1.4.tar.gz to /usr/local/rvm/archives
Extracting yaml-0.1.4.tar.gz to /usr/local/rvm/src
Configuring yaml in /usr/local/rvm/src/yaml-0.1.4.
Compiling yaml in /usr/local/rvm/src/yaml-0.1.4.
Installing yaml to /usr/local/rvm/usr
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-1.9.2-p320, this may take a while depend
ing on your cpu(s)...

ruby-1.9.2-p320 - #fetching
ruby-1.9.2-p320 - #extracting ruby-1.9.2-p320 to /usr/local/rvm/src/ruby-1.9.2-p320
ruby-1.9.2-p320 - #extracted to /usr/local/rvm/src/ruby-1.9.2-p320
ruby-1.9.2-p320 - #configuring
ruby-1.9.2-p320 - #compiling
ruby-1.9.2-p320 - #installing
Retrieving rubygems-1.8.24
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  371k  100  371k    0     0  35412      0  0:00:10  0:00:10 --:--:-- 51058
Extracting rubygems-1.8.24 ...
Removing old Rubygems files...
Installing rubygems-1.8.24 for ruby-1.9.2-p320 ...
Installation of rubygems completed successfully.
ruby-1.9.2-p320 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.2-p320 - #importing default gemsets (/usr/local/rvm/gemsets/)
Install of ruby-1.9.2-p320 - #complete

然后通过git将octopress克隆到本地:

# git clone git://github.com/imathis/octopress.git octopress
# cd octopress
====================================================================================
= NOTICE                                                                           =
====================================================================================
= RVM has encountered a new or modified .rvmrc file in the current directory       =
= This is a shell script and therefore may contain any shell commands.             =
=                                                                                  =
= Examine the contents of this file carefully to be sure the contents are          =
= safe before trusting it! ( Choose v[iew] below to view the contents )            =
====================================================================================
Do you wish to trust this .rvmrc file? (/home/chenr/octopress/.rvmrc)
y[es], n[o], v[iew], c[ancel]> y
Using /usr/local/rvm/gems/ruby-1.9.2-p320
# rake install
rake aborted!
You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may solve this.

(See full trace by running task with --trace)

也就是说要用bundle exec rake

root@deb600-64-mgmt:/home/chenr/octopress# bundle exec rake install
## Copying classic theme into ./source and ./sass
root@deb600-64-mgmt:/home/chenr/octopress#

创建第一篇博客

# bundle exec rake new_post["hello-octopress"]
# vim ./source/_post/2012-04-30-hello-octopress.markdown

生成静态网站

deb600-64-mgmt:/home/chenr/octopress/source/_posts# bundle exec rake generat
(in /home/chenr/octopress)
## Generating Site with Jekyll
unchanged sass/screen.scss
Configuration from /home/chenr/octopress/_config.yml
/usr/local/rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/https.rb:92:in `require': no such file to load -- openssl (LoadError)
        from /usr/local/rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/https.rb:92:in `<top (required)>'
        from /home/chenr/octopress/plugins/gist_tag.rb:10:in `require'
        from /home/chenr/octopress/plugins/gist_tag.rb:10:in `<top (required)>'
        from /usr/local/rvm/gems/ruby-1.9.2-p320/gems/jekyll-0.11.0/lib/jekyll/site.rb:76:in `require'
        from /usr/local/rvm/gems/ruby-1.9.2-p320/gems/jekyll-0.11.0/lib/jekyll/site.rb:76:in `block in setup'
        from /usr/local/rvm/gems/ruby-1.9.2-p320/gems/jekyll-0.11.0/lib/jekyll/site.rb:75:in `each'
        from /usr/local/rvm/gems/ruby-1.9.2-p320/gems/jekyll-0.11.0/lib/jekyll/site.rb:75:in `setup'
        from /usr/local/rvm/gems/ruby-1.9.2-p320/gems/jekyll-0.11.0/lib/jekyll/site.rb:30:in `initialize'
        from /usr/local/rvm/gems/ruby-1.9.2-p320/gems/jekyll-0.11.0/bin/jekyll:224:in `new'
        from /usr/local/rvm/gems/ruby-1.9.2-p320/gems/jekyll-0.11.0/bin/jekyll:224:in `<top (required)>'
        from /usr/local/rvm/gems/ruby-1.9.2-p320/bin/jekyll:23:in `load'
        from /usr/local/rvm/gems/ruby-1.9.2-p320/bin/jekyll:23:in `<main>'

google
/usr/local/rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/https.rb:92:inrequire': no such file to load — openssl (LoadError)`

依稀记得octopress推荐使用ruby-1.9.2-p290,于是

# rvm install ruby-1.9.2-p290
# rvm use ruby-1.9.2-p290
# bundle exec rake generate

错误依旧,傻眼了,还得求助google,我换了一下关键字require': no such file to load -- openssl (LoadError)

这次有结果了:Setting Up Octopress

原来是还缺libssl-dev这个软件包

# aptitude install libssl-dev
# rvm reinstall ruby-1.9.2-p290

终于成功了!归根结底,rvm在安装ruby时,即便缺乏依赖包也没有提示,看来用rvm来安装ruby不怎么靠谱啊。即便用rbenv

nginx

编译和安装

# ./configure --sbin-path=/usr/sbin --conf-path=/etc/nginx/nginx.conf \
 --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid \
 --lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log \
 --http-client-body-temp-path=/var/lib/nginx/body \
 --http-proxy-temp-path=/var/lib/nginx/proxy \
 --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug \
 --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module \
 --with-http_dav_module


Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/sbin"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/lib/nginx/body"
  nginx http proxy temporary files: "/var/lib/nginx/proxy"
  nginx http fastcgi temporary files: "/var/lib/nginx/fastcgi"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

# make & make install

mkdir /var/log/nginx && chown nginx:nignix /var/log/nginx

mkdir /var/lib/nginx && chown nginx:nignix /var/lib/nginx

/etc/init.d/nginx

检测一下:

# lynx localhost