阿里云CentoOS系统安装supervisor和使用gunicorn部署
一般使用配置文件目录
supervisord
负责管理进程的server端,配置文件是/etc/supervisor/supervisord.conf
supervisorctl
client端的命令行工具,管理子进程,配置文件在/etc/supervisor/supervisord.d/目录下
如果用的是阿里云的CentOS7会提示找不到supervisor,则yum install epel-release先安装EPEL源
yum install -y supervisor
开机自启动
systemctl enable supervisord
启动supervisor
systemctl start supervisord
查看启动状态
systemctl status supervisord
● supervisord.service - Process Monitoring and Control Daemon
Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-05-07 18:22:50 CST; 14s ago
Process: 49802 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=0/SUCCESS)
Main PID: 49805 (supervisord)
CGroup: /system.slice/supervisord.service
└─49805 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
May 07 18:22:50 yzsjhl-evdc1-31.opi.com systemd[1]: Starting Process Monitoring and Control Daemon...
May 07 18:22:50 yzsjhl-evdc1-31.opi.com systemd[1]: Started Process Monitoring and Control Daemon.
修改配置文件开启web界面访问,监控程序
vim /etc/supervisord.conf
把inet_http_server模块的注释去并修改IP、用户名与密码,如下
[inet_http_server]
port=0.0.0.0:9001
username=root
password=root
重新载入配置文件supervisorctl reload
开启Supervisor默认的9001端口
firewall-cmd --zone=public --add-port=9001/tcp --permanent
firewall-cmd --reload
访问web页面(我的机器ip是10.4.1.31):http://10.4.1.31:9001
查看配置文件最后一个模块
cat /etc/supervisord.conf
配置需要管理的进程也可修改为files = supervisord.d/.conf后缀,目录在/etc/supervisord.d/下面
[include]
files = supervisord.d/.conf
编辑配置文件, 启动进程, 举个例子, 前提是安装pip3安装好gunicorn
[program:rrw_idfa]
command=/data/anaconda3/envs/sanic/bin/gunicorn -c config/gunicorn_config.py index:app
process_name=%(program_name)s-8888
directory=/home/tornado/rrw_idfa/src ; 运行前cd到此目录
autostart=true ; supervisord守护程序启动时自动启动sanic
autorestart=true ; supervisord守护程序重启时自动重启sanic
user=tornado ; 运行程序前su到此用户
redirect_stderr=true ; 将stderr重定向到stdout
stdout_logfile=/home/tornado/rrw_idfa/logs/sanic_tornado_stdout.log ; 记录控制台输出的日志位置
[program:eolinker_os]
directory = /root/eolinker_os ;启动目录
command = java -jar eolinker_os-4.0.jar ;启动命令
autostart = true ;在supervisord启动的时候也启动
startsecs = 5 ;启动5秒后没有异常退出,就当作已经正常启动了
autorestart = true ;程序异常退出后自动重启
startretries = 3 ;启动失败自动重试次数,默认是3
user = root ;哪个用户启动
redirect_stderr = true ;把stderr重定向到stdout,默认false
stdout_logfile_maxbytes = 20MB ;stdout日志文件大小,默认50MB
stdout_logfile_backups = 20 ;stdout日志文件备份数
stdout_logfile = /root/eolinker_os/logs/eolinker_os_stdout.log
;stdout日志文件,需要手动创建/root/eolinker_os/logs目录
模仿一个写法其中Python37路径是,/data/anaconda3/bin/python,
/data/anaconda3/bin/pip install gunicorn
Successfully installed gunicorn-20.0.4
目录应该在/data/anaconda3/bin/gunicorn
[program:rrw_operational_uid_api]
directory=/data/rrw_tmp/rrw_operational_uid_api/src ; 运行前cd到此目录
command=/data/anaconda3/bin/gunicorn -c config/gunicorn_config.py index:app
process_name=%(program_name)s-8888
autostart=true ; supervisord守护程序启动时自动启动sanic
autorestart=true ; supervisord守护程序重启时自动重启sanic
user=tornado ; 运行程序前su到此用户
redirect_stderr=true ; 将stderr重定向到stdout
stdout_logfile=/data/rrw_tmp/rrw_operational_uid_api/logs/supervisor_operational_stdout.log ; 记录控制台输出的日志位置
启动eolinker_os进程
supervisorctl start rrw_operational_uid_api
supervisorctl常用命令
status #查看程序状态
stop name #关闭name程序
start name #启动name程序
restart name # 重启name程序
reread #读取有更新的配置文件,不会启动新添加的程序
update #重启配置文件修改过的程序
nginx配置
vim /usr/local/nginx/conf/nginx.conf
修改nginx配置文件把80端口映射到9001端口添加
location /supervisor/ {
proxy_pass http://127.0.0.1:9001/;
}
重启nginxsystemctl restart nginx
访问http://192.168.1.108/supervisor/
或者继续访问带端口的地址

浙公网安备 33010602011771号