最近对python非常感兴趣,想通过python web实现一些运维自动化,对于这类简单的应用,webpy当然是不二之选,综合参考,选定了Nginx、uwsgi、webpy这套组合,对于python web 程序的9种部署方式,请参考神贴http://lutaf.com/141.htm,系统及相关软件版本详见如下,

# cat /etc/redhat-release
CentOS release 5.7 (Final)
# uname -a
Linux sandy 2.6.18-274.el5 #1 SMP Fri Jul 22 04:43:29 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

# rpm -qa python
python-2.4.3-44.el5

一、安装pcre、nginx、setuptools、web.py、uwsgi、MySQL、MySQL-python

 
  
  1. #!/bin/sh 
  2. ## QQ:804586747    WEIBO:http://weibo.com/careersh 
  3. mkdir -p /data/www/to
  4. cd /tmp/uwsgiwebpy 
  5. tar zxvf pcre-8.10.tar.gz  
  6. cd pcre-8.10 
  7. ./configure  
  8. make && make install 
  9. cd ../ 
  10. tar zxvf nginx-0.8.53.tar.gz  
  11. cd nginx-0.8.53 
  12. ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --user=www --group=www --with-http_realip_module --with-http_flv_module --with-http_gzip_static_module 
  13. make && make install 
  14. cd ../ 
  15.  
  16. tar zxvf setuptools-0.6c11.tar.gz  
  17. cd setuptools-0.6c11 
  18. python setup.py install 
  19. cd ../ 
  20. tar zxvf web.py-0.37.tar.gz  
  21. cd web.py-0.37 
  22. python setup.py install 
  23. cd ../ 
  24. tar zxvf uwsgi-1.4.9.tar.gz  
  25. cd uwsgi-1.4.9 
  26. python uwsgiconfig.py --build 
  27. python setup.py install 
  28.  
  29. cd /tmp/mysql5.5.30 
  30. rpm -ivh  MySQL-server-5.5.30-1.rhel5.x86_64.rpm MySQL-client-5.5.30-1.rhel5.x86_64.rpm MySQL-devel-5.5.30-1.rhel5.x86_64.rpm MySQL-shared-compat-5.5.30-1.rhel5.x86_64.rpm MySQL-shared-5.5.30-1.rhel5.x86_64.rpm 
  31. service mysql start 
  32. cp /usr/share/mysql/my-huge.cnf /etc/my.cnf 
  33. cd /tmp/uwsgiwebpy 
  34. tar zxvf MySQL-python-1.2.3.tar.gz 
  35. cd MySQL-python-1.2.3 
  36. echo "mysql_config = /usr/bin/mysql_config" >>site.cfg 
  37. python setup.py build 
  38. python setup.py install 
  39.  
  40. echo "All Over!! 

至此软件安装完毕,拷贝simple-todo应用至/data/www/to目录下

simple-todo源码已添加到附件,simple-todo原帖请见http://simple-is-better.com/news/309

二、建库,导入sql

[root@sandy ~]# mysql -u root -p
Enter password:
mysql> create database todo;

导入\simple-todo\static\sql中的todo.sql

#mysql -u root -p todo < todo.sql

三、更改应用启动文件

更改simple-todo目录下的code.py文件,修改其中的“app.run()”为application = app.wsgifunc()

并注释掉if __name__ == "__main__":

四、配置nginx

 
  
  1. server { 
  2.         listen       80; 
  3.         server_name  localhost; 
  4.  
  5.         #charset koi8-r; 
  6.  
  7.         #access_log  logs/host.access.log  main; 
  8.        location / { 
  9.         include uwsgi_params; 
  10.         uwsgi_pass 127.0.0.1:9000; 
  11.         autoindex on
  12.     #    root /data/www/to
  13.         } 
  14.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { 
  15.          root /data/www/to
  16.     location ~ .*\.(js|css)?$ { 
  17.          root /data/www/to
  18. }

 

五、启动

 
  
  1. 启动nginx 
  2. #/usr/local/nginx/sbin/nginx
  3. 启动uwsgi 
  4. [root@sandy ~]# uwsgi  -s 127.0.0.1:9000 -w  code 如果以下语句,则表明已启动成功
  5. WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xd2d2500 pid: 19752 (default app) 

六、测试

通过浏览器访问IP如下:

还有很多不完善,持续更新中,本来准备发布几个参考链接,却不想????,只好作罢!

 
  
QQ:804586747    WEIBO:http://weibo.com/careersh