您好,登錄后才能下訂單哦!
今天小編給大家分享一下如何搭建高性能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]
以下是補充:
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也正常監聽。有可能是應用程序有錯誤導致。
以上就是“如何搭建高性能WEB服務器”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。