博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Centos6.3 下安装 Ngixn +tornado + supervisor
阅读量:7137 次
发布时间:2019-06-28

本文共 3724 字,大约阅读时间需要 12 分钟。

  hot3.png

tornado先天对异步(no-bolocking)处理能力,非常适合作为Web服务。tornado在linux平台使用epoll来实现异步事件的处理,性能非常好。但是python做为一个脚步语言,单进程执行,无法利用多CPU,对当今的多核CPU是一个很大的浪费。为提高性能,提高CPU利用率,一般会将tornado程序允许cup*n个。 怎样才能放便启动多个tornado程序呢,我们可以用supervisor来管理多个tornado应用。supervisor安装非常方便

easy_install supervisord

###安装Nginx

groupadd wwwuseradd -s /sbin/nologin -g www wwwmkdir -p /data/wwwrootchmod +w /data/wwwrootmkdir -p /data/wwwroot/logschmod 755 /data/wwwroot/logschown -R www:www /data/wwwrootwget http://www.nginx.org/download/nginx-1.3.11.tar.gz -P /data/soft/src/tar zxvf /data/soft/src/nginx-1.3.11.tar.gz -C /data/soft/installcd /data/soft/install/nginx-1.3.11yum install zlib pcre pcre-devel openssl./configure \    --user=www\    --group=www\    --prefix=/etc/nginx\    --sbin-path=/etc/nginx/sbin/nginx\    --conf-path=/etc/nginx/conf/nginx.conf\    --with-http_stub_status_module\    --with-http_ssl_module\    --with-pcre\    make &&  make installvim /etc/init.d/nginx

加入以下内容

#!/bin/bash## chkconfig: - 85 15# description: Nginx is a World Wide Web server.# processname: nginxnginx=/etc/nginx/sbin/nginxconf=/etc/nginx/conf/nginx.confcase $1 in       start)              echo -n "Starting Nginx"              $nginx -c $conf              echo " done"       ;;       stop)              echo -n "Stopping Nginx"              killall -9 nginx              echo " done"       ;;       test)              $nginx -t -c $conf       ;;reload)              echo -n "Reloading Nginx"              ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP              echo " done"       ;;restart)$0 stop$0 start       ;;       show)              ps -aux|grep nginx       ;;       *)              echo -n "Usage: $0 {start|restart|reload|stop|test|show}"       ;;esacchmod +x /etc/init.d/nginxchkconfig --add nginxchkconfig nginx onservice nginx startservice nginx testmv /etc/nginx/conf/nginx.conf /etc/nginx/conf/nginx.conf_bakcp /data/soft/src/nginx.conf /etc/nginx/conf/nginx.confvim /etc/nginx/conf/nginx.conf

安装tornado

yum install python-setuptoolseasy_install tornado

###安装 supervisor

easy_install supervisor

然后创建配置文件

echo_supervisord_conf > /etc/supervisord.confvim /etc/supervisord.conf

最后面加上:

[program:tornado_poll]command=python /home/wwwroot/app/app.py 80%(process_num)02d      ;要执行的命令,这里的“%(process_num)02d”会用2位精度的进程号替换,例如,第一个进程是8001,第二个进程是8002,以此类推,下同。process_name=%(program_name)s-80%(process_num)02d    							;process_name expr (default %(program_name)s)   ;启动的进程的名字,这里的名字只是supervisor内部是别用,与你所启动程序的进程名无关numprocs=4                   													; 启动几个tornado进程directory=/home/wwwroot/app 									; 运行前cd到此目录autostart=true                ; supervisord守护程序启动时自动启动tornadoautorestart=true              ; supervisord守护程序重启时自动重启tornadouser=www-data                   ; 运行程序前su到此用户redirect_stderr=true          ; 将stderr重定向到stdoutstdout_logfile=/home/wwwroot/logs/tornado-80%(process_num)02d.logstdout_logfile_maxbytes=500MBstdout_logfile_backups=50stdout_capture_maxbytes=1MBstdout_events_enabled=falseloglevel=warn

运行:

supervisordroot@vps:/tmp# supervisorctltornado_poll:tornado_poll-8000   RUNNING    pid 11352, uptime 0:29:01tornado_poll:tornado_poll-8001   RUNNING    pid 11347, uptime 0:29:02supervisor>#这里可以输入控制命令

我们可以看到,上面显示了现在正在运行的守护进程的信息,下面介绍几个常用的控制命令

stop all #停止所有进程stop tornado_poll:tornado_poll-8000 #停止运行在8000端口上的Tornado守护进程stop tornado_poll:* #停止所有Tornado守护进程supervisordsupervisorctl reload

问题:

* Starting Supervisor daemon manager...Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.For help, use /usr/bin/supervisord -h   ...fail!

解决办法:

unlink /tmp/supervisor.sock

转载于:https://my.oschina.net/liseor/blog/107186

你可能感兴趣的文章
取一种类型里面的产品销售前3甲的数据Sql
查看>>
索引初探(二)
查看>>
linux 打造man中文帮助手册
查看>>
[数分提高]2014-2015-2第6教学周第1次课讲义 3.3 Taylor 公式
查看>>
Android 最火框架XUtils之注解机制详解
查看>>
spring4.x注解概述
查看>>
Dynamic CRM 2015学习笔记(6)没有足够的权限 - 您没有访问这些记录的权限。请联系 Microsoft Dynamics CRM 管理员...
查看>>
C++序列化、反序列化
查看>>
Mysql学习笔记(七)查(补充)
查看>>
[裴礼文数学分析中的典型问题与方法习题参考解答]4.5.5
查看>>
自然科学与社会科学的区别
查看>>
访问者模式
查看>>
Hadoop: MapReduce2的几个基本示例
查看>>
javascript客户端检测技术
查看>>
16款纯CSS3实现的loading加载动画
查看>>
[工程备案]linux基本命令以及C和C++编程
查看>>
多项式回归
查看>>
HTML 5 Audio/Video DOM canplaythrough 事件在移动端遇到的坑
查看>>
react设置innerHTML
查看>>
升级_宽视野Oracle图形升级(升级后dbca建库)—10.2.0.1.0提拔10.2.0.5.0
查看>>