supervisor安装及使用(转载)

Supervisor是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意外被杀死,supervisort监听到进程死后,会自动将它重新拉起,很方便的做到进程自动恢复的功能,不再需要自己写shell脚本来控制。
1、安装
yum install -y supervisor

安装好后在/etc/会生成一个supervisord.conf文件及一个supervisord.d文件目录

2、查看supervisor是否安装成功

supervisord --version

3、启动

supervisord -c /etc/supervisord.conf

4、查看supervisor是否启动成功

ps -ef|grep supervisord

5、设置supervisor 开机启动

systemctl enable supervisord

检查是否是开机启动

systemctl is-enabled supervisord

6、启动服务

systemctl start supervisord

启动时可能回报错:Another program is already listening on a port that one of our HTTP servers is config...rvisord.

 解决方案:

执行命令 find / -name supervisor.sock  然后 unlink /路径/supervisor.sock 最后再执行启动命令 systemctl start supervisord 

7、查看状态

systemctl status supervisord.service

8、配置supervisor ,web管理页面

修改配置信息,supervisor 默认配置文件,放在 /etc/supervisord.conf 路径中:

复制代码
[inet_http_server]         ; HTTP 服务器,提供 web 管理界面
port=*:9001                ; Web 管理后台运行的 IP 和端口
username=user              ; 登录管理后台的用户名
password=1234               ; 登录管理后台的密码

 [include]                     
 files = supervisord.d/*.ini ;配置文件夹

复制代码

修改完之后重启:

supervisorctl reload

然后通过http://ip:9001/访问web界面,账户名密码就是你配置的,效果如下:

 

如果外网无法访问的话

创建配置文件

创建一个.ini文件,放在目录supervisord.d下

复制代码
[program:demo] ;程序名称
command=dotnet demo.dll ; 运行命令
directory=/web/publish;目录
environment=ASPNETCORE_ENVIRONMENT=Production;环境变量
user=root;用户
stopsignal=INT
autostart=true;如果是true的话,子进程将在supervisord启动后被自动启动
autorestart=true;进程死掉后自动重启的情况
stderr_logfile=/var/log/demo/demo.err.log;错误日志文件
stdout_logfile=/var/log/demo/demo.out.log;输出日志文件
复制代码

 重启

systemctl restart supervisord

查看是否生效

supervisorctl status

然后把Xshell关了,浏览器中输入:http://ip:8080/api/values,也能看到以下页面:

supervisorctl 常用命令

查看任务状态:supervisorctl status

启动任务:supervisorctl start <name>

停止任务:supervisorctl stop <name>

重启任务:supervisorctl restart <name>

清除日志文件:supervisorctl  clear <name>

清除多个日志文件:supervisorctl  clear <name> <name> 

清除所有日志文件:supervisorctl  clear all 

移除任务:supervisorctl  remove <name>

Nginx代理配置

安裝nginx:Linux - CentOS 7 通过Yum源安装 Nginx 

修改nginx.conf

添加一个服务

复制代码
  server {
     listen       80;
     server_name  47.106.98.252;

    location / {
          root   html;
          index  index.html index.htm;
          proxy_pass http://localhost:8080;
    }
 }
复制代码

检查配置文件是否成功

nginx -t

 成功之后重启Nginx服务

systemctl restart nginx.service

测试

浏览器输入http://ip:/api/values,效果是一样的:

个人补充:

常见错误及处理

1、Error: not a valid boolean value: 'true #\xe6\x98\xaf\xe5\x90\xa6\xe8\x87\xaa\xe5\x90\xaf\xe5\x8a\xa8'

 删除掉配置文件中的注释即可(.ini文件中的注释)

yum install -y supervisor

安装好后在/etc/会生成一个supervisord.conf文件及一个supervisord.d文件目录

2、查看supervisor是否安装成功

supervisord --version

3、启动

supervisord -c /etc/supervisord.conf

4、查看supervisor是否启动成功

ps -ef|grep supervisord

5、设置supervisor 开机启动

systemctl enable supervisord

检查是否是开机启动

systemctl is-enabled supervisord

6、启动服务

systemctl start supervisord

启动时可能回报错:Another program is already listening on a port that one of our HTTP servers is config...rvisord.

 解决方案:

执行命令 find / -name supervisor.sock  然后 unlink /路径/supervisor.sock 最后再执行启动命令 systemctl start supervisord 

7、查看状态

systemctl status supervisord.service

8、配置supervisor ,web管理页面

修改配置信息,supervisor 默认配置文件,放在 /etc/supervisord.conf 路径中:

复制代码
[inet_http_server]         ; HTTP 服务器,提供 web 管理界面
port=*:9001                ; Web 管理后台运行的 IP 和端口
username=user              ; 登录管理后台的用户名
password=1234               ; 登录管理后台的密码

 [include]                     
 files = supervisord.d/*.ini ;配置文件夹

复制代码

修改完之后重启:

supervisorctl reload

然后通过http://ip:9001/访问web界面,账户名密码就是你配置的,效果如下:

 

如果外网无法访问的话

创建配置文件

创建一个.ini文件,放在目录supervisord.d下

复制代码
[program:demo] ;程序名称
command=dotnet demo.dll ; 运行命令
directory=/web/publish;目录
environment=ASPNETCORE_ENVIRONMENT=Production;环境变量
user=root;用户
stopsignal=INT
autostart=true;如果是true的话,子进程将在supervisord启动后被自动启动
autorestart=true;进程死掉后自动重启的情况
stderr_logfile=/var/log/demo/demo.err.log;错误日志文件
stdout_logfile=/var/log/demo/demo.out.log;输出日志文件
复制代码

 重启

systemctl restart supervisord

查看是否生效

supervisorctl status

然后把Xshell关了,浏览器中输入:http://ip:8080/api/values,也能看到以下页面:

supervisorctl 常用命令

查看任务状态:supervisorctl status

启动任务:supervisorctl start <name>

停止任务:supervisorctl stop <name>

重启任务:supervisorctl restart <name>

清除日志文件:supervisorctl  clear <name>

清除多个日志文件:supervisorctl  clear <name> <name> 

清除所有日志文件:supervisorctl  clear all 

移除任务:supervisorctl  remove <name>

Nginx代理配置

安裝nginx:Linux - CentOS 7 通过Yum源安装 Nginx 

修改nginx.conf

添加一个服务

复制代码
  server {
     listen       80;
     server_name  47.106.98.252;

    location / {
          root   html;
          index  index.html index.htm;
          proxy_pass http://localhost:8080;
    }
 }
复制代码

检查配置文件是否成功

nginx -t

 成功之后重启Nginx服务

systemctl restart nginx.service

测试

浏览器输入http://ip:/api/values,效果是一样的:

个人补充:

常见错误及处理

1、Error: not a valid boolean value: 'true #\xe6\x98\xaf\xe5\x90\xa6\xe8\x87\xaa\xe5\x90\xaf\xe5\x8a\xa8'

 删除掉配置文件中的注释即可(.ini文件中的注释)

猜你喜欢

转载自www.cnblogs.com/wanggang2016/p/12320560.html
今日推荐