Category Archives: unix/linux

unix,linux related

graphviz examples

Table of Contents

patricia tree

digraph g {
graph [
#rankdir = LR
];

node [
fontsize = "20"
fontname = "Times-Italic"
];

edge [
];

##parent [
##label = "parent"
##fontcolor=red
##shape = plaintext
##];

##kid_node [
##label = "kid_node"
##fontcolor=red
##shape = plaintext
##];

nodei [
label = "'/i/' \,idx = 0"
shape = ellipse
];

nodeiism [
label = "'/i/ism/' \,idx = 3"
shape = ellipse
];

nodea1 [
label = "'a1' \,idx = 0"
shape = ellipse
];

kidsi [
label = "'/'"
shape = box
];

kidsa [
label = "'a'"
shape = box
];

kids0 [
label = "'\0'"
shape = box
];

kidsa1 [
label = "'/'"
shape = box
];

nodei -> kidsi[label = "kids"];
kidsi -> nodeiism[label = "node"];
kidsi -> kidsa[label = "brother"];
{rank = same;kidsi;kidsa;}
kidsa ->nodea1[label = "node"];

nodeiism ->kids0[label = "kids"];
nodea1 ->kidsa1[label = "kids"];

kids0 ->nodei[label = "node"];
kidsa1 ->nodei[label = "node"];
}

输出: http://pic.yupoo.com/zhongyijun/Corvv8Xi/k223V.png

digraph g {
graph [
#rankdir = LR
];

node [
fontsize = "20"
fontname = "Times-Italic"
];

edge [
];

##parent [
##label = "parent"
##fontcolor=red
##shape = plaintext
##];

##kid_node [
##label = "kid_node"
##fontcolor=red
##shape = plaintext
##];
nodei [
label = "'/i/' \,idx = 0"
shape = ellipse
];

nodeiism [
label = "'/i/ism/' \,idx = 3"
style=filled
color=red
shape = ellipse
];

nodea1 [
label = "'a1' \,idx = 0"
shape = ellipse
];

kidsi [
label = "'/'"
shape = box
];

kidsa [
label = "'a'"
shape = box
];

kids0 [
label = "'\0'"
shape = box
];

kidsa1 [
label = "'/'"
shape = box
];

nodei -> kidsi[label = "kids"];
kidsi -> nodeiism[label = "node"];
kidsi -> kidsa[label = "brother"];
{rank = same;kidsi;kidsa;}
kidsa ->nodea1[label = "node"];

nodeiism ->kids0[label = "kids"];
nodea1 ->kidsa1[label = "kids"];
kidsa1 ->nodei[label = "node"];

kids0 ->nodei[label = "node"];

{rank=min;nodei;}
{rank=max;kids0;}
}

输出: http://pic.yupoo.com/zhongyijun/CorvvmAZ/aTXth.png

digraph g {
graph [
#rankdir = LR
];

node [
fontsize = "20"
fontname = "Times-Italic"
];

edge [
];

parent [
label = "parent"
fontcolor=blue
shape = plaintext
];

kid_node [
label = "kid_node"
fontcolor=blue
shape = plaintext
];

nodei [
label = "'/i/' \,idx = 0"
shape = ellipse
];

nodeiism [
label = "'/i/ism/' \,idx = 3"
color=red
style=filled
shape = ellipse
];

nodea1 [
label = "'a1' \,idx = 0"
shape = ellipse
];

kidsi [
label = "'/'"
shape = box
];

kidsa [
label = "'a'"
shape = box
];

kids0 [
label = "'\0'"
shape = box
];

kidsa1 [
label = "'/'"
shape = box
];

nodei -> kidsi[label = "kids"];
kidsi -> nodeiism[label = "node"];
kidsi -> kidsa[label = "brother"];
{rank = same;kidsi;kidsa;}
kidsa ->nodea1[label = "node"];

nodeiism ->kids0[label = "kids"];
nodea1 ->kidsa1[label = "kids"];
kidsa1 ->nodei[label = "node"];

kids0 ->nodei[label = "node"];
{rank=min;nodei;}
{rank=max;kids0;kid_node;}

parent -> nodeiism;
kid_node ->nodeiism;
}

输出: http://pic.yupoo.com/zhongyijun/Corvvvsu/NG4g1.png

digraph g {
graph [
#rankdir = LR
];

node [
fontsize = "20"
fontname = "Times-Italic"
];

edge [
];

parent [
label = "parent"
fontcolor=blue
shape = plaintext
];

kid_node [
label = "kid_node"
fontcolor=blue
shape = plaintext
];

nodei [
label = "'/i/' \,idx = 0"
shape = ellipse
];

nodeiism [
label = "'/i/ism/' \,idx = 3"
color=red
style=filled
shape = ellipse
];

nodea1 [
label = "'a1' \,idx = 0"
shape = ellipse
];

kidsi [
label = "'/'"
shape = box
];

kidsa [
label = "'a'"
shape = box
];

kids0 [
label = "'\0'"
shape = box
];

kidsa1 [
label = "'/'"
shape = box
];

nodei -> kidsi[label = "kids"];
kidsi -> nodeiism[label = "node"];
kidsi -> kidsa[label = "brother"];
{rank = same;kidsi;kidsa;}
kidsa ->nodea1[label = "node"];

nodeiism ->kids0[label = "kids"];
nodea1 ->kidsa1[label = "kids"];
kidsa1 ->nodei[label = "node"];

kids0 ->nodei[label = "node"];
{rank=min;nodei;}
{rank=max;kids0;kid_node;}

parent -> nodeiism;
##{rank = same;parent;nodei;}
kid_node ->nodei;
##{rank = same;kid_node;nodeiism;}
}

输出: http://pic.yupoo.com/zhongyijun/Corvvngz/na1iz.png

digraph g {
graph [
#rankdir = LR
];

node [
fontsize = "20"
fontname = "Times-Italic"
];

edge [
];

nodei [
label = "'/i/' \,idx = 0"
shape = ellipse
];

nodeite [
label = "'/i/te' \,idx = 3"
shape = ellipse
];

nodeitest [
label = "'/i/test' \,idx = 5"
shape = ellipse
];

nodea1 [
label = "'a1' \,idx = 0"
shape = ellipse
];

nodeb1 [
label = "'b1' \,idx = 0"
shape = ellipse
];

kidsi [
label = "'/'"
shape = box
];

kidsb [
label = "'b'"
shape = box
];

kidsa [
label = "'a'"
shape = box
];

kidst [
label = "t"
shape = box
];

kids0 [
label = "'\0'"
shape = box
];

kidsb1 [
label = "'/'"
shape = box
];

kidsa1 [
label = "'/'"
shape = box
];

nodei -> kidsi[label = "kids"];
kidsi -> nodeite[label = "node"];
kidsi -> kidsb[label = "brother"];
{rank = same;kidsi;kidsb;}

kidsb ->nodeb1[label = "node"];
kidsb ->kidsa[label = "brother"];
{rank = same;kidsa;kidsb;}

kidsa ->nodea1[label = "node"];

nodeite ->kidst[label = "kids"];
kidst ->nodeitest[label = "node"];

nodeitest ->kids0[label = "kids"];
kids0 ->nodeite[label = "node"];

nodeb1 ->kidsb1[label = "kids"];
kidsb1 ->nodei[label = "node"];

nodea1 ->kidsa1[label = "kids"];
kidsa1 ->nodei[label = "node"];
}

输出: http://pic.yupoo.com/zhongyijun/CorvvJ6I/tXwqH.png

digraph g {
graph [
#rankdir = LR
];

node [
fontsize = "20"
fontname = "Times-Italic"
];

edge [
];

parent [
label = "parent"
fontcolor=red
shape = plaintext
];

kid_node [
label = "kid_node"
fontcolor=red
shape = plaintext
];

len [
label = "len = 12"
fontcolor = blue
shape = plaintext
];

nodei [
label = "'/i/' \,idx = 0"
shape = ellipse
];

nodeite [
label = "'/i/te' \,idx = 3"
shape = ellipse
];

nodeitest [
label = "'/i/test' \,idx = 5"
shape = ellipse
];

nodea1 [
label = "'a1' \,idx = 0"
shape = ellipse
];

nodeb1 [
label = "'b1' \,idx = 0"
shape = ellipse
];

kidsi [
label = "'/'"
shape = box
];

kidsb [
label = "'b'"
shape = box
];

kidsa [
label = "'a'"
shape = box
];

kidst [
label = "t"
shape = box
];

kids0 [
label = "'\0'"
shape = box
];

kidsb1[
label = "'/'"
shape = box
];

kidsa1 [
label = "'/'"
shape = box
];

nodei -> kidsi[label = "kids"];
kidsi -> nodeite[label = "node"];
kidsi -> kidsb[label = "brother"];
{rank = same;kidsi;kidsb;}

kidsb ->nodeb1[label = "node",len = 2.5];
kidsb ->kidsa[label = "brother"];
{rank = same;kidsa;kidsb;}

kidsa ->nodea1[label = "node",len = 2.5];

nodeite ->kidst[label = "kids"];
kidst ->nodeitest[label = "node"];

nodeitest ->kids0[label = "kids"];
kids0 ->nodeite[label = "node"];

nodeb1 ->kidsb1[label = "kids"];
kidsb1 ->nodei[label = "node"];

nodea1 ->kidsa1[label = "kids"];
kidsa1 ->nodei[label = "node"];

parent ->nodei;
{rank = same;parent;nodei;}
kid_node ->nodeite;
{rank = same;kid_node;nodeite;}

len ->nodei[style=invis];
{rank=same;len;nodei;}
}

输出: http://pic.yupoo.com/zhongyijun/Corvv480/tydlI.png

digraph g {
graph [
#rankdir = LR
];

node [
fontsize = "20"
fontname = "Times-Italic"
];

edge [
];

parent [
label = "parent"
fontcolor=red
shape = plaintext
];

kid_node [
label = "kid_node"
fontcolor=red
shape = plaintext
];

len [
label = "len = 12"
fontcolor = blue
shape = plaintext
];

nodei [
label = "'/i/' \,idx = 0"
shape = ellipse
];

nodeite [
label = "'/i/te' \,idx = 3"
shape = ellipse
];

nodeitest [
label = "'/i/test' \,idx = 5"
shape = ellipse
];

nodea1 [
label = "'a1' \,idx = 0"
shape = ellipse
];

nodeb1 [
label = "'b1' \,idx = 0"
shape = ellipse
];

kidsi [
label = "'/'"
shape = box
];

kidsb [
label = "'b'"
shape = box
];

kidsa [
label = "'a'"
shape = box
];

kidst [
label = "t"
shape = box
];

kids0 [
label = "'\0'"
shape = box
];

kidsb1 [
label = "'/'"
shape = box
];

kidsa1 [
label = "'/'"
shape = box
];

nodei -> kidsi[label = "kids"];
kidsi -> nodeite[label = "node"];
kidsi -> kidsb[label = "brother"];
{rank = same;kidsi;kidsb;}
{rank = min;nodei;}

kidsb ->nodeb1[label = "node",len = 2.5];
kidsb ->kidsa[label = "brother"];
{rank = same;kidsa;kidsb;}

kidsa ->nodea1[label = "node",len = 2.5];

nodeite ->kidst[label = "kids"];
kidst ->nodeitest[label = "node"];

nodeitest ->kids0[label = "kids"];
kids0 ->nodeite[label = "node"];

nodeb1 ->kidsb1[label = "kids"];
kidsb1 ->nodei[label = "node"];
nodea1 ->kidsa1[label = "kids"];
kidsa1 ->nodei[label = "node"];

parent ->nodeite;
{rank = same;parent;nodeite;}
kid_node ->nodeitest;
{rank = same;kid_node;nodeitest;}

len ->nodei[style=invis];
{rank=same;len;nodei;}
}

输出: http://pic.yupoo.com/zhongyijun/Corvw2Wi/hsLFP.png

digraph g {
graph [
#rankdir = LR
];

node [
fontsize = "20"
fontname = "Times-Italic"
];

edge [
];

parent [
label = "parent"
fontcolor = red
shape = plaintext
];

kid_node [
label = "kid_node"
fontcolor=red
shape = plaintext
];

len [
label = "len = 12"
fontcolor=blue
shape = plaintext
];

nodei [
label = "'/i/' \,idx = 0"
shape = ellipse
];

nodeite [
label = "'/i/te' \,idx = 3"
shape = ellipse
];

nodeitest [
label = "'/i/test' \,idx = 5"
shape = ellipse
];

nodea1 [
label = "'a1' \,idx = 0"
shape = ellipse
];

nodeb1 [
label = "'b1' \,idx = 0"
shape = ellipse
];

kidsi [
label = "'/'"
shape = box
];

kidsb [
label = "'b'"
shape = box
];

kidsa [
label = "'a'"
shape = box
];

kidst [
label = "t"
shape = box
];

kids0 [
label = "'\0'"
shape = box
];

kidsb1[
label = "'/'"
shape = box
];

kidsa1 [
label = "'/'"
shape = box
];

nodei -> kidsi[label = "kids"];
kidsi -> nodeite[label = "node"];
kidsi -> kidsb[label = "brother"];
{rank = same;kidsi;kidsb;}
{rank = min;nodei;}

kidsb ->nodeb1[label = "node",len = 2.5];
kidsb ->kidsa[label = "brother"];
{rank = same;kidsa;kidsb;}

kidsa ->nodea1[label = "node",len = 2.5];

nodeite ->kidst[label = "kids"];
kidst ->nodeitest[label = "node"];

nodeitest ->kids0[label = "kids"];
kids0 ->nodeite[label = "node"];

nodeb1 ->kidsb1[label = "kids"];
kidsb1 ->nodei[label = "node"];
nodea1 ->kidsa1[label = "kids"];
kidsa1 ->nodei[label = "node"];

parent ->nodeitest;
kid_node ->nodeitest;
{rank = max;parent;kid_node;kids0}

len ->nodei[style=invis];
{rank=same;len;nodei;}
}

输出: http://pic.yupoo.com/zhongyijun/CorvvVnC/mxKga.png

参考文献

media wiki使用bibtex扩展

下载和安装

进入media wiki的extensions目录:

cd ./extensions

下载扩展:

wget http://simson.net/src/Bibtex.tar.gz

解压并且安装:

tar zxvf tar -xvzf Bibtex.tar.gz
mv Bibtex BibTex

设置LocalSettings.php:

require_once( "$IP/extensions/Bibtex/bibtex.php");

配置bibtex(bibstyle.php):

$wbib_usejavascript  = true;             # Sometimes people don't want to use js. I can understand it.
$wbib_allowbibpopup  = true;             # A link named bibtex is appearing. It can pop with the bibtex reference like in ACM libraries
$wbib_allowdivpopup  = true;             # A div is popping when the cursor is over the link named bibtex;

效果请参考:

http://simson.net/page/Mediawiki_Bibtex_Extension

注意事项

一定要把Bibtex重新命名为BibTex,要不然无法加载bibtex.css文件。

参考文献

在openshift顺利上搭建media wiki,并成功绑定域名

开通博客之后,一直有个想法搭建一个wiki平台进行知识管理,这些大量的文章写到wordpress还是不太合适,毕竟wiki的分类、查找和链接还是非常方便的;闲话少说,下面记录一下过程。

1.关于openshift的介绍

1.1 来自维基百科:

OpenShift is a cloud computing platform as a service product from Red Hat. The software that runs the service is open-sourced under the name “OpenShift Origin”, and is available on GitHub. Developers can use Git to deploy web applications in different languages on the platform. Uniquely, OpenShift also supports binary programs that are web applications, so long as they can run on RHEL Linux. This allows the use of arbitrary languages and frameworks. OpenShift takes care of maintaining the services underlying the application and scaling the application as needed.

1.2 来自百度百科

红帽OpenShift通过为开发人员提供在语言、框架和云上的更多的选择,使开发人员可以构建、测试、运行和管理他们的应用,从而重新定义了PaaS市场。以红帽全面的JBoss专业知识为基础,OpenShift凭借创新的特性(包括CDI)领导PaaS市场,并支持Java EE 6,从而将PaaS的能力扩展到更丰富和更苛刻的应用。建立在红帽开源领导地位基础上的OpenShift旨在终结PaaS的厂商锁定,使用户可以选择自己应用运行在哪个云提供商的云中。OpenShift将作为在线服务来提供。

2.关于media wiki

看了minix3的wiki站点之后,对python写的MoinMoin很有好感,刚开始还一直在为MediaWiki,MoinMoin,和dokuwiki的选择而头疼,经过一番搜索,觉得media wiki对中文的支持是最好的,而且支持php的主机也多,以后迁移什么的可能会方便一些,果断使用之。

2.1 来自维基百科的介绍

MediaWiki is a free web-based wiki software application. Developed by the Wikimedia Foundation and others, it is used to run all of the Foundation’s projects, including Wikipedia, Wiktionary and Wikinews. Numerous other wikis around the world also use it to power their websites. It is structured functionally.

2.2 来自百度百科

MediaWiki全球最著名的开源wiki程序,运行于PHP+MySQL环境。MediaWiki从2002年2月25日被作为维基百科全书的系统软件,并有大量其他应用实例。目前MediaWiki的开发得到维基媒体基金会的支持。 MediaWiki是建立wiki网站的首选后台程序,目前国内的灰狐维客等站点都采用这套系统。 MediaWiki一直保值着持续更新,当前最新版本为1.5.8(2006-3-26)和1.6.6(2006-5-23)稳定版本。MediaWiki的原作者为德国的Magnus Manske。

3.在openshift上申请账号,猛击这里

下载安装openshift的开发客户端 https://openshift.redhat.com/community/get-started

4.安装media wiki

这里假设你使用的平台是unix或者linux,用CLI进行操作,windows平台用git bash,请看参考文献。

4.1 建立一个wiki的php应用,并绑定mysql到这个应用上

app create -a wiki -t php-5.3
rhc app cartridge add -a wiki -c mysql-5.1

当你绑定mysql到你的wiki应用之后,openshift会分配给你mysql的主机名,用户名和密码,如下图,请保管好。 注意: “mysql://ip:port”,后面那个ip地址,请记住它,后面配置mysql数据库的时候会用到,它是数据库的主机名称,而不是localhost。

4.2 下载wiki程序并解压到目录wiki/

cd wiki/php
wget http://download.wikimedia.org/mediawiki/1.19/mediawiki-1.19.2.tar.gz
tar zxvf mediawiki-1.19.2.tar.gz
cd mediawiki-1.19.2
cp * -R  ..
cd ..
rm -rf mediawiki-1.19.2

4.3 用git提交到openshift,并发布应用

git commit -A
git commit -a -m "my first wiki"
git push

4.4 配置你的wiki,界面语言,数据库,还有一些其他信息

具体请看下面各图

4.4.1 访问你的wiki应用

比如说:http://wiki-verynix.rhcloud.com; 开始进行wiki的相关参数设置,如下图: http://pic.yupoo.com/zhongyijun/CeKPcjSF/bFjQ8.png

4.4.2 选择语言

http://pic.yupoo.com/zhongyijun/CeKPcjSF/bFjQ8.png

4.4.3 填写数据库信息

这一步容易出错:特别是主机名字,不是localhost,数据库主机填写刚才绑定mysql到php应用的时候分到的ip地址。

4.4.4 数据库配置

默认就行

4.4.5 其他信息

填上就行 http://pic.yupoo.com/zhongyijun/CeKPcQWy/lf0NR.png

4.4.6 下载配置文件,然后git上传

配置完成之后,会提示你下载LocalSettings.php文件,这是刚才所有配置步骤生成的文件,请下载到你的本地应用目录里面,例如wiki/php,然后用git上传到openshift:

git add LocalSettings.php
git commit -a -m "settings coinfig file"
git push

5.绑定域名

5.1 用openshift的命令行工具执行以下命令:

rhc app add-alias -a wiki --alias wiki.verynix.com

5.2 添加CNAME记录

到你的DNS解析服务器那里添加一条CNAME记录(DNS记录科普知识 http://www.lihongye.net/post/dns.html),我用的是dnspod,如下图所示: http://pic.yupoo.com/zhongyijun/CfDaqvEW/pzzyD.png

5.3 修改wgServer变量

重要的一步,修改根目录下的LocalSettings.php的wgServer变量,要不然每当你访问你已经绑定的域名:wiki.verynix.com,网站会重定向回原来openshift给你的域名:wiki-verynix.rhcloud.com,相当于没有绑定。

$wgServer = "http://wiki.verynix.com";

然后git commit,git push.至此,一个media wiki应用就搭建成功了: 非常尼克斯的wiki站点;欢迎围观。

Debian Squeeze安装输入法并配置中文环境

fcitx是linux下挺好用的一款中文输入法,词库比较丰富。

1.添加fcitx的源

debian squeeze很保守,因此很稳定,但是这也是源内的软件包版本比较低的原因,所以fcitx没有进debian squeeze,进了testing版本,需要添加下面这行到你的/etc/apt/sources.list:
deb http://download.opensuse.org/repositories/home:hillwood/Debian_6.0/ /

然后:

sudo apt-get update
sudo apt-get install fcitx

新建文件/etc/X11/Xsession.d/95xinput,并把下面这些内容写到里面去:

export XIM=fcitx
export XIM_ARGS="-d"
export XIM_PROGRAM=fcitx
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export LANG="en_US.UTF-8"
export LC_CTYPE="zh_CN.UTF-8"
export XMODIFIERS="@im=fcitx"
fcitx &

如果apt-get update出现以下没有public key的错误:

W: GPG error: http://download.opensuse.org  Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4EE56CE7EBCA0CF4

请加入key:

wget -q http://download.opensuse.org/repositories/home:/hillwood/Debian_6.0/Release.key -O -|apt-key add -

2.设置系统的locale

2.1 什么是locale?

来自wiki pedia:
In computing, a locale is a set of parameters that defines the user’s language, country and any special variant preferences that the user wants to see in their user interface. Usually a locale identifier consists of at least a language identifier and a region identifier. On POSIX platforms such as Unix, Linux and others, locale identifiers are defined similar to the BCP 47 definition of language tags, but the locale variant modifier is defined differently, and the character set is included as a part of the identifier. It is defined in this format: [language[_territory][.codeset][@modifier]]. (For example, Australian English using the UTF-8 encoding is en_AU.UTF-8.)

简而言之,就是系统的字符集。

2.2 配置

sudo apt-get install locales
sudo dpkg-reconfigure locales

选择英语,简体中文和繁体中文的locale:

en_US.ISO-8859-1
en_US.UTF-8
zh_CN.GB2312
zh_CN.GB18030
zh_CN.UTF-8
zh_CN.GBK
zh_TW.BIG5
zh_TW.UTF-8

我缺省locale选择的是英文的en_US.UTF-8,这样系统的默认语言是英文,如果不习惯,请选择zh_CN.UTF-8。

3.安装中文字体

sudo apt-get install ttf-arphic-ukai ttf-arphic-uming xfonts-wqy ttf-bitstream-vera ttf-mscorefonts-installer ttf-wqy-zenhei ttf-wqy-microhei

文泉译的字体挺好看,如果你不喜欢,可以寻找更好看的字体。

4.后记

debian官方中的fcitx包不是很好用,从源代码安装也显得异常麻烦,从debian 6 squeeze升级到debian 7 wheezy之后,fcitx也无法正常工作,出现类似dbus connection error等错误;因此比较推荐从opensuse的这个源安装fcitx。 如果fcitx出现无法启动的其他错误,建议用dpkg –list找到相关软件,然后用apt-get remove删除,然后再重新apt-get install fcitx安装。

5.参考文献

Debian下用emacs的org2blog插件写wordpress博客

1.概述

自从适应了vim或者emacs的编辑模式之后,已经无法忍受其他编辑器的编辑速度,无法在文档内部快速移动的感觉让人很抓狂;为了实现这一“梦想”,前一篇博文足足写了3个星期,蛋疼无比的wordpress默认编辑器总是会自动转义一些字符,在html模式和visual模式相互切换的时候还会自动插入一些无用的代码,为了折腾emacs的org mode环境,又得重新折腾折腾linux环境了,装个软件总出错,不让人省心啊;刚开始想直接用ubuntu,省事,好久没用,LTS的版本都彪到12.04了,不想在实体机上折腾linux了,索性直接在虚拟机里面安装,但ubuntu用他自己的unity桌面,运行起来相当地慢,让我这老爷机情合以堪,无法启动;想起了gentoo,当年大学的岁月就是折腾系统的岁月,折腾系统的岁月就是折腾gentoo的岁月;可是当时无法识别我的dvd刻录机,水平有限,整了很久没有找到解决方案,我心已死,只能把gentoo深深埋在心底;于是乎,思来想去,还是Debian吧,感觉很好,相当稳定。
在这里,把折腾过程记录下来,有些地方可能对新手有用,避免走弯路。

2.安装debian

现在比较懒了,直接在网上找linux的vmware镜像,发现两个不错的网站推荐给同样需要的童鞋。
thought police,这里应该是最出名的提供linux和FreeBSD的vmware iso镜像下载,提供CentOS,Debian,Fedora,FreeBSD,Ubuntu,OpenSUSE的镜像,很不错;不过这里的镜像大多是没有桌面环境的。
trend sigma,这里vmware iso镜像很不错,提供Bodhi,Debian,Fedora,Mint,Ubuntu,Lubuntu,openSUSE的镜像下载,我就是用这里的Debian 6镜像。
注意:trendsigma的Debian 6有两个镜像,一个带vmwaretool,这个版本预装的软件会多一些;一个不带vmware tool,这个版本预装的软件会少些;建议使用带vmware tool的版本,因为第二个版本你需要安装vmwaretool,比较麻烦,还会出现如下的错误:
Searching for GCC...
The path "/usr/bin/gcc" is not valid path to the gcc binary.
Would you like to change it? [yes] 

即使已经有gcc,但是还是会出现这样的错误,因为一些头文件没有正确安装, 解决办法(参见:superuser.com):

sudo aptitude install libglib2.0-0 gcc-4.3 make linux-headers-`uname -r` -y

3.安装emacs和org mode

emacs就不多介绍了,简单介绍一下emacs的org mode,这是一个神器,文本编辑终极解决方案。
来自wiki pedia:
Org-mode is an editing mode in the text editor Emacs which supports the editing of plain text hierarchical documents. It has specific support for a number of different use cases, such as writing to-do lists, project planning, and writing web pages. For example, to-do items can optionally be given priorities and deadlines, subdivided into sub-to-dos or checklists, and given tags and properties. An agenda for the items to be done this week can then be automatically generated by Org-mode.[2] Org-mode also includes a lightweight markup language (similar in function to Markdown, reStructuredText, Textile, etc., but with a different implementation) for text formatting such as *bold*, /italic/, =code=, ~verbatim~, _underlined_, +strike-through+, | tables |, – lists, – [X] checkboxes, * headlines… According to the short description by Org-mode author Carsten Dominik, “Org-mode does outlining, note-taking, hyperlinks, spreadsheets, TODO lists, project planning, GTD, HTML and LaTeX authoring, all with plain text files in Emacs.”[3] Most aspects of Org-mode’s behaviour are customisable, in the standard Emacs ways (that is, either by setting variables directly, or by using the more user-friendly Customize interface). Since Emacs version 22, Org-mode has been part of Emacs[4] – although it is also released separately, and newer versions of Org-mode than the ones shipped with Emacs are often available.

3.1 安装:

sudo apt-get install emacs23
cd ~/.emacs.d (没有就创建)
wget http://orgmode.org/org-7.9.1.tar.gz
tar zxvf org-7.9.1.tar.gz
cd org-7.9.1
make config
sudo make install

3.2 激活org mode:

添加如下代码到你的~/.emacs文件里面(没有就创建):
(add-to-list 'load-path "~/.emacs.d/")
(add-to-list 'load-path "~/.emacs.d/org-7.9.1/lisp")
(add-to-list 'load-path "~/.emacs.d/org-7.9.1/contrib/lisp")
(require 'org-install)
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-cc" 'org-capture)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
(transient-mark-mode 1)

4.安装org2blog

org2blog是把org模式的文章发布成wordpress格式的文章,理论上,也可以发布为其他博客系统的格式。
下面是来自官方网站的介绍:
org2blog/wp is a tool to publish directly from Emacs’ org-mode to WordPress blogs. org2blog/wp is one of the two packages named org2blog. The other is org2blog/atom by Tom Breton. org2blog/wp should, ideally, work with any platform that supports xml-rpc but some of wordpress specific features may not work. org2blog was inspired by and based on a wordpress posting client for muse-mode written by Ashish Shukla. org2blog is licensed under GPLv3.

4.1 安装

cd ~/.emacs.d
git clone http://github.com/punchagan/org2blog.git

把如下代码添加到~/.emacs文件中去:

(setq load-path (cons "~/.emacs.d/org2blog/" load-path))
(require 'org2blog-autoloads)

4.2 org2blog使用方法

这里不介绍,请看参考文献

4.3 一些问题

默认情况下org2blog是把org格式的文章转换成wordpress的文章格式;如果你已经有写好的wordpress文章,但是还是草稿状态,需要转换成org格式的文章,怎么办? org2blog的作者已经写好一个python程序,可以把wordpress的xml格式转换成org格式的文章。具体做法就是到wordpress后台,导出文章为xml格式,然后用这个python脚本转换成org文件,emacs直接编辑就行了。
还有一些问题,如果要批量转换怎么办?可以在wordpress后台新建一个用户,把那些要转换的文章划归到那个用户下,然后导出就行。
在debian squeeze下用org2blog-importers转换的时候,需要安装pandoc程序,因为debian squeeze实在保守了,保守的结果就是稳定,因此源中的软件包版本一般都会比较低,我在debian squeeze上安装pandoc的时候没少受苦,主要是ghc的版本太低,命令行安长cabal-install,然后安装pandoc,无法安装成功,如下错误信息:
base-3.0.3.2 requires syb ==0.1.0.2
however
syb-0.1.0.2 was excluded because json-0.5 requires syb >=0.3.3

官方提供的方法:

cabal install cabal-install
cabal install json-0.4.4
cabal install pandoc

也还是无法解决问题,原因就是ghc的版本太低,6.2的;所以你要自己编译安装最新的ghc,然后再安装pandoc。到这里下载安装最新的ghc,然后到这里下载安装Haskell平台。

5.参考文献

完美支持ipv6的测试工具:tsung

平日工作做单元测试经常会需要进行一些简单的压力测试,挺多功能要测试ipv6地址,在网上找了一圈,发现只有tsung这个的命令行工具能完美支持ipv6地址,非常强大,它是一款分布式的、支持多协议的开源压力测试工具,据说压死过很多服务器,配置非常灵活,推荐大家使用。 来自官方网站的介绍:

What is Tsung ?

Tsung (formerly IDX-Tsunami) is a distributed load testing tool. It is protocol-independent and can currently be used to stress HTTP, WebDAV, SOAP, PostgreSQL, MySQL, LDAP, and Jabber/XMPP servers. It is distributed under the GNU General Public License version 2.

1.安装 需要安装erlang,以debian为例,去官方网站下载最新源代码: http://tsung.erlang-projects.org/;现在的最新版本是1.4.2。

sudo apt-get install erlang
tar zxvf tsung-1.4.2.tar.gz
cd tsung-1.4.2
./configure && make && make install

2.通过几个简单例子来理解配置文件 向服务器发送压力流量通过配置文件来设置相应参数。
2.1 向ip地址为2012:1081::10:8:1:75发压力,每隔0.2秒产生一个并发用户。















2.2 向ip地址为2012:1081::10:8:1:75发压力,每隔0.2秒产生一个并发用户,这次的端口是443(SSL)端口。















3.启动tsung

tsung start -f tsung.xml

tsung.xml是配置文件。

这是一些简单的例子,更多的配置和需求以后陆续更新;tsung用配置文件来定义压力的内容,让压力变得更加可控和扩展性。

参考文献:
1.tsung官方文档
http://tsung.erlang-projects.org/user_manual.html

2.来自iteye的一篇文章
http://cryolite.iteye.com/blog/378758

学习graphviz:画双向队列或者双向链表

我在这篇文章《深入理解FreeBSD中的TAILQ》中需要画队列图举例子,想到的画图工具就是微软的visio,dia,diagram designer,易图等这些所见即所得的画流程图的软件,但是无法画出自己想要的那种效果,或者说要画出那种效果非常难,而且很做作的感觉;于是乎,网上乱搜一番,发现了强大的graphviz软件,画出来的图想当完美;它是AT&T的开源项目,原生的类unix命令行软件,沿袭了unix的文本即一切的思想,类似Knuth教授的tex软件,用文本生成图形。

来自官方网站的介绍(http://www.graphviz.org/):

What is Graphviz?

Graphviz is open source graph visualization software. Graph visualization is a way of representing structural information as diagrams of abstract graphs and networks. It has important applications in networking, bioinformatics,  software engineering, database and web design, machine learning, and in visual interfaces for other technical domains.

我现在要画出下面这个双向队列(或者双向链表)来学习graphviz。

说明(详细信息请见《深入理解FreeBSD中的TAILQ》):

1.这个队列头是queue_head,tqh_first指针指向第一个元素,tqh_last是一个二级指针,是最后一个元素1的tqe_next的地址。数据结构如下所示:

struct int_head {
    struct int_node *tqh_first; /* first element */
    struct int_node **tqh_last; /* addr of last next element */
} queue_head;

2.队列中的元素结构体如下:tqe_next是指向下一个元素的指针,tqe_prev是二级指针,是前一个元素的tqe_next的地址。

struct int_node{
    int num;
    struct int_node *tqe_next;  /* next element */
    sturct int_node **tqe_prev; /* address of previous next element */
};

先来一个简单的,画队列头的代码:

digraph g {
graph [
rankdir = "LR"
];
node [
fontsize = "20"
fontname = "Times-Italic"
shape = "record"
];

head [label = " tqh_first|  tqh_last"];
queue_head [label="queue_head",shape=plaintext];
head:last ->head:first;
head:first ->NULL;
head:last -> queue_head[style=invis,constraint=false];
}

生成这样的图:

解释:
这个图g中有3个节点:第一个节点叫做head,形状是record(可以分层,类似struct),第一层first的文字是tqh_first,第二层的文字是tqh_last;第二个几点叫做queue_head,形状是plaintext,也就是只有文字没有边框;第三个节点叫NULL。接下来是形容他们的指向关系。

下面这段代码生成开始的那个图:

digraph g {
rankdir=LR;
node [
fontsize = "20"
fontname = "Times-Italic"
shape = "record"
];

head [label = "tqh_first| tqh_last"];
first [label = " 2| tqe_next | tqe_prev"];
second [label =" 1| tqe_next | tqe_prev"];
queue_head [label = "queue_head",shape=plaintext]

head:first ->first:num[style=invis];
head ->queue_head[style=invis,constraint=false];
head:first ->first:num;
head:last ->second:next;

first:num ->second:num[style=invis,constraint=false];
first:next ->second:num;
first:prev ->head:first;

second:next ->NULL;
second:prev ->first:next;
}

解释:跟上图类似,只不过指向关系复杂一点。注意:head ->queue_head[style=invis,constraint=false];这行的目的是让queue_head在head结点的下方。

总结:这只是一个用graphviz画图的一个很简单的例子,graphviz在有很复杂的指向关系的时候,它的优势就会非常的突出,因为你不用去关心图形的拓扑细节,有了结点之间的指向关系,graphviz会自动生成相应的布局;更多内容请看下面的参考文献。


参考文献:

这里当然是最权威的文档,命令行的具体用法和图形的属性的详细信息都在这里的文档能找到;但是对于初学者来说,直接看文档可能会让你一头雾水,他们提供了一些具体的例子来学习: http://www.graphviz.org/Gallery.php

Kentbye的Flickr网络相册,这里有更多的例子,是新手入门非常好的资料;

来自icodeit的文章,这篇文章应该是国内介绍graphviz最详细的一篇文章了,强烈推荐。

  • 4.论坛

http://www.graphviz.org/forums/general-discussion

http://stackoverflow.com/

还有问题?到这两个地方问吧。

debian下安装curl loader压力工具出现crypto.h的错误

FreeBSD的编译环境跟linux差别怎么这么大,很多时候gmake编译源代码都出错,很无奈啊;最近用到一些http的测试工具,源代码安装,在FreeBSD上源代码安装很难成功,依赖关系残缺不全,用ports安装也不省心,果断用debian linux。
找个能支持ipv6的压力测试工具真是难啊,tsung貌似很强大,也符合要求,但是BSD7上通过cli安装tsung好麻烦,新的ports还要java的license认证,麻烦加无语啊,后来找来找去,貌似curl loader很符合要求,能做ftp和ipv6的压力测试,果断安装,但是debian上源代码编译有如下错误:

ssl_thr_lock.h:27:28: error: openssl/crypto.h: No such file or directory

本以为安装openssl就行了,但是谷歌发现,需要安装openssl-devel,debian的包名叫libssl-dev,安装之后就OK了。这种错误让新手很无语加蛋疼,权且记录下来,让需要的人少走些弯路。

Page 2 of 812345...Last »