Hzg @ 2006-03-29 08:00
http://xlp223.yculblog.com/post.1172709.html
访问网址超出本站范围,不能确定是否安全
继续访问 取消访问http://xlp223.yculblog.com/post.1172709.html
看到OneZ的blog,他说到scgi的设置中,可以进行分布式部署,他还没有试,而我对此颇感兴趣,可能熟悉web部署的人不以为然吧,呵呵。我昨晚在家用两台机子试验了一下,两台的机子ip地址:
192.168.1.10 (scgi server) <--> 192.168.1.100 (web server)。
1)在192.168.1.100中安装lighttpd,并进行scgi的设置,与以前类似,只是host有变化。
scgi.server = ("/" =>
( "127.0.0.1" =>
(
"host" => "192.168.1.10",
"port" => 5000,
"check-local" => "disable"
)))
2)然后在192.168.1.10中运行helloworld,paster serve scgi.ini
但是访问之后,总是报192.168.1.100 disallowed的错。经过查看源代码,并与OneZ交流之后,发现了其中的机关。看看源码吧,这是最好的文档注解,这也是python的优点之一。
首先找到报错的地方,在flup包scgi_base.py中释放出来的消息,
def _isClientAllowed(self, addr):
ret = self._allowedServers is None or addr[0] in self._allowedServers
if not ret:
self.logger.warning('Server connection from %s disallowed',
addr[0])
return ret
其中有个self._allowedServers,它是由BaseSCGIServer()对象的__init__()中的成员。上次提到了scgi的流程,回溯到pastescript中flup_server.py中的
def run_scgi_thread(wsgi_app, global_conf,
scriptName='', host='localhost', port='4000',
allowedServers='127.0.0.1'):
发现这里有host,port,还有allowedServers,因在.ini中有对应的host,port的设置,我们就试试设置allowedServers,
allowedServers=192.168.1.100
如果要有多个ip的话,看看后面的代码,
allowedServers=aslist(allowedServers)
aslist是from paste.deploy.converters import aslist中的函数,看完源码后,知道多个ip地址之间只要以空格分割就行,没有那么多机子来试,就弄一个算了。
哈哈,设置完之后,马上就通了。这种分布式部署,非常有意思,能够有效的分配资源。又一次体会到了paste对部署提供的方便。不过load balancing,还不知道如何来做?