在Dreamhost空间安装配置python-2.5+django-1.0环境

by 丑鑫鑫(Chouxinxin)

1 前言

2 准备工作

首先你至少应该有个在淘宝上购买的10多元一年的DreamHost合租空间,当然如果银子充裕弄一个500G+独立IP的空间更好。在DreamHost的控制面板添加一个二级域名,丑鑫鑫使用的是django.v44.cn,保存前一定要勾选中 FastCGI Support。然后就是远程连接工具,我在这里推荐Putty+WinSCP组合,

3 开始安装

3.1 升级python到2.5.2

用Putty登录到DreamHost的Shell控制台执行如下的命令:

$>mkdir opt
$>cd opt
$>mkdir packages
$>wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
$>tar -xzvf Python-2.5.2.tgz

第一步为创建 opt目录,第二步在opt目录下创建 packages目录,第三步到python官方网站下载Python-2.5.2源码发布包,第四步将发布包解压到Python-2.5.2目录下

$>./configure -prefix=$HOME/opt
$>make
$>make install

以上步骤是编译并安装Python2.5.2

$>cd $HOME
$>vi .bash_profile

编辑.bash_profile文件加入

export PATH=$HOME/opt/bin/:$PATH

将python加入到shell path中

$>source .bash_profile

刷新环境变量,确保当前执行环境使用的我们安装的最新python

3.2 安装python-Mysql

$>cd downloads
$>wget http://internap.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.2.tar.gz
$>tar xvzf MySQL-python-1.2.2.tar.gz
$>cd MySQL-python-1.2.2
$>python setup.py install

3.3 安装django-1.0

$>cd $HOME/packages
$>wget http://www.djangoproject.com/download/1.0/tarball/
$>tar -xzvf Django-1.0.tar.gz
$>cd Django-1.0
$>python setup.py install

然后,
在python交互环境下查看django的版本,以测试安装配置的准确性。

>>>import django
>>>django.VERSION
(1, 0, ‘final’)

OK,Succeed!

3.4配置FastCGI

$>cd $HOME/django
$>wget http://svn.saddi.com/py-lib/trunk/fcgi.py
$>chmod 755 fcgi.py

转到先前准备的二级域名指定的目录下,下载fcgi.py,更改其权限为755,创建名为dispatch.fcgi 文件,编辑这个文件为

#!/home/yourusername/opt/bin/python
import sys
sys.path += [‘/home/
yourusername/django_projects’]
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘django1.settings’
WSGIServer(WSGIHandler()).run()

创建.htaccess文件内容如下:

RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ – [L]
RewriteRule ^(admin_media/.*)$ – [L]
RewriteRule ^(dispatch.fcgi/.*)$ – [L]
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]

用来开启apache的mod_rewrite

最后用命令测试:

$>./dispatch.fcgi

如果返回的是一个django页面的字符串。
再通过浏览器访问http://django.v44.cn
出现的django提示

恭喜你,配置成功。

4 注意事项

一定要保证dispatch.fcgi是被我们安装的最新的python解析器所执行。否则fastcgi进程将会被DreamHost的扫描进程Kill。还有就是分发文件dispatch.fcgi必须为这个文件名否则也是一样的下场。

FastCGI: incomplete headers

5 参考资料

http://wiki.dreamhost.com/Python_FastCGI

http://jeffcroft.com/blog/2006/may/11/django-dreamhost/

http://blog.localkinegrinds.com/2007/08/20/custom-python-installation-for-django-on-dreamhost/

撰写令人感兴趣的技术文章的五个技巧 5-tips-for-writing-interesting

撰写令人感兴趣的技术文章的五个技巧


在过去的几周,我收到了很多邮件。这些邮件都是咨询我是怎样不断的写出好文章的。正如我在以前的一篇文章中说过,我为Javalobby, Test Early 写过文章,当然也包括我自己的博客.以下是一些撰写令人感兴趣的技术文章的技巧。

撰写一篇好的技术文章的确是一个挑战,它将会占用你大量的私人时间,要求你做大量的研究。而且需要你对读和写一些技术文章有相当的热情。相信我如果你不喜欢阅读,那么你也不可能写作。现在让我们来看一看这五个技巧:

1. 第一点也是最重要的一点,你所写文章的论题上你应该有有相当多的专业知识。如果你对你所要写的论题不自信,你也不要写这个文章。要确保你已经制订出所有的步骤和给你的读者相当多的信息当出错时让他们知道应该怎么办。集中在一个论题上,并确保是扼要的。包括许许多的带有清晰说明有用的样品。如果你真的想去写,但又没有线索应该在哪里开始,最好的地方的就是从你自己的博客开始写。

2. 写作风格和标题:确保你所用的语言越简单越好自从你开始写一个技术论文。这是为了让母语不是英语的人在不用来回查字,也能很好的领会你的文章。让你的论文使读者感到友好。一个容易记住的标题对于吸引读者的注意力是非常重要的。这里的意思不是说你用为了让标题引起读者注意,而让文章与标题不符。

3. 写一个粗稿:我们都在语文课上学过一篇文章应该有三部分;引言,主体,最后是结论。在你发表之前确保你自己已经读过2-3次。如果你有家庭成员或同事,请他们看一下。通常来说,两个人看总比一个人看要好,对吗?

4. 评论:确保当你的读者有任何问题时,你能尽力最快的回复给读者。这些回复往往紧随在你的文章后面。尽管这些评论不恰当。但请务必不要进入口水战。请试着礼貌的传达你的信息,如果你不能做到,那就不用回复了。

5. 资源:请提供你认为的对读者有用并能得到更多信息的链接。这些放在文章末尾或者你直接提供把链接放在文中参考过这些资料的地方。如果你参考过任何书,也将他们列出来。这会给读者一条清晰的思路去搜索更多的详细资料。

这些就是我平常写文章的一些技巧,现在你也知道这个秘密,你还在等什么呢?开始写吧,让我们继续在Javalobby上发表文章吧。

限制同一用户同一时间只能一次登录系统(Acegi ConcurrentSessionFilter)

by 丑鑫鑫

如果系统是采用acegi security,你不需要另外编写额外的代码来满足这个需求,硬生生的写个Listener,Filter去监听或者拦截session,实现这个功能不叫重造轮子,应该叫做用别人的轮子重造轮胎 😉

采用Acegi 的系统限制同一用户同一时间只能一次登录系统步骤如下:

1.改写web.xml加入如下的语句

<listener>
<listener-class>org.acegisecurity.ui.session.HttpSessionEventPublisher</listener-class>
</listener>

这个监听器用来监听session生命期的事件

2.在acegi相关的spring bean配置文件加入:

<bean id=“authenticationManager” class=“org.acegisecurity.providers.ProviderManager”>
<property name=“providers”>
<!– your providers go here –>
</property>

<property name=“sessionController”><ref bean=“concurrentSessionController”/></property>
</bean>

<bean id=“concurrentSessionController” class=“org.acegisecurity.concurrent.ConcurrentSessionControllerImpl”>

<property name=“maximumSessions”><value>1</value></property>
<property name=“sessionRegistry”><ref local=“sessionRegistry”/></property>
</bean>

<bean id=“sessionRegistry” class=“org.acegisecurity.concurrent.SessionRegistryImpl”/>

执行的过程为用户couxinxin登录到系统,在另一台机器上couxinxin这个用户又登录到系统,那么前一个用户couxinxin的Session将被后者冲掉(踢掉)

搞定Over ! 🙂

必须要使用acegi1.0.6及其以后的版本,不然会报出
java.lang.IllegalArgumentException: Authentication.getDetails() required
这是版本1.0.5的bug
描述为:

If concurrent session control is used with an authentication provider which doesn’t copy the authentication details object to the successful authentication (e.g. CasAuthenticationProvider) then the check with the concurrent session controller on whether access is allowed takes place before the copyDetails method of AbstractAuthenticationManager is called. This isn’t a problem with classes which extend AbstractUserDetailsAuthenticationProvider, as it copies the authentication details object itself.

The copyDetails method should probably be pulled down into ProviderManager and called before checkAuthenticationAllowed() is called. This will ensure that the details object is available even if the provider doesn’t set it.

It’s also not clear that we really need an AbstractAuthenticationManager at all, given how little there is in there.

参见:http://jira.springframework.org/browse/SEC-618

ps: blogger 的xml排版有点难看,呵呵

jboss jBPM SVN Repository Address

Some projects such as JBoss Web Services, JBoss ESB, and JBoss Rules use Subversion for their source code repositories. We have multiple svn repositories:

NOTE: THE URLs here are NOT YET READY for JBoss Rules, please do not use them at this time.

Anonymous Access is provided by the following url:

http://anonsvn.jboss.org/repos/

Committer Access is provided by:

https://svn.jboss.org/repos/

Note that the anonymous repository is a mirror of the committer repository that is synched every 5 minutes.

Committers will be prompted for their jboss.com id and password. There are no public and private keys for these repositories. All encryption is done via https. Each project maintains its own list of committers and there is directory level access controls in place.

Committer access requires agreement to one of the following contributor agreements:

… …

http://anonsvn.jboss.org/repos/中列出的项目里面没有jBPM,但是我们发现JBoss Portal的地址是http://anonsvn.jboss.org/repos/portal/ 通过猜测可以的到jbpm的SVN库地址为

http://anonsvn.jboss.org/repos/jbpm/

(+_+)#

解决在虚拟主机安装drupal的问题

直接安装drupal 6.4到虚拟主机会遇到当安装数据库这样步的时候,输入正确的数据库信息却不能走到下一步。而页面又重新刷新了一次,没有任何错误提示信息。

解决方法:填好数据库信息时,修改 sites/default/settings.php数据库相关的内容为真实的设置,再点击 save & continue。

自从去年11月份开始,用Google提供的方法把域名指向这个ghs.l.google.com别名方式就行不通了。。今天在网上逛。发现这样的方法:改用A记录指向这些IP居然用自定义域名可以在国内访问了。。啊哈哈哈。。

Note:

但是不能用Live Writer来写,超级郁闷 G F W 啊~~

解决thinkpad x61 热拔插网线造成的蓝屏死机问题 (0x40000080)

折腾了大半个月 0x40000080 这个错误代码,在网上放狗搜了又搜。总是的不到解决。先是怀疑是网卡驱动的问题。装了个最新的Intel 驱动,结果还是不行。唉。结果终于找到办法:
1. 右键点击桌面的网上邻居选择属性。
2然后在右键点击当前的连接选择属性可以那些协议视图中看到 TVT Packet Filter Service
删除该协议。解决了这个频繁蓝屏死机的问题。

在Intel网站找到最新的驱动程序,最后更新驱动为最新的9.12.18.0(2008.2.6)
OK, 随便怎么拔插网线都没有问题了。

今天再次总结下步骤(2008-10-11):

1.删除网络连接属性中的 TVT Packet Filter Service

2.更新网卡驱动到9.12.18.0(2008.2.6)