安装Supervisor 配置开机启动
centos安装supervisor详细教程
安装supervisor 使用yum命令安装
$ sudo su - #切换为root用户 yum install epel-release yum install -y supervisor systemctl enable supervisord # 开机自启动 systemctl start supervisord # 启动supervisord服务 systemctl status supervisord # 查看supervisord服务状态 ps -ef|grep supervisord # 查看是否存在supervisord进程
配置supervisor
supervisord 的配置文件位置:
$ vim /etc/supervisor/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/supervisor/conf.d/*.conf ; 可以是 *.conf 或 *.ini ;files = relative/directory/*.ini
配置Supervisor开机启动:
新建一个“supervisord.service”文件
# dservice for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit] Description=Supervisor daemon [Service] Type=forking ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf ExecStop=/usr/bin/supervisorctl shutdown ExecReload=/usr/bin/supervisorctl reload KillMode=process Restart=on-failure RestartSec=42s [Install] WantedBy=multi-user.target
将文件拷贝至:“/usr/lib/systemd/system/supervisord.service”
systemctl enable supervisord
验证一下是否为开机启动:systemctl is-enabled supervisord