加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

centos – 使用supervisord运行(和监控)nginx

发布时间:2020-12-13 21:26:39 所属栏目:Nginx 来源:网络整理
导读:我将从我的用例开始,因为我很可能没有使用正确的工具来完成这项工作.如果我以错误的方式解决这个问题,请告诉我 用例:我有一个托管多个网络应用的CentOS服务器.我希望能够相信我的Web服务器和应用程序服务器将会运行.我的堆栈看起来像 web服务器:nginx 应用

我将从我的用例开始,因为我很可能没有使用正确的工具来完成这项工作.如果我以错误的方式解决这个问题,请告诉我

用例:我有一个托管多个网络应用的CentOS服务器.我希望能够相信我的Web服务器和应用程序服务器将会运行.我的堆栈看起来像

> web服务器:nginx
>应用服务器:uWSGI
> web框架:flask / python

我想使用supervisord来监控nginx和uWSGI.在我的/etc/supervisor.conf中,我有

[program:nginxgo]
command = /usr/sbin/nginx
autostart=true
autorestart=unexpected
exitcodes=0
stdout_logfile=/home/webdev/nginxgo.log
stderr_logfile=/home/webdev/nginxgoerr.log

[program:uwsgi_emperor_go]
command = uwsgi --emperor /etc/uwsgi/emperor.ini
autostart=true
autorestart=unexpected
stopsignal=INT
stdout_logfile=/home/webdev/emp.log
stderr_logfile=/home/webdev/emperr.log
directory=/home/webdev/
user=webdev

我启动了uWSGI流程.当我输入[root @ mymachine]#/usr/local / bin / supervisord -n -c /etc/supervisord.conf时

输出是

2014-11-26 14:07:56,917 CRIT Supervisor running as root (no user in config file)
2014-11-26 14:07:56,951 CRIT Server 'inet_http_server' running without any HTTP authentication checking
2014-11-26 14:07:56,952 INFO supervisord started with pid 31068
2014-11-26 14:07:57,957 INFO spawned: 'nginxgo' with pid 31071
2014-11-26 14:07:57,970 INFO spawned: 'uwsgi_emperor_go' with pid 31072
2014-11-26 14:07:59,095 INFO success: nginxgo entered RUNNING state,process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:07:59,095 INFO success: uwsgi_emperor_go entered RUNNING state,process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:08:00,601 INFO exited: nginxgo (exit status 1; not expected)
2014-11-26 14:08:01,607 INFO spawned: 'nginxgo' with pid 31079
2014-11-26 14:08:02,684 INFO success: nginxgo entered RUNNING state,process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:08:04,189 INFO exited: nginxgo (exit status 1; not expected)
2014-11-26 14:08:05,194 INFO spawned: 'nginxgo' with pid 31080
2014-11-26 14:08:06,264 INFO success: nginxgo entered RUNNING state,process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:08:07,771 INFO exited: nginxgo (exit status 1; not expected)
2014-11-26 14:08:08,775 INFO spawned: 'nginxgo' with pid 31081
2014-11-26 14:08:09,808 INFO success: nginxgo entered RUNNING state,process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:08:11,314 INFO exited: nginxgo (exit status 1; not expected)
2014-11-26 14:08:12,319 INFO spawned: 'nginxgo' with pid 31082
2014-11-26 14:08:13,381 INFO success: nginxgo entered RUNNING state,process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:08:14,886 INFO exited: nginxgo (exit status 1; not expected)
^C2014-11-26 14:08:15,601 INFO spawned: 'nginxgo' with pid 31083
2014-11-26 14:08:15,603 WARN received SIGINT indicating exit request
2014-11-26 14:08:15,611 INFO waiting for nginxgo,uwsgi_emperor_go to die
2014-11-26 14:08:16,738 INFO success: nginxgo entered RUNNING state,process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:08:18,242 INFO exited: nginxgo (exit status 1; not expected)
2014-11-26 14:08:19,244 INFO waiting for uwsgi_emperor_go to die
2014-11-26 14:08:21,607 INFO stopped: uwsgi_emperor_go (exit status 0)

看看它是怎么说的

2014-11-26 14:07:59,process has stayed up for > than 1 seconds (startsecs)

但它开始只是循环nginxgo过程.我用CTRL-C杀死了supervisord实例,我在htop中看到nginx主进程和工作进程都是活动的.

我想要的是在服务器启动/重启或任一程序失败时启动nginx和我的uWSGI emperor

最佳答案
supervisord只能处理前台进程. nginx的默认值在后台作为守护进程运行.

要确保nginx与supervisord一起运行,您必须在nginx.conf中设置’daemon off'(另请参阅http://nginx.org/en/docs/ngx_core_module.html#daemon中的nginx文档).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读