环境:CentOS5.5+Nginx1.0+Python2.6.2+uwsgi0.9.7.7
1、升级Python 系统自带的Python版本是2.4,我们需要升级到2.6.1,官网号称是被屏蔽了,所以我们需要到网上搜索一个。
下载文件: http://download.huihoo.com/python/Python-2.6.1.tar.bz2 解压: tar -jxvf Python-2.6.1.tar.bz2
编译: cd cd Python-2.6.1 ./configure make make install
自此,python2.6安装后路径默认是在/usr/local/lib/python2.6,查看Python版本:
/usr/local/bin/python2.6 -V
建立软连接,使系统默认的python指向python2.6 正常情况下即使python2.6安装成功后,系统默认指向的python仍然是2.4.3版本,所以我们需要做一个软连接
mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/bin/python2.6 /usr/bin/python
检验python指向是否成功 python -V
解决系统python软链接指向python2.6版本后,yum不能正常工作 vi /usr/bin/yum 将文本编辑显示的#/usr/bin/python修改为#/usr/bin/python2.4,保存修改即可
2、安装uwsgi 目前最新的版本是0.9.7.2
下载文件: wget http://projects.unbit.it/downloads/uwsgi-0.9.7.2.tar.gz
uwsgi需要用到libxml2,系统自带的版本无法使用,我们需要升级到libxml2-2.6.26 yum -y install libxml2*
编译: tar -zxvf uwsgi-0.9.7.2.tar.gz cd uwsgi-0.9.7.2 make -f Makefile.Py26 #使用针对Python2.6的配置文件
编译完成后,目录下会生成可扫行文件 uwsgi,这样编译就算成功了。 我们可以将文件拷到/usr/bin目录,方便使用 mv uwsgi /usr/bin
参考地址:http://projects.unbit.it/uwsgi/wiki/Install
3、安装Nginx
下载文件: wget http://nginx.org/download/nginx-1.0.0.tar.gz
Nginx编译需要pcre和openssl的支持,需要先安装下: yum -y install pcre-devel openssl openssl-devel
编译: ./configure --prefix=/usr/local/nginx make make instal
4、启动uswgi服务
编写一个简单的wsgi程序,myapp.my def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) yield 'Hello World\n'
运行uwsgi uwsgi -s 127.0.0.1:3031 -w myapp
正常情况下,会出现提示信息: *** Starting uWSGI 0.9.7.2 (32bit) on [Wed Apr 27 10:56:49 2011] *** compiled with version: 4.1.2 20080704 (Red Hat 4.1.2-50) on 27 April 2011 06:40:07 uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** *** WARNING: you are running uWSGI without its master process manager *** your memory page size is 4096 bytes uwsgi socket 0 bound to TCP address 127.0.0.1:3031 fd 3 Python version: 2.6.1 (r261:67515, Apr 27 2011, 06:29:38) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] Python main interpreter initialized at 0x883ed30 your server socket listen backlog is limited to 100 connections *** Operational MODE: single process *** WSGI application 0 (SCRIPT_NAME=) ready on interpreter 0x883ed30 (default app) *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 1208, cores: 1)
参考地址:http://projects.unbit.it/uwsgi/wiki/Doc095
5、配置并启动Nginx 编辑Nginx配置文件 vim /usr/local/nginx/conf/nginx.conf
加入: location / {
uwsgi_pass 127.0.0.1:3031; include uwsgi_params; 在本机3031端口监听。
在浏览器里输入http://localhost 将提示如下信息: Hello World 说明平台已经OK了
|