centos安装supervisor

# yum install epel-release

# yum install -y supervisor

# systemctl enable supervisord # 开机自启动

# systemctl start supervisord # 启动supervisord服务

 

将supervisor配置为开机自启动服务

编辑服务文件

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

[Unit]
Description=Supervisor daemon

[Service]
Type=forking
PIDFile=/var/run/supervisord.pid
ExecStart=/bin/supervisord -c /etc/supervisord.conf
ExecStop=/bin/supervisorctl shutdown
ExecReload=/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

 

 

配置supervisor

supervisord 的配置文件位置:

$ vim /etc/supervisord.conf

supervisord 的配置文件

[unix_http_server]
file=/tmp/supervisor.sock   ; UNIX socket 文件,supervisorctl 会使用
;chmod=0700                 ; socket 文件的 mode,默认是 0700
;chown=nobody:nogroup       ; socket 文件的 owner,格式: uid:gid

[inet_http_server]         ; HTTP 服务器,提供 web 管理界面
port=127.0.0.1:9001        ; Web 管理后台运行的 IP 和端口,如果开放到公网,需要注意安全性
username=user              ; 登录管理后台的用户名
password=123               ; 登录管理后台的密码

[supervisord]
logfile=/tmp/supervisord.log ; 日志文件,默认是 $CWD/supervisord.log
logfile_maxbytes=50MB        ; 日志文件大小,超出会 rotate,默认 50MB
logfile_backups=10           ; 日志文件保留备份数量默认 10
loglevel=info                ; 日志级别,默认 info,其它: debug,warn,trace
pidfile=/tmp/supervisord.pid ; pid 文件
nodaemon=false               ; 是否在前台启动,默认是 false,即以 daemon 的方式启动
minfds=1024                  ; 可以打开的文件描述符的最小值,默认 1024
minprocs=200                 ; 可以打开的进程数的最小值,默认 200

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; 通过 UNIX socket 连接 supervisord,路径与 unix_http_server 部分的 file 一致
;serverurl=http://127.0.0.1:9001 ; 通过 HTTP 的方式连接 supervisord

; 包含其他的配置文件
[include]
files = /etc/supervisord.d/*.conf   ; 可以是 *.conf 或 *.ini

配置要守护的程序
vim /etc/supervisord.d/xxxxxxx.conf

[program:backend]
command=dotnet backend.dll ; 运行程序的命令
directory=/usr/local/src/backend/ ; 命令执行的目录
autorestart=true ; 程序意外退出是否自动重启
stderr_logfile=/var/log/backend.err.log ; 错误日志文件
stdout_logfile=/var/log/backend.out.log ; 输出日志文件
user=root ; 进程执行的用户身份
stopsignal=INT ; INT(类似于Ctrl+C)(kill -INT pid),退出后会将写文件或日志(推荐)

 

用supervisord web 把backend程序跑起来


posted @ 2022-05-30 18:42  小谭行天下  阅读(461)  评论(0编辑  收藏  举报