supervisor使用

1。yum install supervisor

2.配置文件路径   supervisor配置文件:/etc/supervisord.conf

3.配置子进程 打开supervisord.conf,最后加上这句 子进程的目录文件都在这里

[include]
files = /etc/supervisor/conf.d/*.conf 

4.配置各个子进程的文件

#项目名
[program:blog]
#脚本目录
directory=/opt/bin
#脚本执行命令
command=/usr/bin/python/opt/bin/test.py

#supervisor启动的时候是否随着同时启动,默认True
autostart=true
#当程序exit的时候,这个program不会自动重启,默认unexpected,设置子进程挂掉后自动重启的情况,有三个选项,false,unexpected和true。如果为false的时候,无论什么情况下,都不会被重新启动,如果为unexpected,只有当进程的退出码不在下面的exitcodes里面定义的
autorestart=false
#这个选项是子进程启动多少秒之后,此时状态如果是running,则我们认为启动成功了。默认值为1
startsecs=1

#脚本运行的用户身份 
user = test

#日志输出 
stderr_logfile=/tmp/blog_stderr.log 
stdout_logfile=/tmp/blog_stdout.log 
#把stderr重定向到stdout,默认 false
redirect_stderr = true
#stdout日志文件大小,默认 50MB
stdout_logfile_maxbytes = 20MB
#stdout日志文件备份数
stdout_logfile_backups = 20


[program:es_comment]
command=su -c "/data/download/elasticsearch/bin/elasticsearch" elasticsearch


stderr_logfile=/etc/supervisor/supervisor_log/es_comment.err.log
stdout_logfile=/etc/supervisor/supervisor_log/es_comment.out.log
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true

 

 

 启动supervisor   ,使用supervisor进程管理命令之前先启动supervisord,否则程序报错。

systemctl start supervisord.service     //启动supervisor并加载默认配置文件
systemctl enable supervisord.service    //将supervisor加入开机启动项

 supervisor 命令

supervisorctl status        //查看所有进程的状态
supervisorctl stop es       //停止es
supervisorctl start es      //启动es
supervisorctl restart       //重启es
supervisorctl update        //配置文件修改后使用该命令加载新的配置
supervisorctl reload        //重新启动配置中的所有程序

 查看supervisor id 并且修改supervisor 打开的文件数

[edw@palo101 ~]$ ps -e | grep supervisor
1034 ? 00:02:51 supervisord
[edw@palo101 ~]$ cat /proc/1034/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size unlimited unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 100000 100000 processes
Max open files 1024 1024 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 256980 256980 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us

发现supervisor的最大文件描述符数量为1024,doris的be操作很多都是文件操作,被supervisor管理的子进程会继承父进程的文件描述数量限制,所以这个有可能会导致be数据丢失,设置crash。

解决办法为修改supervisor的最大文件描述符数目

sudo vim /usr/lib/systemd/system/supervisord.service

在service下添加内容:

LimitCORE=infinity
LimitNOFILE=100000
LimitNPROC=100000

修改后的完整文件内容为:

[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service nss-user-lookup.target


[Service]
LimitCORE=infinity
LimitNOFILE=100000
LimitNPROC=100000

Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf

[Install]
WantedBy=multi-user.target

重新加载

systemctl daemon-reload

  systemctl restart supervisord.service

 

 

supervisord 添加配置 而 不重启所有进程

一般不是严格的环境下的时候,我们在添加了supervisord 新的配置之后,会使用 supervisorctl reload进行配置更新,但是这样一来,所有过去的进程也会重新load一次。

经过发现,我们可以使用supervisorctl reread,然后supervisorctl update,这样就会在不打扰过去配置的基础上新增我们的需求。

注意,我做测试的时候,只是单纯的cpy了一份儿tomcat.conf,里面的program name啥的都没有改,这样实际上是不会添加成功的,因为supervisor没有发现变动。

supervisorctl reread
supervisorctl update

 

posted @ 2021-06-21 09:30  今晚再打老虎  阅读(215)  评论(0编辑  收藏  举报