最近对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
- #!/bin/sh
## QQ:804586747 WEIBO:http://weibo.com/careersh
- mkdir -p /data/www/to
- cd /tmp/uwsgiwebpy
- tar zxvf pcre-8.10.tar.gz
- cd pcre-8.10
- ./configure
- make && make install
- cd ../
- tar zxvf nginx-0.8.53.tar.gz
- cd nginx-0.8.53
- ./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
- make && make install
- cd ../
- tar zxvf setuptools-0.6c11.tar.gz
- cd setuptools-0.6c11
- python setup.py install
- cd ../
- tar zxvf web.py-0.37.tar.gz
- cd web.py-0.37
- python setup.py install
- cd ../
- tar zxvf uwsgi-1.4.9.tar.gz
- cd uwsgi-1.4.9
- python uwsgiconfig.py --build
- python setup.py install
- cd /tmp/mysql5.5.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
- service mysql start
- cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
- cd /tmp/uwsgiwebpy
- tar zxvf MySQL-python-1.2.3.tar.gz
- cd MySQL-python-1.2.3
- echo "mysql_config = /usr/bin/mysql_config" >>site.cfg
- python setup.py build
- python setup.py install
- 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
- server {
- listen 80;
- server_name localhost;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {
- include uwsgi_params;
- uwsgi_pass 127.0.0.1:9000;
- autoindex on;
- # root /data/www/to;
- }
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
- root /data/www/to;
- }
- location ~ .*\.(js|css)?$ {
- root /data/www/to;
- }
五、启动
- 启动nginx
- #/usr/local/nginx/sbin/nginx
- 启动uwsgi
- [root@sandy ~]# uwsgi -s 127.0.0.1:9000 -w code 如果以下语句,则表明已启动成功
- WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xd2d2500 pid: 19752 (default app)
六、测试
通过浏览器访问IP如下:
还有很多不完善,持续更新中,本来准备发布几个参考链接,却不想????,只好作罢!
QQ:804586747 WEIBO:http://weibo.com/careersh
转载于:https://blog.51cto.com/beibei2008/1158256