CentOS 7 配置 Supervisor

in #cn6 years ago

Supervisor 的文档地址:http://www.supervisord.org/

1. 安装 Supervisor

yum install supervisor

安装完成,如下图:

QQ截图20180821162222.png

2. 配置 Supervisor

Supervisor 的配置文件为:/etc/supervisord.conf ,Supervisor 所管理的应用的配置文件放在 /etc/supervisord.d/ 目录中,这个目录可以在 supervisord.conf 中配置。

QQ截图20180821233818.png

启动 Supervisor
supervisord -c /etc/supervisor.conf

通过这种方式启动,服务器重启后 Supervisor 不会自动启动,不建议使用这种方式启动Supervisor。

安装 Supervisor 后,在 /usr/lib/systemd/system/ 目录中会有一个 supervisord.service 文件,内容如下:

QQ截图20180822000509.png

如果没有,在该目录中创建一个,用下面的内容替换:

# supervisord service for sysstemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon

[Service]
Type=forking
ExecStart=/usr/bin/supervisord
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
启用开机启动
systemctl enable supervisord.service
启动Supervisor
systemctl start supervisord.service
查看Supervisor状态
systemctl status supervisord.service

QQ截图20180822001155.png

3. 应用配置

Supervisor 管理应用的进程,需要对每个应用进行配置。在 /etc/supervisor.d 中创建 helloworld.ini,每个应用对应一个配置文件即可。

下面是配置文件的示例:

[program:helloworld]  ;程序的名称
command = dotnet HelloWorld.dll ;执行的命令
directory = /root/www/ ;命令执行的目录
environment = ASPNETCORE__ENVIRONMENT=Production  ;环境变量
user = root  ;执行进程的用户
stopsignal = INT  
autostart = true  ;是否自动启动
autorestart = true  ;是否自动重启
startsecs = 1  ;自动重启间隔
stderr_logfile = /var/log/helloworld.err.log  ;标准错误日志
stdout_logfile = /var/log/helloworld.out.log  ;标准输出日志

创建好配置文件后,重启 Supervisor

supervisorctl reload

为确保没有错误,可以正常启动,使用前文提到的查看Supervisor状态的命令查看。或者查看要管理的进程是否启动,本例中可以使用下面的命令:

ps -ef | grep HelloWorld.dll

或
ps -ef | grep dotnet

4. Supervisor 管理进程

有两种方式可以管理进程,命令行和UI界面。

命令行
supervisorctl shutdown #关闭所有任务

supervisorctl stop|start program_name

supervisorctl status #查看所有任务状态
UI界面

启用 UI 管理,首先将 /etc/supervisord.conf 配置文件中的 inet_http_server 节点取消注释。

QQ截图20180822151437.png

修改后重启 Supervisor

supervisorctl reload

在浏览器中打开地址,如下图所示。

QQ截图20180822150704.png

Sort:  

Congratulations @bitming! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:
SteemitBoard and the Veterans on Steemit - The First Community Badge.

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @bitming! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.18
TRX 0.14
JST 0.029
BTC 58051.31
ETH 3136.86
USDT 1.00
SBD 2.44