文档章节

centos6.4 uWSGI + nginx + bottle (下)

Jackman
 Jackman
发布于 2014/09/14 17:11
字数 1133
阅读 61
收藏 0

配置uWSGI的服务方式启动

承接上文 centos6.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: \n"
    do_status
;;
start)
    echo -en "Starting $NAME: \n"
    do_start
;;
stop)
    echo -en "Stopping $NAME: \n"
    do_stop
;;
reload|graceful)
    echo -en "Reloading $NAME: \n"
    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_app2,纯上代码的:

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: \n"
    do_status
;;
start)
    echo -en "Starting $NAME: \n"
    do_start
;;
stop)
    echo -en "Stopping $NAME: \n"
    do_stop
;;
reload|graceful)
    echo -en "Reloading $NAME: \n"
    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的可能了,再多就不行了。整体来说还算可以的。

参考


© 著作权归作者所有

Jackman
粉丝 3
博文 2
码字总数 2042
作品 0
深圳
项目经理
私信 提问
加载中

评论(1)

啦啦啦拉拉
啦啦啦拉拉
可以可以
uwsgi的工作原理,如何调用python脚本

比如说我有一个用bottle写的 a_bottle_app.py 使用uwsgi运行wsgi应用 和直接使用python解释器调用独立运行 有什么区别呢? uwsgi应该是常驻内存的,那是不是相当于每次有请求时uwsgi都去调用...

yifei_kong
2013/03/05
3.4K
0
nginx连接uwsgi使用web.py框架构造pythonweb项目

相关页面: http://webpy.org/install http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html http://projects.unbit.it/uwsgi/wiki/Example uwsgi的安装需要python-devel,可以......

跬步
2013/05/13
0
0
nginx+uwsgi+flask配置记录

nginx部分: nginx使用nginx官方yum源 详情:http://nginx.org/en/download.html nginx的配置文件: server { access_log /var/log/nginx/iday.me.access.log main; include uwsgi_params; ......

Risol
2012/08/03
0
4
Nginx+uWSGI 部署 Django 应用

常见的 webapp 部署方式采用 或 的方式部署,今天我这备忘下采用的部署方式。 目前我这博客就是采用 Nginx + uWSGI + Python + Django 构建的,部署虽没有php那样扔到目录那么方便,但是并发和...

鉴客
2011/10/26
27.1K
8
python + django + bootstrap + uWSGI + nginx 环境搭建

原文:http://www.huangdc.com/103 在了解 uWSGI 之前,我们不妨先了解一下 python http服务器? 要使 Python 写的程序能在 Web 上被访问,还需要搭建一个支持 Python 的 HTTP 服务器,列举几...

dchuang
2015/07/19
0
0

没有更多内容

加载失败,请刷新页面

加载更多

kubernetes API 访问控制在阿里云容器服务(ACK)上的实践

提起K8s API的访问控制,很多同学应该都会想到RBAC,这是K8s用来做权限控制的方法,但是K8s对API的访问控制却不止于此,今天我们就来简单介绍下K8s的访问控制以及ACK如何利用这套方法提供便捷...

zhaowei121
21分钟前
1
0
从HelloWorld看Knative Serving代码实现

概念先知 官方给出的这几个资源的关系图还是比较清晰的: 1.Service: 自动管理工作负载整个生命周期。负责创建route,configuration以及每个service更新的revision。通过Service可以指定路由流...

迷你芊宝宝
21分钟前
1
0
如何防止http请求数据被篡改

故事的开始,面试官问了我一个问题: 如何防止http请求中数据被篡改? 回答: 1.设置客户端IP黑/白名单 1.1.客户端所有请求,请求到代理服务器(nginx),代理服务器维护黑/白名单的ip,决定是...

太猪-YJ
26分钟前
1
0
好程序员大数据笔记之:Hadoop集群搭建

在学习大数据的过程中,我们接触了很多关于Hadoop的理论和操作性的知识点,尤其在近期学习的Hadoop集群的搭建问题上,小细节,小难点拼频频出现,所以,今天集中总结以下笔记,希望对各位同学...

好程序员IT
32分钟前
1
0
MySql用navcat连接时报错 2509

在8版本以后的MySql默认的加密方式都改为了caching_sha2_password 因此进入mysql的命令行更改加密方式即可 ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER......

lanyu96
34分钟前
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部