当前位置:七道奇文章资讯系统安全Linux安全
日期:2011-04-25 16:13:00  来源:本站整理

Centos5.4+Nginx-0.8.50+UWSGI-0.9.6.2+Django-1.2.3搭建高性能W[Linux安全]

赞助商链接



  本文“Centos5.4+Nginx-0.8.50+UWSGI-0.9.6.2+Django-1.2.3搭建高性能W[Linux安全]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

之前一向利用Nginx+Fastcgi来搭建python web服务器,本文介绍Nginx+UWSGI组合来实现.uWSGI 是一个快速的、纯C语言开辟的、自保护的、对开辟者友好的WSGI服务器,旨在供应专业的 Python web利用公布和开辟.它更符合python web的尺度协议,速度要比Fastcgi要快、性能越发安定.
1、安装平台
1、安装pcre

引用
cd /home
mkdir -p /home/install/nginx && cd /home/install/nginx
wget http://ftp.exim.llorien.org/pcre/pcre-8.00.tar.gz
tar -zxvf pcre-8.00.tar.gz
cd pcre-8.00
./configure
make && make install
cd ..

2、安装Nginx

引用
wget http://nginx.org/download/nginx-0.8.50.tar.gz
tar -zxvf nginx-0.8.50.tar.gz
cd nginx-0.8.50/
./configure –user=nobody –group=nobody –prefix=/usr/local/nginx –with-http_stub_status_module –with-cc-opt=’-O3′ –with-cpu-opt=opteron
make && make install
cd ..

3、安装python&Mysql-python

引用
wget http://www.python.org/ftp/python/2.5.1/Python-2.5.1.tgz
tar -zxvf Python-2.5.1.tgz
cd Python-2.5.1
./configure && make && make install
echo “export PATH=\$PATH:/usr/local/bin” >> /etc/profile
source /etc/profile

4、安装MySql-python

引用
cd ../
wget http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.2/MySQL-python-1.2.2.tar.gz?r=&ts=1285248455&use_mirror=nchc
cd MySQL-python-1.2.2
python setup.py install

5、安装Django

引用
wget http://www.djangoproject.com/download/1.2.3/tarball/
tar -zxvf Django-1.2.3.tar.gz
cd Django-1.2.3
python setup.py install
cd ..

6、安装uWSGI

引用
wget http://projects.unbit.it/downloads/uwsgi-0.9.6.2.tar.gz
tar -zxvf uwsgi-0.9.6.2.tar.gz
cd uwsgi-0.9.6.2
make
cp uwsgi /usr/bin

2、平台配置
1、平台环境阐明
1.1、项目位置:/opt/www/Purgesys
成立项目办法:

引用
cd /opt/www
django-admin.py startproject Purgesys

1.2、查看项目(呈现以下文件构造阐明项目已成立成功)
#tree Purgesys

引用
Purgesys
|– __init__.py
|– manage.py
|– settings.py
`– urls.py

2、Nginx相关配置
#cd /usr/local/nginx/conf
#vi django_uwsgi.conf

view plaincopy to clipboardprint?
# Django project
server {
listen 80;
server_name purgesys.domain.com;
location / {
uwsgi_pass 127.0.0.1:9000;
include uwsgi_params;
access_log off;
}
location ^~ /static {
root /opt/www/Purgesys;
}
location ^~ /admin/ {
uwsgi_pass 127.0.0.1:9000;
include uwsgi_params;
access_log off;
}
location ~* ^.+\.(mpg|avi|mp3|swf|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|txt|tar|mid|midi|wav|rtf|mpeg)$ {
root /opt/www/Purgesys/static;
access_log off;
}
}
# Django project server {         listen  80;         server_name purgesys.domain.com;           location / {             uwsgi_pass   127.0.0.1:9000;             include     uwsgi_params;             access_log  off;         }          location ^~ /static {                 root   /opt/www/Purgesys;         }          location ^~ /admin/ {             uwsgi_pass   127.0.0.1:9000;             include  uwsgi_params;             access_log   off;         }          location ~* ^.+\.(mpg|avi|mp3|swf|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|txt|tar|mid|midi|wav|rtf|mpeg)$ {             root   /opt/www/Purgesys/static;             access_log   off;         }  }
*Nginx-0.8.50默许已增添uwsgi输出头支持
include uwsgi_params;

#vi nginx.conf
追加子配置文件django_uwsgi.conf

http{
……..
include django_uwsgi.conf;
}
http{ …….. include django_uwsgi.conf; }
3、UWSGI配置
#mkdir -p /home/uwsgi;cd /home/uwsgi
#mkdir -p /opt/www/logs
#echo “” > /opt/www/logs/django.log
#vi uwsgi.xml

view plaincopy to clipboardprint?
<uwsgi>
<socket>127.0.0.1:9000</socket>
<listen>200</listen>
<master>true</master>
<pidfile>/usr/local/nginx/uwsgi.pid</pidfile>
<processes>8</processes>
<pythonpath>/opt/www/Purgesys</pythonpath>
<pythonpath>/opt/www/</pythonpath>
<module>django_wsgi</module>
<profiler>true</profiler>
<memory-report>true</memory-report>
<enable-threads>true</enable-threads>
<logdate>true</logdate>
<limit-as>6048</limit-as>
<daemonize>/opt/www/logs/django.log</daemonize>
</uwsgi>
<uwsgi>   <socket>127.0.0.1:9000</socket>   <listen>200</listen>   <master>true</master>   <pidfile>/usr/local/nginx/uwsgi.pid</pidfile>   <processes>8</processes>   <pythonpath>/opt/www/Purgesys</pythonpath>   <pythonpath>/opt/www/</pythonpath>   <module>django_wsgi</module>   <profiler>true</profiler>   <memory-report>true</memory-report>   <enable-threads>true</enable-threads>   <logdate>true</logdate>   <limit-as>6048</limit-as>   <daemonize>/opt/www/logs/django.log</daemonize> </uwsgi>
4、成立利用模块
cd /opt/www/Purgesys
vi django_wsgi.py

view plaincopy to clipboardprint?
import os
os.environ['DJANGO_SETTINGS_MODULE'] = ‘Purgesys.settings’
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
import os os.environ['DJANGO_SETTINGS_MODULE'] = ‘Purgesys.settings’ import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
5、启动服务
#/usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
#/usr/local/nginx/sbin/nginx

6、查看进程
#[liuts@webserver nginx]# ps -ef|grep uwsgi|grep -v grep

引用
root 21652 1 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21653 21652 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21654 21652 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21655 21652 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21656 21652 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21657 21652 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21658 21652 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21659 21652 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
root 21660 21652 0 17:12 ? 00:00:00 /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml

7、监听端口
#[liuts@webserver nginx]# netstat -an|grep 9000

引用
tcp 0 127.0.0.1:9000 0.0.0.0:* LISTEN

8、拜候测试
输入http://serverip/

大功告成!

*附uwsgi启动脚本
#cd /home/uwsgi
#vi uwsgiserver.sh

view plaincopy to clipboardprint?
#!/bin/bash
if [ $1 = start ];then
psid=`ps aux|grep “uwsgi”|grep -v “grep”|wc -l`
if [ $psid -gt 2 ];then
echo “uwsgi is running!”
exit 0
else
/usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
fi
echo “Start uwsgi service [OK]“
elif [ $1 = stop ];then
killall -9 uwsgi
echo “Stop uwsgi service [OK]“
elif [ $1 = restart ];then
killall -9 uwsgi
/usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml
echo “Restart uwsgi service [OK]“
else
echo “Usages: sh uwsgiserver.sh [start|stop|restart]“
fi
#!/bin/bash if [ $1 = start ];then   psid=`ps aux|grep “uwsgi”|grep -v “grep”|wc -l`   if [ $psid -gt 2 ];then     echo “uwsgi is running!”     exit 0   else     /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml   fi   echo “Start uwsgi service [OK]” elif [ $1 = stop ];then   killall -9 uwsgi   echo “Stop uwsgi service [OK]” elif [ $1 = restart ];then   killall -9 uwsgi   /usr/bin/uwsgi -x /home/uwsgi/uwsgi.xml   echo “Restart uwsgi service [OK]” else   echo “Usages: sh uwsgiserver.sh [start|stop|restart]” fi
#sh uwsgiserver.sh start
[uWSGI] parsing config file /home/uwsgi/uwsgi.xml
Start uwsgi service [OK]

http://blog.liuts.com/post/216/   以上是“Centos5.4+Nginx-0.8.50+UWSGI-0.9.6.2+Django-1.2.3搭建高性能W[Linux安全]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:

  • Windows 2008R2 HyperV下安装CentOS6,网卡无痛设置
  • CentOS 6.x 利用安装光盘作为yum源
  • CentOS 下 Nginx + Keepalived 配置高可用Web站点
  • CentOS 5.8布置web缓存服务器(squid+memcached)
  • centos6.2改正yum的源为安装光盘
  • CentOS6 yum搭建Linux+Nginx+PHP+MYSQL(LNMP)
  • CentOS 6.2 安装Nginx并设置为开机服务
  • CentOS 6.2布置DNS
  • CentOS6.2利用yum安装LAMP及phpMyadmin
  • CentOS下配置PHP+phpMyAdmin
  • centos下mysql主从同步快速设置步骤分享
  • 在Windows主机上按时备份远程VPS(CentOS)数据的批处理
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .