Adding Ubuntu-GIS repository

在Ubuntu上安装GIS软件,可以添加这个PPA源:
deb http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu karmic main

导入GPG KEY
gpg –keyserver subkeys.pgp.net –recv 089EBE08314DF160
gpg –export –armor 089EBE08314DF160 | sudo apt-key add -

这个源中目前包含了最新版本的GIS软件:

  • gdal 1.6
  • grass
  • qgis

在RHEL4上搭建Python/Lighttpd/FastCGI环境

在一台赤裸裸的RHEL4上部署web.py程序,一切从几乎是从零开始。以下操作均以root用户操作。

1. 安装MySQL数据库

下载安装MySQL
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.41-linux-i686-glibc23.tar.gz/from/http://mirror.services.wisc.edu/mysql/
解压,按照INSTALL文件说明进行安装,不多赘述

2. 安装Python环境

下载Python源码

wget http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tar.bz2
解压,编译安装,不需要特殊操作。

下载Easy_install

wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg
安装
sh setuptools-0.6c11-py2.6.egg

安装相关Packages

easy_install DBUtils
easy_install flup
easy_install web.py

安装mysql-python

mysql-python包不能用easy_install安装,手动下载
wget http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3b1/MySQL-python-1.2.3b1.tar.gz?use_mirror=softlayer
加压,编辑site.cfg
指定mysql_config的路径,注意是新安装的mysql路径
mysql_config=/usr/local/mysql/bin/mysql_config
编译、安装
python setup.py build
python setup.py install

声明libmysqlclient路径
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql/lib

3. 安装服务器环境

下载安装fastcgi头文件

wget http://www.fastcgi.com/dist/fcgi.tar.gz
解压,默认编译安装

下载安装PCRE

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.00.tar.bz2
解压,默认编译安装

下载lighttpd

wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.25.tar.bz2
configure时指定–prefix=/usr/local/lighttpd
编译,安装

4. 配置

lighttpd fastcgi运行web.py程序请参考
http://www.classicning.com/blog/2009/11/lighttpd%e9%80%9a%e8%bf%87fastcgi%e8%bf%90%e8%a1%8cweb-py%e7%a8%8b%e5%ba%8f/

非常重要的几点注意:

  • 通过fastcgi运行的python脚本必须具有可执行权限, chmod u+x web/main.py
  • 重启fastcgi程序需要删除/tmp/fastcgi.socket*

任何Python程序出错、权限错误都会导致lighttpd这样的报错:
2009-11-27 18:12:02: (mod_fastcgi.c.1108) child exited with status 13 /home/admin/web/main.py
2009-11-27 18:12:02: (mod_fastcgi.c.1111) If you’re trying to run your app as a FastCGI backend, make sure you’re using the FastCGI-enabled version.
If this is PHP on Gentoo, add ‘fastcgi’ to the USE flags.
2009-11-27 18:12:02: (mod_fastcgi.c.1399) [ERROR]: spawning fcgi failed.
2009-11-27 18:12:02: (server.c.931) Configuration of plugins failed. Going down.

报错会提示fastcgi未正确安装,而实际上仅仅是程序错误或权限问题而已。

Nginx HTTP Push

前些天看到一个Nginx的Module,用来是实现Comet,今天简单试了一下功能。作者名叫Leo Ponomarev,项目地址:http://pushmodule.slact.net/

安装

Module需要在编译时加入nginx,同时下载nginx和nginx-push-module,在nginx configure时增加一个参数:
./configure –add-module=path/to/nginx_http_push_module

使用

编写一个非常基本的nginx配置文件:

events{
	worker_connections 1024;
}
http{
	server {
		listen	80;
		server_name	localhost;

		location /publish {
			set $push_channel_id $arg_id;

			push_publisher;

			push_store_messages on;
			push_message_timeout 2h;
			push_max_message_buffer_length 10;
			push_min_message_recipients 0;
		}

		location /subscribe{
			push_subscriber;

			push_subscriber_concurrency broadcast;
			set $push_channel_id $arg_id;
			default_type text/plain;
		}

	}
}

一个简单的Server定义了两个路径分别用于publish和subscribe。所有相关的配置项可以在项目主页找到解释,不作赘述。

启动nginx
nginx -c /home/sun/nginxpush/nginx-push.conf

打开一个终端访问subscribe
curl -X GET http://localhost/subscribe?id=0

可以看到HTTP请求被阻塞

打开另一个终端访问publish
curl -X POST http://localhost/publish?id=0 -d “Hello World”

此时subscriber收到字符串”Hello World” ,完成HTTP请求。

subscriber可以通过设置HTTP头来对消息进行过滤,如
curl -X POST http://localhost/publish?id=0 -d “Hello World”
curl -X GET http://localhost/subscribe?id=0 –verbose

* About to connect() to localhost port 80 (#0)
*   Trying 127.0.0.1… connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /subscribe?id=0 HTTP/1.1
> User-Agent: curl/7.19.7 (i686-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3.3
> Host: localhost
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/0.8.28
< Date: Thu, 26 Nov 2009 09:45:25 GMT
< Content-Type: application/x-www-form-urlencoded
< Content-Length: 10
< Last-Modified: Thu, 26 Nov 2009 09:44:59 GMT
< Connection: keep-alive
< Etag: 0
< Vary: If-None-Match, If-Modified-Since
<
* Connection #0 to host localhost left intact
* Closing connection #0

HelloWorld

从响应的头部可以看到Last-Modified: Thu, 26 Nov 2009 09:44:59 GMT的时间是上一次publish的时间,并且通过Vary字段提示了两个选项

  • If-None-Match
  • If-Modified-Since

RFC中对Vary头是这样解释的:

The Vary field value indicates the set of request-header fields that fully determines, while the response is fresh, whether a cache is permitted to use the response to reply to a subsequent request without revalidation.

即可以通过发送If-Modified-Since来获取指定时间之后的数据

curl -X GET -H “If-Modified-Since: Thu, 26 Nov 2009 09:44:50 GMT” http://localhost/subscribe?id=0 –verbose

这时subscribe会重新被阻塞而不是接收上次publish的数据,充分利用了HTTP的语义。

这样用push module来做Web-IM、聊天室的思路就非常清晰了:每个浏览器保持一个subscriber连接,在接收到消息后连接关闭。把消息打印出来,并根据消息响应的头部Last-Modified请求重新subscribe。

这一切没有想象的那么糟

如果还不算太晚的话,大家抬头看看木星拱月吧,一张笑脸少了一只眼睛。今年这木星和月亮已经腻味了半年了。我倒是清楚记得去年冬天这场面也出现过,那时依稀是火星跟金星,没今天这亮但总归比今天齐全。当然不能太强求完整不是。

我们班刚工作的同学除了在张江的两位都回去考研了,顺利的话60%的大家又要团聚了。我想经历过这半年的同学回去以后肯定有更深刻的体会,我们这个专业找工作阻力很多很大,有的是没办法的事情。现在我又是在旁观者的角度看别人了,冷暖自知,自己的状况,也只有大家自己心里有数。

话说,好久没有码字了,下班一路上想了不少事情,回来写起来却非常吃力,表达能力进一步退化,恶性循环。

又,发现冬天听广播很有感觉,最早听广播还是某个冬天晚上六点半左右电视坏了寻找的替代,一晃今年正好是第十年。至于为什么时间记得这么清楚,呵,因为当时的节目到现在印象还很深。话说现在很多人肯定不能想象,我还有过打热线电话中奖的经历,不过中的什么门票到最后也没用着。那会南京电台还在著名的延龄巷50号,这个难找的地方着实花了我很长时间去领奖。

再,这个月公司也十周年,不过到现在都没看出有什么特别的动静,也没什么可透露的,估计是比不了马云家的大场面的。

Exaile-DoubanCover 0.0.2

The Exaile plugin “Douban Covers” has been upgraded to 0.0.2. Now there is a new preference pane inside exaile preference dialog. This update provides you an optional choice to specify your own apikey when access douban.com open api. With an apikey, your request frequency will be raised to 40 times per minute.

Again, you can get the plugin from:
http://bitbucket.org/sunng/exailedoubancovers/downloads/

Grab source with mercurial:
hg close http://bitbucket.org/sunng/exailedoubancovers/

Also, exaile-cn has its first 0.3.0-compatible version released early today. As a part of Exaile-cn, Exaile-Doubancovers 0.0.1 has been packaged into the public release for the first time. Find the project at: http://code.google.com/p/exaile-cn/