1.安装meld
wget https://pypi.python.org/packages/45/a0/317c6422b26c12fe0161e936fc35f36552069ba8e6f7ecbd99bbffe32a5f/meld3-1.0.2.tar.gz#md5=3ccc78cd79cffd63a751ad7684c02c91 tar -zxvf meld3-1.0.2.tar.gz cd meld3-1.0.2 python setup.py install
2.安装supervisor
wget https://pypi.python.org/packages/31/7e/788fc6566211e77c395ea272058eb71299c65cc5e55b6214d479c6c2ec9a/supervisor-3.3.3.tar.gz#md5=0fe86dfec4e5c5d98324d24c4cf944bd tar -zxvf supervisor-3.3.3.tar.gz cd supervisor-3.3.3 python setup.py install
3.配置supervisor
a.创建文件夹和配置文件
代码语言:javascript复制mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf
b.修改/etc/supervisor/supervisord.conf文件内容
在文件结尾[include]节点处
把;files = relative/directory/*.ini
改为files = /etc/supervisor/conf.d/*.ini
c.执行supervisorctl reload命令使配置文件生效。
出现报错:error:<class 'socket.error'>, [Errno 2]No such file or directtory: file: /usr/lib64/python2.7/socket.py line:224
解决方法使用下面命令启动
/usr/bin/python2 /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
然后再执行命令:supervisorctl reload
d.在/etc/supervisor/下创建conf.d文件夹,及ProjectName.conf(以项目名称命名的)
e.打开ProjectName.conf文件,添加内容如下:
代码语言:javascript复制[program: ProjectName]
command=dotnet ProjectName.dll ; 运行程序的命令
directory=/root/Publishing/PublishOutput/ ; 命令执行的目录
autorestart=true ; 程序意外退出是否自动重启
autostart=true ; 是否自动启动
stderr_logfile=/var/log/ProjectName.err.log ; 错误日志文件
stdout_logfile=/var/log/ProjectName.out.log ; 输出日志文件
environment=ASPNETCORE_ENVIRONMENT=Production ; 进程环境变量
user=root ; 进程执行的用户身份
stopsignal=INT
startsecs=1 ; 自动重启间隔
*.ini的配置
代码语言:javascript复制[program:kafkaRedis]
process_name=%(program_name)s_%(process_num)02d
command= xxx
directory=/etc/supervisor/daemon
autostart=true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile=/etc/supervisor/logs/kafkaRedis.log
保存并退出
3、 运行supervisord,查看是否生效,执行以下命令:
代码语言:javascript复制supervisord -c /etc/supervisor/ supervisord.conf
ps -ef | grep ProjectName
出现错误:Error: Another program is already listening on a port that one of our HTTP servers is configured to
解决办法:
find / -name supervisor.sock
unlink /xxx/supervisor.sock
#xxx=第一个命令查出来的sock路径
成功后执行命令:supervisorctl,可以看到配置的守护任务已经启动
4、 常用命令
代码语言:javascript复制sudo service supervisor stop 停止supervisor服务
sudo service supervisor start 启动supervisor服务
supervisorctl shutdown #关闭所有任务
supervisorctl stop|start program_name #启动或停止服务
supervisorctl status #查看所有任务状态
5、 配置supervisord开机启动
a.在指定目录下创建文件supervisord.service
代码语言:javascript复制vim /usr/lib/systemd/system/supervisord.service
b.输入以下内容:
代码语言:javascript复制[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
保存并退出
执行以下命令:
代码语言:javascript复制systemctl enable supervisord
提示:
代码语言:javascript复制Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
验证是否为开机启动:
代码语言:javascript复制systemctl is-enabled supervisord
提示:
enabled
表示设置成功!