【uWSGI】 实战之操作经验

xiaoxiao2022-06-11  54

以下是uWSGI版本为2.0以上,uwsgi的启动可以把参数加载命令行中,也可以是配置文件 .ini, .xml, .yaml 配置文件中,个人用的比较多得是 .ini 文件。下面总结下自己操作和使用经验,基本都是django部署。

启动,停止,重载 前提是在配置中制定了pid文件,这里使用 .ini配置文件, pid文件叫 uwsgi.pid. 可以在此基础上自己写个启停脚本或者系统服务脚本。

启动 uwsgi --ini uwsgi.ini重载(一般修改参数,或者修改py文件经常用到) uwsgi --reload uwsgi.pid 重启(一般系统环境变化会用到) uwsgi --stop uwsgi.pid 查看状态 前提是要配置状态文件或者端口,配置参考 文档status server 部分  这里是在 uwsgi.ini 中配置 stats=/tmp/uwsgi.status

读取uwsgi实时状态 uwsgi --connect-and-read /tmp/uwsgi.status 读取的结果是个json串,包括每个总的状态,每个work是状态,响应时间等,非常全面,也有一些开源的监控可以使用。

uwsgitop 这里有个uwsgi官方制作的实用工具 uwsgitop, 下面看下效果:

# pip install uwsgitop # uwsgitop /tmp/uwsgi.status uwsgi-2.0.9 - Mon Sep 14 11:20:44 2015 - req: 0 - RPS: 0 - lq: 0 - tx: 0 node: lzz-rmbp - cwd: /Users/liuzhizhi/erya/portal - uid: 501 - gid: 20 - masterpid: 12748  WID    %       PID     REQ     RPS     EXC     SIG     STATUS  AVG     RSS     VSZ     TX      RunT  1      0.0     12749   0       0       0       0       idle    0ms     0       0       0       0  2      0.0     12750   0       0       0       0       idle    0ms     0       0       0       0  3      0.0     12751   0       0       0       0       idle    0ms     0       0       0       0  4      0.0     12752   0       0       0       0       idle    0ms     0       0       0       0  5      0.0     12753   0       0       0       0       idle    0ms     0       0       0       0  6      0.0     12754   0       0       0       0       idle    0ms     0       0       0       0  7      0.0     12755   0       0       0       0       idle    0ms     0       0       0       0  8      0.0     12756   0       0       0       0       idle    0ms     0       0       0       0 unix socket 配置 有时候不想让反向代理走本地回环,可以使用 unix socket,来配置uwsgi和nginx。

uwsgi 配置 uwsgi.ini ... socket=/tmp/portal.sock ... nginx server块配置样例 location / {     client_max_body_size 4M;     uwsgi_pass unix:///tmp/portal.sock;     include uwsgi_params; } 测试调试经验 使用http server 在测试环境或者压力非常小的环境,直接用uwsgi http非常好使。

uwsgi.ini 配置

http=0.0.0.0:8080 py文件修改,自动加载 uwsgi.ini 加入配置

py-autoreload = 1 缓存问题 生产环境中最好不要使用使django 的 local memory cache, 这个缓存是不能够进程间共享的,而我们的部署一般是多个进程的,一般需要缓存的数据即使是小量也最好用redis或者memcached这种全局cache服务,或者自己定义的缓存服务,uwsgi 有些缓存插件可以在整个uwsgi中共享缓存。

遇到的问题 【uwsgi】 listen queue of socket (fd: 3) 错误分析 ---------------------  作者:orangleliu  来源:  原文:https://blog.csdn.net/orangleliu/article/details/48437319  版权声明:本文为博主原创文章,转载请附上博文链接!

转载请注明原文地址: https://www.6miu.com/read-4931335.html

最新回复(0)