Deployment¶
Isso ships with a built-in web server, which is useful for the initial setup and may be used in production for low-traffic sites (up to 20 requests per second). Running a “real” WSGI server supports nice things such as UNIX domain sockets, daemonization and solid HTTP handler. WSGI servers are more stable, secure and web-scale than the built-in web server.
gevent, coroutine-based network library
uWSGI, full-featured uWSGI server
gunicorn, Python WSGI HTTP Server for UNIX
mod_wsgi, Apache interface to WSGI
mod_fastcgi, Apache interface to FastCGI
uberspace.de, try this guide (in german)
Openshift, Isso has a one click installer
gevent¶
可能是最简单的部署方法。使用PIP安装(需要libevent):
$ pip install gevent
然后,像往常一样使用 isso
可执行文件。Gevent Monkey修补了Python的标准库以使用greenlets。
要执行Isso,只需使用命令行界面:
$ isso -c my.cfg run
uWSGI¶
Isso对uWSGI具有特殊的支持,即快速IPC缓存(fast IPC caching),作业假脱机(job spooling)和延迟作业(delayed jobs)。这是作者的选择,但不是唯一的选择。您需要uWSGI 1.9或更高版本,幸运的是,您可以从PyPi安装它:
~> apt-get install build-essential python-dev
~> pip install uwsgi
为了方便起见,我建议使用INI样式的配置(您还可以将所有内容作为命令行参数提供):
[uwsgi]
http = :8080
master = true
; set to `nproc`
processes = 4
cache2 = name=hash,items=1024,blocksize=32
; you may change this
spooler = /tmp/isso/mail
module = isso.run
; uncomment if you use a virtual environment
; virtualenv = /path/to/isso
env = ISSO_SETTINGS=/path/to/isso.cfg
然后,创建假脱机目录并通过uWSGI启动Isso:
~> mkdir /tmp/isso/mail
~> uwsgi /path/to/uwsgi.ini
gunicorn¶
Gunicorn,’Gree Unicorn’, 是一个用于Unix具有pre-fork工作模型的Python WSGI HTTP服务器,移植于Ruby的Unicorn项目。通过PIP安装 gunicorn :
$ pip install gunicorn
要执行Isso,请使用类似于以下命令:
$ export ISSO_SETTINGS="/path/to/isso.cfg"
$ gunicorn -b localhost:8080 -w 4 --preload isso.run
mod_wsgi¶
首先,创建一个名为 isso.wsgi 的启动脚本。如果Isso在您的系统模块搜索路径中,则脚本非常简单。此脚本作为 run.py 包含在isso发行版中:
from __future__ import unicode_literals
import os
from isso import make_app
from isso import dist, config
application = make_app(
config.load(
os.path.join(dist.location, dist.project_name, "defaults.ini"),
"/path/to/isso.cfg"),
multiprocessing=True)
如果在虚拟环境中安装了Isso,则必须将virtualenv的路径添加到特定于站点的Python路径中:
from __future__ import unicode_literals
import site
site.addsitedir("/path/to/isso_virtualenv")
import os
from isso import make_app
from isso import dist, config
application = make_app(
config.load(
os.path.join(dist.location, dist.project_name, "defaults.ini"),
"/path/to/isso.cfg",
multiprocessing=True)
使用上述脚本将在可用时加载系统模块,并从virtualenv加载模块。如果您想要相反的行为,即virtualenv中的模块优先于系统模块,则以下脚本可以解决问题:
from __future__ import unicode_literals
import os
import site
import sys
# Remember original sys.path.
prev_sys_path = list(sys.path)
# Add the new site-packages directory.
site.addsitedir("/path/to/isso_virtualenv")
# Reorder sys.path so new directories at the front.
new_sys_path = []
for item in list(sys.path):
if item not in prev_sys_path:
new_sys_path.append(item)
sys.path.remove(item)
sys.path[:0] = new_sys_path
from isso import make_app
from isso import dist, config
application = make_app(
config.load(
os.path.join(dist.location, dist.project_name, "defaults.ini"),
"/path/to/isso.cfg",
multiprocessing=True)
最后两个脚本基于 mod_wsgi文档 给出的。
Apache的配置将类似于以下内容:
<VirtualHost *>
ServerName example.org
WSGIDaemonProcess isso user=www-data group=www-data threads=5
WSGIScriptAlias /mounted_isso_path /path/to/isso.wsgi
</VirtualHost>
You will need to adjust the user and group according to your Apache installation and security policy. Be aware that the directory containing the comments database must be writable by the user or group running the WSGI daemon process: having a writable database only is not enough, since SQLite will need to create a lock file in the same directory.
mod_fastcgi¶
如果您的托管服务提供商不允许您运行长时间的进程,则可以使用此方法。如果尚未在服务器中配置FastCGI,请按照以下步骤操作:
注解
如果您对如何通过 mod_fastcgi 部署Python有更多的了解,那么此信息可能是错误的,请考虑扩展/更正此部分。
有关更多信息,请参见 Flask: Configuring Apache 。
LoadModule fastcgi_module /usr/lib64/httpd/modules/mod_fastcgi.so
FastCgiServer /var/www/html/yourapplication/app.fcgi -idle-timeout 300 -processes 5
<VirtualHost *>
ServerName example.org
AddHandler fastcgi-script fcgi
ScriptAlias / /var/www/isso.fcgi
<Location />
SetHandler fastcgi-script
</Location>
</VirtualHost>
接下来,要将isso作为FastCGI脚本运行,您需要使用PIP安装 flup
:
$ pip install flup
最后,复制并粘贴到 /var/www/isso.fcgi (或您喜欢的任何位置):
#!/usr/bin/env python
#: uncomment if you're using a virtualenv
# import sys
# sys.path.insert(0, '<your_local_path>/lib/python2.7/site-packages')
from isso import make_app, dist, config
import os
from flup.server.fcgi import WSGIServer
application = make_app(config.load(
os.path.join(dist.location, dist.project_name, "defaults.ini"),
"/path/to/isso.cfg"))
WSGIServer(application).run()
Openshift¶
使用 Isso Openshift Deployment Kit 只需单击一下即可将Isso安装在Open Shift上。确保您已经安装了rhc(说明:instructions )并完成设置。
运行以下命令,您将获得一个随Isso安装的Open Shift实例:
rhc create-app appname python-2.7 --from-code https://github.com/avinassh/isso-openshift.git
上面的步骤还将在当前目录中克隆Open Shift实例的Git存储库。更改配置文件并推回Openshift,它将使用新设置重新部署。
访问
http://<yourappname>-<openshift-namespace>.com/info
以验证Isso是否已正确部署并正常工作。