随笔 - 120  文章 - 0  评论 - 35  阅读 - 85万

supervisor初试

Supervisor (http://supervisord.org) 是一个用 Python 写的进程管理工具,可以很方便的用来启动、重启、关闭进程(不仅仅是 Python 进程)。除了对单个进程的控制,还可以同时启动、关闭多个进程,比如很不幸的服务器出问题导致所有应用程序都被杀死,此时可以用 supervisor 同时启动所有应用程序而不是一个一个地敲命令启动。

安装:

1、首先配置epel源,这里省略

2、安装

yum install python-pip
pip install supervisor

上步骤可能遇到报错:

pkg_resources.DistributionNotFound: meld3>=0.6.5

解决办法:

1. git clone https://github.com/Supervisor/meld3
2. cd meld3
3. python setup.py install

安装完成后,做如下操作:

生成默认配置文件:
# echo_supervisord_conf > /etc/supervisord.conf
 
简单的为nginx和weblogic服务配置,在上面生成的配置文件末尾添加:
复制代码
[program:weblogic]
directory = /home/weblogic/Oracle/Middleware/user_projects/domains/base_domain
command = sh startWebLogic.sh(记得weblogic的服务不要&,不要指定后台运行)
user = weblogic
startsecs = 90
autorestart = true
autostart = true
stdout_logfile = /var/log/weblogic_stdout.log

[program:nginx]
command = /usr/sbin/nginx -c /etc/nginx/nginx.conf(配置nginx服务不要使用后台daemon运行:daemon  off;添加到nginx配置文件中)
startsecs = 90
autorestart = true
autostart = true
stdout_logfile = /var/log/nginx_stdout.log
复制代码

开启supervisor服务:

# /usr/bin/supervisord -c /etc/supervisord.conf

查看该服务日志:

复制代码
[root@weblogic etc]# tail -f /tmp/supervisord.log                 
2017-12-12 15:33:02,868 CRIT Supervisor running as root (no user in config file)
2017-12-12 15:33:02,878 INFO RPC interface 'supervisor' initialized
2017-12-12 15:33:02,878 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2017-12-12 15:33:02,880 INFO daemonizing the supervisord process
2017-12-12 15:33:02,880 INFO supervisord started with pid 5173
2017-12-12 15:33:03,887 INFO spawned: 'nginx' with pid 5174
2017-12-12 15:33:03,897 INFO spawned: 'weblogic' with pid 5175
2017-12-12 15:34:34,389 INFO success: nginx entered RUNNING state, process has stayed up for > than 90 seconds (startsecs)
2017-12-12 15:34:34,389 INFO success: weblogic entered RUNNING state, process has stayed up for > than 90 seconds (startsecs)
复制代码

查看服务运行情况:

复制代码
[root@weblogic ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      5174/nginx          
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1165/sshd           
tcp        0      0 :::80                       :::*                        LISTEN      5174/nginx          
tcp        0      0 :::22                       :::*                        LISTEN      1165/sshd           
tcp        0      0 ::ffff:127.0.0.1:7001       :::*                        LISTEN      5232/java           
tcp        0      0 fe80::20c:29ff:fe3b:78:7001 :::*                        LISTEN      5232/java           
tcp        0      0 ::ffff:192.168.101.16:7001  :::*                        LISTEN      5232/java           
tcp        0      0 ::1:7001                    :::*                        LISTEN      5232/java           
tcp        0      0 :::7005                     :::*                        LISTEN      5232/java           
udp        0      0 :::1161                     :::*                                    5232/java
复制代码

 

附加:上面配置文件的一些参数信息:

复制代码
[program:usercenter]
directory = /home/leon/projects/usercenter ; 程序的启动目录
command = gunicorn -c gunicorn.py wsgi:app  ; 启动命令,可以看出与手动在命令行启动的命令是一样的
autostart = true     ; 在 supervisord 启动的时候也自动启动
startsecs = 5        ; 启动 5 秒后没有异常退出,就当作已经正常启动了
autorestart = true   ; 程序异常退出后自动重启
startretries = 3     ; 启动失败自动重试次数,默认是 3
user = leon          ; 用哪个用户启动
redirect_stderr = true  ; 把 stderr 重定向到 stdout,默认 false
stdout_logfile_maxbytes = 20MB  ; stdout 日志文件大小,默认 50MB
stdout_logfile_backups = 20     ; stdout 日志文件备份数
; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件)
stdout_logfile = /data/logs/usercenter_stdout.log
 
; 可以通过 environment 来添加需要的环境变量,一种常见的用法是修改 PYTHONPATH
; environment=PYTHONPATH=$PYTHONPATH:/path/to/somewhere
复制代码

 

posted on   wadeson  阅读(1552)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示