最新消息:20210917 已从crifan.com换到crifan.org

[记录]尝试去在CentOS中折腾uwsgi

CentOS crifan 4788浏览 0评论

折腾:

[已解决]已安装Flask的虚拟环境中无法正常运行uwsgi

期间,已经:

[整理]uwsgi作用和语法

了,然后参考:

Python/WSGI 应用快速入门 — uWSGI 2.0 文档

去折腾看看uwsgi

直到对于uwsgi有了一定了解后,

再去折腾

uwsgi+Nginx+Flask

用代码:

 uwsgi cat foobar.py 
def application(env, start_response):
    start_response(‘200 OK’, [(‘Content-Type’,’text/html’)])
    return ["Hello World"]

去运行:

 uwsgi cauwsgi –http :9090 –wsgi-file foobar.py  
*** Starting uWSGI 2.0.13.1 (64bit) on [Thu Aug 18 14:27:39 2016] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-17) on 17 August 2016 17:19:10
os: Linux-3.10.101-1.el6.elrepo.x86_64 #1 SMP Wed Mar 16 20:55:27 EDT 2016
nodename: AY140128113754462e2eZ
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /usr/share/nginx/html/uwsgi
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use –uid/–gid/–chroot options
*** WARNING: you are running uWSGI as root !!! (use the –uid flag) *** 
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 31452
your memory page size is 4096 bytes
detected max file descriptor number: 65535
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with –thunder-lock)
uWSGI http bound on :9090 fd 4
spawned uWSGI http 1 (pid: 17793)
uwsgi socket 0 bound to TCP address 127.0.0.1:43996 (port auto-assigned) fd 3
Python version: 2.7.12 (default, Aug 15 2016, 11:09:04)  [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
*** Python threads support is disabled. You can enable it with –enable-threads ***
Python main interpreter initialized at 0xaccf60
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72768 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint=”) ready in 0 seconds on interpreter 0xaccf60 pid: 17792 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 17792, cores: 1)

浏览器中去访问:

http://115.29.173.126:9090/

显示:

对应的输出log:

[pid: 17792|app: 0|req: 1/1] 58.208.66.13 () {38 vars in 677 bytes} [Thu Aug 18 14:29:57 2016] GET / => generated 11 bytes in 0 msecs (HTTP/1.1 200) 1 headers in 44 bytes (1 switches on core 0)
[pid: 17792|app: 0|req: 2/2] 58.208.66.13 () {36 vars in 605 bytes} [Thu Aug 18 14:29:57 2016] GET /favicon.ico => generated 11 bytes in 0 msecs (HTTP/1.1 200) 1 headers in 44 bytes (1 switches on core 0)

再去试试:

uwsgi –http :9090 –wsgi-file foobar.py –master –processes 4 –threads 2

 uwsgi uwsgi –http :9090 –wsgi-file foobar.py –master –processes 4 –threads 2
*** Starting uWSGI 2.0.13.1 (64bit) on [Thu Aug 18 14:30:36 2016] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-17) on 17 August 2016 17:19:10
os: Linux-3.10.101-1.el6.elrepo.x86_64 #1 SMP Wed Mar 16 20:55:27 EDT 2016
nodename: AY140128113754462e2eZ
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /usr/share/nginx/html/uwsgi
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use –uid/–gid/–chroot options
*** WARNING: you are running uWSGI as root !!! (use the –uid flag) *** 
your processes number limit is 31452
your memory page size is 4096 bytes
detected max file descriptor number: 65535
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with –thunder-lock)
uWSGI http bound on :9090 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:60289 (port auto-assigned) fd 3
Python version: 2.7.12 (default, Aug 15 2016, 11:09:04)  [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
Python main interpreter initialized at 0x21e00a0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 415360 bytes (405 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint=”) ready in 0 seconds on interpreter 0x21e00a0 pid: 17820 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 17820)
spawned uWSGI worker 1 (pid: 17821, cores: 2)
spawned uWSGI worker 2 (pid: 17822, cores: 2)
spawned uWSGI worker 3 (pid: 17823, cores: 2)
spawned uWSGI worker 4 (pid: 17824, cores: 2)
spawned uWSGI http 1 (pid: 17825)

改了下代码:

 uwsgi vi foobar.py 
def application(env, start_response):
    start_response(‘200 OK’, [(‘Content-Type’,’text/html’)])
    return ["Hello uWSGI"]

去运行:

 uwsgi uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processes 4 –threads 2 –stats 127.0.0.1:9191 &
[1] 18049
*** Starting uWSGI 2.0.13.1 (64bit) on [Thu Aug 18 14:48:46 2016] ***                                                                   
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-17) on 17 August 2016 17:19:10
os: Linux-3.10.101-1.el6.elrepo.x86_64 #1 SMP Wed Mar 16 20:55:27 EDT 2016
nodename: AY140128113754462e2eZ
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /usr/share/nginx/html/uwsgi
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use –uid/–gid/–chroot options
*** WARNING: you are running uWSGI as root !!! (use the –uid flag) *** 
your processes number limit is 31452
your memory page size is 4096 bytes
detected max file descriptor number: 65535
lock engine: pthread robust mutexes
 uwsgi thunder lock: disabled (you can enable it with –thunder-lock)
uwsgi socket 0 bound to TCP address 127.0.0.1:8080 fd 3
Python version: 2.7.12 (default, Aug 15 2016, 11:09:04)  [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
Python main interpreter initialized at 0x224d020
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 415360 bytes (405 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint=”) ready in 0 seconds on interpreter 0x224d020 pid: 18049 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 18049)
spawned uWSGI worker 1 (pid: 18054, cores: 2)
spawned uWSGI worker 2 (pid: 18055, cores: 2)
spawned uWSGI worker 3 (pid: 18056, cores: 2)
spawned uWSGI worker 4 (pid: 18057, cores: 2)
*** Stats server enabled on 127.0.0.1:9191 fd: 15 ***

然后输入:

ps aux

ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
。。。
root     18049  0.2  0.1 151220  6676 pts/0    SN   14:48   0:00 uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processe
root     18054  0.0  0.1 244164  5968 pts/0    SNl  14:48   0:00 uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processe
root     18055  0.0  0.1 244164  5968 pts/0    SNl  14:48   0:00 uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processe
root     18056  0.0  0.1 244164  5968 pts/0    SNl  14:48   0:00 uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processe
root     18057  0.0  0.1 244164  5968 pts/0    SNl  14:48   0:00 uwsgi –socket 127.0.0.1:8080 –wsgi-file foobar.py –master –processe
。。。

然后后来出现:

[已解决]运行Flask出错:socket.error Errno 98 Address already in use

再去试试,还是出错:

[已解决]Flask运行出错:socket.gaierror Errno -2 Name or service not known

然后去参考:

uWSGI — Flask Documentation (0.11)

http://flask.pocoo.org/docs/0.11/deploying/uwsgi/

用:

[已解决]运行uwsgi出错:UNABLE to load uWSGI plugin: ./python_plugin.so: cannot open shared object file: No such file or directory

[已解决]nginx出错:nginx emerg location directive is not allowed here in

[未解决]启动uWSGI后访问主页Nginx出错:502 Bad Gateway

去试试那个Gunicorn:

【已解决】Flask的gunicorn的启动任务管理supervisor

转载请注明:在路上 » [记录]尝试去在CentOS中折腾uwsgi

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
96 queries in 0.194 seconds, using 20.09MB memory