centos 6.4 uWSGI + nginx + bottle (하)

7736 단어 nginxlinuxBottleuwsgi
uWSGI 서비스 시작 설정
위의 centos 6.4 uWSGI + nginx + bottle (위) 계승 ,이 글 은 uWSGI 설정 (이전 / etc / rc. local 의 추가 script 삭제) 을 말 합 니 다.
vi /etc/uwsgi3031.ini
[uwsgi]
socket = 127.0.0.1:3031
master = true
vhost = true
no-stie = true
workers = 2
reload-mercy = 10    
vacuum = true
max-requests = 1000  
limit-as = 512
buffer-sizi = 30000
pidfile = /var/run/uwsgi3031.pid
daemonize = /var/www/test_app/uwsgi3031.log
vi /etc/init.d/uwsgi3031
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for uwsgi webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f uwsgi defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add uwsgi'
### BEGIN INIT INFO
# Provides:          uwsgi
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the uwsgi web server
# Description:       starts uwsgi using start-stop-daemon
### END INIT INFO
# Author:   licess
# website:  http://lnmp.org
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="uwsgi daemon"
NAME=uwsgi3031
DAEMON=/usr/bin/uwsgi
CONFIGFILE=/etc/$NAME.ini
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
    $DAEMON $CONFIGFILE || echo -n "uwsgi already running"
}
do_stop() {
    $DAEMON --stop $PIDFILE || echo -n "uwsgi not running"
    rm -f $PIDFILE
    echo "$DAEMON STOPED."
}
do_reload() {
    $DAEMON --reload $PIDFILE || echo -n "uwsgi can't reload"
}
do_status() {
    ps aux|grep $DAEMON
}
case "$1" in
status)
    echo -en "Status $NAME: 
" do_status ;; start) echo -en "Starting $NAME:
" do_start ;; stop) echo -en "Stopping $NAME:
" do_stop ;; reload|graceful) echo -en "Reloading $NAME:
" do_reload ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2 exit 3 ;; esac exit 0
이 디 렉 터 리 에서 실행 권한 이 있어 야 합 니 다.
chmod +x /etc/init.d/uwsgi3031
시동 서 비 스 를 설정 합 니 다.
### add service
chkconfig --add uwsgi3031
chkconfig uwsgi3031 on
마지막 으로 기 계 를 다시 켜 서 해 보 세 요!
여러 사이트 설정
위의 방법 에 따라 하나의 uWSGI 를 설정 합 니 다. 포트 가 다 를 뿐 입 니 다. 그리고 nginx 의 프로필 에 해당 하 는 server 노드 를 추가 하면 됩 니 다. 제 가 다음 에 예 를 들 어 이전 코드 를 test 라 는 이름 으로 복사 하 겠 습 니 다.app 2, 순수한 코드 의:
vi /etc/uwsgi9099.ini
[uwsgi]
socket = 127.0.0.1:9099
master = true
vhost = true
no-stie = true
workers = 2
reload-mercy = 10    
vacuum = true
max-requests = 1000  
limit-as = 512
buffer-sizi = 30000
pidfile = /var/run/uwsgi9099.pid
daemonize = /var/www/test_app2/uwsgi9099.log
vi /etc/init.d/uwsgi9099
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for uwsgi webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f uwsgi defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add uwsgi'
### BEGIN INIT INFO
# Provides:          uwsgi
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the uwsgi web server
# Description:       starts uwsgi using start-stop-daemon
### END INIT INFO
# Author:   licess
# website:  http://lnmp.org
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="uwsgi daemon"
NAME=uwsgi9099
DAEMON=/usr/bin/uwsgi
CONFIGFILE=/etc/$NAME.ini
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
    $DAEMON $CONFIGFILE || echo -n "uwsgi already running"
}
do_stop() {
    $DAEMON --stop $PIDFILE || echo -n "uwsgi not running"
    rm -f $PIDFILE
    echo "$DAEMON STOPED."
}
do_reload() {
    $DAEMON --reload $PIDFILE || echo -n "uwsgi can't reload"
}
do_status() {
    ps aux|grep $DAEMON
}
case "$1" in
status)
    echo -en "Status $NAME: 
" do_status ;; start) echo -en "Starting $NAME:
" do_start ;; stop) echo -en "Stopping $NAME:
" do_stop ;; reload|graceful) echo -en "Reloading $NAME:
" do_reload ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2 exit 3 ;; esac exit 0
chmod +x /etc/init.d/uwsgi9099
vi /etc/nginx/conf.d/default.conf
## add one more server node, append this
server {
    listen       9999;
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
    location / {
       include uwsgi_params;
       uwsgi_param UWSGI_PYHOME /var/www/test_app2;
       uwsgi_param UWSGI_CHDIR /var/www/test_app2;
       uwsgi_param UWSGI_SCRIPT app;
       uwsgi_pass 127.0.0.1:9099;
       # root   /usr/share/nginx/html;
       # index  index.html index.htm;
    }
}

In the terminal:
##  add it to the service
chkconfig --add uwsgi9099
chkconfig uwsgi9099 on
## start the service
service uwsgi9099 start
## restart the nginx
service nginx restart
## you can try it out with curl or browser
curl http://127.0.0.1:9999/

간단 한 성능 테스트
우 리 는 Apache 의 ab command line 을 사용 합 니 다. ab 는 linux / unix 에서 기본적으로 설치 되 어 있 습 니 다. 바로 사용 할 수 있 습 니 다. windows 시스템 은 따로 설치 해 야 합 니 다.다음은 바로 간단 한 스트레스 테스트!
#------------------------------------------------
#memory : 1024 MB
#cpu: Intel Core x 1
#     10000   ,10   (        10      )
#------------------------------------------------
$ ab -c 10 -n 10000 http://192.168.1.99/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.1.99 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software:        nginx/1.4.4
Server Hostname:        192.168.1.99
Server Port:            80
Document Path:          /
Document Length:        21 bytes
Concurrency Level:      10
Time taken for tests:   10.711 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      1770000 bytes
HTML transferred:       210000 bytes
Requests per second:    933.61 [#/sec] (mean)
Time per request:       10.711 [ms] (mean)
Time per request:       1.071 [ms] (mean, across all concurrent requests)
Transfer rate:          161.38 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  33.1      0    1103
Processing:     1    9  17.8      9     564
Waiting:        1    9  17.8      9     564
Total:          1   11  37.5     10    1115
Percentage of the requests served within a certain time (ms)
  50%     10
  66%     10
  75%     10
  80%     10
  90%     11
  95%     11
  98%     12
  99%     13
100%   1115 (longest request)

랜 내 80% 의 요청 은 10 밀리초 안에 응답 할 수 있 습 니 다. 가상 기계 설정 이 비교적 낮 습 니 다. (제 컴퓨터 도 3 년 전에 어 쩔 수 없 었 습 니 다) 모두 10000 개의 요청 이 괜 찮 았 습 니 다. 20000 이면 비교적 강하 지 않 습 니 다. fail 의 가능성 이 있 습 니 다. 더 많 으 면 안 됩 니 다.전체적으로 그런대로 괜 찮 은 편 이다.
레 퍼 런 스
  • CentOS + nginx + uwsgi + Python 다 중 사이트 환경 구축
  • 좋은 웹페이지 즐겨찾기