Bywing
Recording
Recording
Mar 30th
编译keepalived-1.2.2的时候遇到几个问题,在网上找了一下得以解决,备忘。
ip_vs.h:19:31: error: netlink/genl/genl.h: No such file or directory ip_vs.h:20:31: error: netlink/genl/ctrl.h: No such file or directory
这个时候需要安装libnl:
wget http://www.infradead.org/~tgr/libnl/files/libnl-1.1.tar.gz
不要用yum install这个方式安装,libnl.i386 libnl-devel.i386这两个的版本不够高。
如果已经通过yum install libnl.i386 libnl-devel.i386, 则要把/usr/lib/下面libnl相关的库删掉,不然会出现下面的错误:
libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_timeout_parse_cb': /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:953: undefined reference to `genlmsg_parse' libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_getinfo_parse_cb': /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:141: undefined reference to `genlmsg_parse' libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_daemon_parse_cb': /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:1010: undefined reference to `genlmsg_parse' /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:1023: undefined reference to `nla_get_string' libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_dests_parse_cb': /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:714: undefined reference to `genlmsg_parse' libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_services_parse_cb': /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:554: undefined reference to `genlmsg_parse' /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:587: undefined reference to `nla_get_string' libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_nl_send_message': /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:72: undefined reference to `genl_connect' /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:75: undefined reference to `genl_ctrl_resolve' /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:86: undefined reference to `nl_socket_modify_cb' /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:92: undefined reference to `nl_recvmsgs_default' libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_nl_message': /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:49: undefined reference to `nlmsg_alloc' /other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:53: undefined reference to `genlmsg_put'
/usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’ /usr/include/linux/types.h:13: error: previous declaration of ‘dev_t’ was here ... make: *** [othptab.o] Error 1
从网上找了资料后找到解决办法,具体如下:
vim keepalived/libipvs-2.6/ip_vs.h
把#include linux/types.h /* For __beXX types in userland */
移到#include sys/types.h 这行的下面
再编译就可以通过了。
Jan 17th
正确
这是写代码必须达到,也是最基本的要求。要实现这一要求,需要对功能需求有全面的分析,对没个实现细节都做到心中有底。基本不出现什么Bug。
精简
这是这在写出正确代码的基础上对程序员提出更高的要求,即使得代码精简,没有冗余。尽量使代码显的扁平化,没有深层嵌套。及时的重构代码。
优美
优美的代码会让读代码的人觉得轻松,有继续阅读的欲望。而想写出优美的代码,不仅看程序员本身技术,更看程序员本身对自己的要求有多高。这样的代码不但完成了精简这一步骤,还需要从代码格式,变量命名等多个方面进行优化。
Jun 12th

原文地址:http://rrn.dk/http-streaming-push-comet-with-orbited
译文地址:http://www.bywing.com/?p=40

因为我工作的一个项目,我已经捣鼓HTTP streaming(也被叫作Comet)有一段时间了。我发现对我来说最好并且最容易的解决方案就是使用开源项目Orbited提供的解决方案。Orbited是一个强大的软件,让我花了好些时间阅读文档和相关的文章才真正领会它的架构。
var client = new STOMPClient();
client.connect(ip, port);
client.onmessageframe = function(frame) {
alert('The server said ' + frame.body);
};
client = Stomp::Client.open "stomp://localhost:61613"
client.send "channel_name", "My message"
May 5th
php-amqp是基于librabbitmq-c的,所以在安装php-amqp之前,先要安装librabbitmq-c。可以从http://hg.rabbitmq.com/rabbitmq-c/下载,也可以直接通过mercurial把代码下载下来。如果没有装mercurial, 可以用 sudo apt-get install mercurial 安装,然后按照下列步骤安装 librabbitmq-c:
hg clone http://hg.rabbitmq.com/rabbitmq-c cd rabbitmq-c hg clone http://hg.rabbitmq.com/rabbitmq-codegen codegen autoreconf -i ./configure make sudo make install
然后下载php-amqp的源码包。
tar xzvf amqp-0.0.7.tgz
下载补丁issue2.patch2.
patch -d amqp-0.0.7 < issue2.patch2 cd amqp-0.0.7 phpize ./configure --with-amqp make sudo make install
到这里,amqp已经安装完了,剩下就是在php.ini里加入extension=amqp.so, 然后重启。
Apr 26th
在官方提供的方法里,提供了直接从源安装的方法。不过我安装的是9.10的,即使把PPA里面加进去,也没有针对9.10的karmic的版本。所以还是需要手动修改一下,方法如下:
从源配置安装:
创建数据库:
初始化设置:
sudo mogdbsetup –dbhost=localhost –dbname=mogilefs –dbuser=mogile –dbpassword=sekrit –dbrootuser=root –dbrootpass=
参考:
InstallOnUbuntu: http://code.google.com/p/mogilefs/wiki/InstallOnUbuntu
Apr 23rd
原文地址:http://www.grid.net.ru/nginx/mogilefs.en.html (在墙外)
MogileFS client for nginx web server.
The module queries MogileFS tracker specified by mogilefs_tracker directive and uses first path returned by tracker to fetch requested file. The file key is specified by mogilefs_pass directive. If no domain or no file with specified key is found by tracker “404 Not found” status is retuned. If file is found but zero paths are returned by tracker “503 Service unavailable” status is retuned. If tracker has returned successful response the modules tries to fetch file using path with the greatest priority.
Specifies key of the file to query from MogileFS tracker. The key can contain any variables. If key is omitted, the part of request URI will be uses as key, which remains after stripping the name of mathced location.
location /download/ {
mogilefs_pass {
[...]
}
}
In this example if request URI is /download/example.jpg, the tracker will be queried for file with the key example.jpg.
The fetch block contains configuration which will be used to fetch file from storage node. In this block it is necessary to use proxy_pass directive with $mogilefs_path as an argument. Example:
mogilefs_pass {
proxy_pass $mogilefs_path;
proxy_hide_header Content-Type;
proxy_buffering off;
}
The variable $mogilefs_path contains absolute URL to the file on storage node. The fetch block creates a hidden internal location with the name /mogilefs_fetch_XXXXXXXX, where redirected will be performed after successful tracker response.
Specifies which methods will be allowed to access MogileFS. GET retrieves a resource from MogileFS, PUT creates or replaces, DELETE deletes a resource in MogileFS.
Specifies the name of MogileFS domain to query. The specification may contain variables.
This directive specifies what to use as “class” parameter when making a request to tracker. The arguments of this directives will be evaluated and first non-empty value will be used as class. Arguments can contain variables.
Specifies address of MogileFS tracker to query.
Enables sending of noverify argument to MogileFS.
Specifies a timeout to be used to connect to mogilefs tracker. Could not be longer than 75 seconds.
Specifies a timeout to be used to send data to mogilefs tracker. If no data will be received by mogilefs tracker during this time interval, nginx will close the connection.
Specifies a timeout to be used to receive data from mogilefs tracker. If no data will be send by mogilefs tracker during this time interval, nginx will close the connection.
error_log logs/error.log notice;
working_directory /usr/local/nginx;
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
#
# This location could be used to retrieve files from MogileFS.
# It is publicly available.
#
location /download/ {
#
# Query tracker at 192.168.2.2 for a file with the key
# equal to remaining part of request URI
#
mogilefs_tracker 192.168.2.2;
mogilefs_domain example_domain;
mogilefs_pass {
proxy_pass $mogilefs_path;
proxy_hide_header Content-Type;
proxy_buffering off;
}
}
#
# This location could be used to store or delete files in MogileFS.
# It may be configured to be accessable only from local network.
#
location /upload/ {
allow 192.168.2.0/24;
deny all;
mogilefs_tracker 192.168.2.2;
mogilefs_domain example_domain;
mogilefs_methods PUT DELETE;
mogilefs_pass {
proxy_pass $mogilefs_path;
proxy_hide_header Content-Type;
proxy_buffering off;
}
}
}
}
http://github.com/vkholodkov/nginx-mogilefs-module/tree/master
nginx — is a web-server, developed by Igor Sysoev.
The above-described module is an addition to nginx web-server, nevertheless they are independent products. The licence of above-described module is BSD You should have received a copy of license along with the source code. By using the materials from this site you automatically agree to the terms and conditions of this license. If you don’t agree to the terms and conditions of this license, you must immediately remove from your computer all materials downloaded from this site.
Valery Kholodkov valery+nginx@grid.net.ru
Please use address extension while composing an Email to me.
Copyright (C) 2009 Valery Kholodkov
Apr 7th
Rabbitmq Installation (Server)
homepage: http://www.rabbitmq.com/
source code from repositories: http://www.rabbitmq.com/build-server.html
rabbitmq-server releases: http://www.rabbitmq.com/releases/rabbitmq-server/v1.7.2/rabbitmq-server-1.7.2.tar.gz
tar -xzvf rabbitmq-server-1.7.2
cd rabbitmq-server-1.7.2 && make
PHP-AMQP Installation (PHP Client)
homepage: http://code.google.com/p/php-amqp/
* Download librabbitmq-c from from http://hg.rabbitmq.com/rabbitmq-c/ and extract its contents.
* Download librabbitmq-codegen from http://hg.rabbitmq.com/rabbitmq-codegen/ and extract its contents to a subdirectory in librabbitmq-c named “codegen”
* Compile and install librabbitmq using:
* autoreconf -i && ./configure && make && sudo make install
* Download and unpack the PHP extension, compile and install it using:
* phpize && ./configure –with-amqp && make && sudo make install
* Add the PHP Extension to your php.ini file:
* extension = amqp.so
amqplib Installation (Python Client)
homepage: http://code.google.com/p/py-amqplib/
* Download amqplib from http://code.google.com/p/py-amqplib/downloads/list and unpack
* python setup.py install
Jan 7th
Jan 3rd
指定字段名: 在定义字段的时候,增加参数db_column=’real_field’; 指定表名: 在model的class中,添加Meta类,在Meta类中指定表名(db_table) 例如在某个models.py文件中,有一个类叫Cat:
class Cat(models.Model):
name = models.CharField(verbose_name='猫名', max_length=32, db_column='cat_name')
class Meta:
db_table = 'tbl_cat'
verbose_name = '猫'
在上面这个Cat类里面,name是类变量,而cat_name是表里面的字段名,由db_column指定;而在Meta中有db_table指定的’tbl_cat’则是我们指定的表名。
Dec 16th
使用过很多编程语言,但一直没去深入学习如”字符集(charset)”,”编码”之类的问题,因此也常常因”乱码”、”编码(encode)”、”解码(decode)”这些问题而苦恼不堪。虽然这些问题基本都能在网上找到相应的办法,但是不能从根本上理解怎么回事,实在是不应该。所以还是决定好好补补相关的基础知识。
先来了解一下常见的字符集(charset)
还有几篇关于ASCII和中文的,应该看看:
Unicode的最初目标,是用1个16位的编码来为超过65000字符提供映射。但这还不够,它不能覆盖全部历史上的文字,也不能解决传输的问题 (implantation head-ache’s),尤其在那些基于网络的应用中。已有的软件必须做大量的工作来程序16位的数据。
因此,Unicode用一些基本的保留字符制定了三套编码方式。它们分别是UTF-8,UTF-16和UTF-32。正如名字所示,在UTF-8中,字符 是以8位序列来编码的,用一个或几个字节来表示一个字符。这种方式的最大好处,是UTF-8保留了ASCII字符的编码做为它的一部分,例如,在 UTF-8和ASCII中,“A”的编码都是0×41.
UTF-16和UTF-32分别是Unicode的16位和32位编码方式。考虑到最初的目的,通常说的Unicode就是指UTF-16。在讨论Unicode时,搞清楚哪种编码方式非常重要。
总结:不同字符集有代表的字符,有的根本不同,有些有交叉,有些是兼容的。字符集就是一个编码表,把字符编码成数字,为的就是让我们能看懂的文字、符号变成计算机能看懂的机器码。