哭佛林

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

安装Supervisor

1.1    安装Python包管理工具(easy_install),安装supervisor

yum install python-setuptools

easy_install supervisor

 

说明:supervisor安装完成后会生成三个执行程序:supervisortd、supervisorctl、echo_supervisord_conf,分别是supervisor的守护进程服务(用于接收进程管理命令)、客户端(用于和守护进程通信,发送管理进程的指令)、生成初始配置文件程序

1.2    配置supervisor

1.2.1      生成supervisor的初始化配置文件

mkdir /etc/supervisor

echo_supervisord_conf > /etc/supervisor/supervisord.conf

 

1.2.2      修改配置文件

vi /etc/supervisor/supervisord.conf

 

修改内容如下:

;file=/tmp/supervisor.sock ;修改为/var/run目录,避免被系统删除
file=/var/run/supervisor.sock ; (the path to the socket file)

;logfile=/tmp/supervisord.log ;修改为/var/log目录,避免被系统删除 
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket ;取消注释、修改文件并保存 [include] files = conf.d/*.conf

 

1.2.3      修改相关文件夹的权限

sudo chmod 777 /run

sudo chmod 777 /var/log

 

1.3    配置管理进程

              说明:进程管理配置参数,不建议全都写在supervisord.conf文件中,应该每个进程写一个配置文件放在include指定的目录下包含进supervisord.conf文件中

1.3.1      创建 /etc/supervisor/conf.d目录, 用于存放进程管理的配置文件

mkdir /etc/supervisor/conf.d/

 

1.3.2      修改/etc/supervisor/supervisord.conf中的include参数,见:配置supervisor

1.3.3      应用配置,比如我们应用程序名称为:testweb

vi /etc/supervisor/conf.d/testweb.conf

 

输入代码:

[program: testweb]

command=/usr/bin/dotnet /root/web/testweb/testweb.dll

directory=/root/web/testweb

autostart=true

autorestart=true

stderr_logfile=/var/log/testweb.err.log

stdout_logfile=/var/log/testweb.out.log

environment=ASPNETCORE_ENVIRONMENT=Production

user=root

stopsignal=INT

 

1.3.4      保存并退出

1.4    启动supervisor服务

supervisord -c /etc/supervisor/supervisord.conf

 

#查看状态

supervisorctl status

 

检查到有一个应用程序在运行中,说明正常

1.5    进程管理

说明:supervisord启动成功后,可以通过supervisorctl客户端控制进程,启动、停止、重启。运行supervisorctl命令,不加参数,会进入supervisor客户端的交互终端,并会列出当前所管理的所有进程

 

 

上图中的testweb就是我们在配置文件中[program:testweb]指定的名字

1.6    bash终端控制

supervisord -c /etc/supervisor/supervisord.conf

 

       通过以下命令进行控制

    supervisorctl status

    supervisorctl stop testweb

    supervisorctl start testweb

    supervisorctl restart testweb

    supervisorctl reload

    supervisorctl update

 

1.7    Web管理界面

说明:出于安全考虑,默认配置是没有开启web管理界面,需要修改supervisord.conf配置文件打开http访权限,将下面的配置修改:

 

 

此配置说明我的管理界面是开启的哦,9001端口,我们来浏览一下地址http://192.168.56.99:9001/

 

 

1.8    开机启动supervisor服务

1.8.1      首先进入/lib/systemd/system目录,并创建supervisor.service文件

vi /lib/systemd/system/supervisor.service

 

输入代码如下:

[Unit]

Description=supervisor

After=network.target

 

[Service]

Type=forking

ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf

ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown

ExecReload=/usr/bin/supervisorctl $OPTIONS reload

KillMode=process

Restart=on-failure

RestartSec=42s

 

[Install]

WantedBy=multi-user.target

 

保存并退出

1.8.2      修改文件权限

chmod 766 /lib/systemd/system/supervisor.service

 

1.8.3      设置开机启动

systemctl enable supervisor.service

systemctl daemon-reload

 

1.9    相关问题

Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting

解决方法:

find / -name supervisor.sock

unlink /tmp/supervisor.sock

 

l  Error: Cannot open an HTTP server: socket.error reported errno.EADDRNOTAVAIL (99)

此问题是开启浏览器查看产生的,后面查了好久没有解决,后面发现这台远程机器有一个内网ip还一个公网ip,而在配置中,port 用了公网ip,想了想,把port配置内网ip,然后用nginx反向代理到内网ip

l  Error: Cannot open an HTTP server: socket.error reported errno.EACCES (13)

需要为刚才创建的文件夹赋予权限:

sudo chmod 777 /run

sudo chmod 777 /var/log

 

posted on 2018-11-11 09:38  哭佛林<Kufolin>  阅读(181)  评论(0)    收藏  举报