Total Pageviews

Wednesday, 28 August 2013

在linux vps上搭建静态博客程序-gor

首先在你的vps上搭建go环境,参见http://briteming.blogspot.com/2013/05/linuxgo.html,然后:

# wget https://gor.googlecode.com/files/gor-2.5.zip
# unzip gor-2.5.zip
# cd linux
# mv gor /root
新建站点 :
# cd /root
# gor new my-gor-site (这样,在/root/下,会生成my-gor-site目录)
# cd my-gor-site
# gor post "goodday" (即可生成posts/goodday.md文件.用nano编辑这个goodday.md,保存,帖子就写好了)
# gor compile (运行该命令生成静态网页,即发布帖子)
# gor -http=:2345 http(如果你的vps 的8080端口被占用了,则运行该命令。如果未被占用,则运行gor http.用该行命令临时预览一下网站)

打开你的浏览器,访问 http://urvps.com:2345,即可看到博客效果。若不想看效果了,按ctrl+c退出该命令。
在运行那个gor compile后,在/root/my-gor-site/下面会生成compiled目录,这个目录就是网站的根目录,绑定一个域名到该compiled目录,即可用该域名访问这个博客网站。

我的示例:http://gor.brite.biz,
http://as3.brite.biz:3560/(这个是用nohup Rwebserver 3560 > /dev/null &实现的:
as3:~/my-gor-site/compiled# nohup Rwebserver 3560 > /dev/null &)

以后如果要写新帖,重复gor post "xxx"gor compile即可。

官网:https://github.com/wendal/gor
--------------------------------
你也可编译gor如下:

首先安装go1.4版。(从官网下载go1.4版 ,解压到/usr/local,这样/usr/local/下会生成go目录)
cd /usr/local/go/
mkdir gospace
cd gospace
export GOPATH=`pwd`

root@AR:/usr/local/go/gospace# /usr/local/go/bin/go install github.com/wendal/gor/gor
src/github.com/wendal/gor/gor/gor.go:8:2: cannot find package "github.com/howeyc/fsnotify" in any of:
/usr/local/go/src/github.com/howeyc/fsnotify (from $GOROOT)
/usr/local/go/gospace/src/github.com/howeyc/fsnotify (from $GOPATH)
root@AR:/usr/local/go/gospace# /usr/local/go/bin/go get github.com/howeyc/fsnotify
root@AR:/usr/local/go/gospace# ls src/github.com/
aws     goftp go-xiaohei  hyqhyq3   kr peachdocs  Unknwon
BurntSushi  go-ini h12w     jmespath  mirovarga  pkg     wendal
eahydra     go-macaron howeyc     kless     mschoch reusee
root@AR:/usr/local/go/gospace# /usr/local/go/bin/go install github.com/wendal/gor/gor
root@AR:/usr/local/go/gospace# ls
bin  pkg  src
root@AR:/usr/local/go/gospace# ls bin
gor  peach  pugo

root@AR:/usr/local/go/gospace#
(/usr/local/go/gospace/bin/里面出现了可执行文件gor,说明gor安装成功。)
root@AR:/usr/local/go/gospace# bin/gor -h
2013/08/27 22:16:34 gor.go:46: gor ver 3.7.0
Usage of bin/gor:
  -debug=true: Enable Debug, verbose output
  -http=":8080": Http addr for Preview or Server
root@AR:/usr/local/go/gospace#

注意:如果你安装了go1.4,又安装了go1.5,然后运行/usr/local/go1.5.x/bin/go get github.com/abc/xyz遇到错误:“imports runtime: C source files not allowed when not using cgo or SWIG”,解决办法:需要重新设置GOROOT,指向/usr/local/go1.5.x/即可。参见http://stackoverflow.com/questions/27772831/golang-c-source-files-not-allowed-when-not-using-cgo里的一句话:“if you install Go 1.4 and then install Go 1.5. But don't change GOROOT environment variables. Change GOROOT ,point to GO 1.5 path.“
--------------------------------
gor的一个修改版:
https://github.com/hugozhu/blog,这个修改版支持分页。原作者的版本不支持分页。

git clone https://github.com/hugozhu/blog hugozhu-blog
cd hugozhu-blog
gor compile
 
我的演示站点:http://as3.brite.biz:36723/
作者的演示站点:http://hugozhu.myalert.info/