您好,登录后才能下订单哦!
这篇文章主要介绍“Centos怎么搭建高性能WEB服务器”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Centos怎么搭建高性能WEB服务器”文章能帮助大家解决问题。
一、安装平台
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
二、平台配置
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
# 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; }
3、uwsgi配置
#mkdir -p /home/uwsgi;cd /home/uwsgi
#mkdir -p /opt/www/logs
#echo "" > /opt/www/logs/django.log
#vi uwsgi.xml
<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
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
#!/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]
如大家有什么疑问或感兴趣的话题可以通过weibo与我交流:http://t.qq.com/yorkoliu
以下是补充:
1、mysql-python 安装错误如下
from setuptools import setup importerror:
先安装
python ez_setup.py
在安装
python setup.py install
贴一下,方便其他兄弟了
2、我的nginx+uwsgi+django遇到大header的request,经常出现502,uwsgi报的是 invalid request header size,何解我的uwsgi配置为[uwsgi]socket = :8010master = truemodule = django_wsgiprocesses = 8home = /path/to/virtualenvharakiri = 20daemonize = /path/to/uwsgi.logpidfile = /path/to/uwsgi.pidpythonpath = /path/to/projectpythonpath = /path/to/uwsgibuffer-size = 32768reload-mercy = 8max-requests = 5000socket-timeout = 4
解决方法:大header可以修改nginx http head部分参数。
3、nginx报502,但是uwsgi正常启动端口9000也正常监听。有可能是应用程序有错误导致。
关于“Centos怎么搭建高性能WEB服务器”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。