Linux 之 supervisor安装和使用

Supervisor 官网

一、介绍

Supervisor有四个组件:

1. supervisord

运行Supervisor的后台服务,它用来启动和管理那些你需要Supervisor管理的子进程,响应客户端发来的请求,重启意外退出的子进程,将子进程的stdout和stderr写入日志,响应事件等。它是Supervisor最核心的部分。

2. supervisorctl

相当于supervisord的客户端,它是一个命令行工具,用户可以通过它向supervisord服务发指令,比如查看子进程状态,启动或关闭子进程。它可以连接不同的supervisord服务,包括远程机上的服务。

3. Web服务器

这是supervisord的Web客户端,用户可以在Web页面上完成类似于supervisorctl的功能。

4. XML-RPC接口

这是留给第三方集成的接口,你的服务可以在远程调用这些XML-RPC接口来控制supervisord管理的子进程。上面的Web服务器其实也是通过这个XML-RPC接口实现的。

二、安装

1、pip 安装

	pip3 install supervisor

2、easy_install 安装:

	yum install python-setuptools
	easy_install supervisor

3、centos 安装:

	yum update
	yum install -y epel-release
	yum install -y supervisor

4、Debian/Ubuntu 安装 (我的是这个)

	apt-get install supervisor

注意,安装后配置文件生成:

1、通过easy_install或pip安装后, 没有supervisor的配置文件

	 mkdir /etc/supervisor
	 echo_supervisord_conf > /etc/supervisor/supervisord.conf

2、使用 apt-get 安装后,supervisor的主配置文件在:

	 # 主进程配置文件
	 /etc/supervisor/supervisord.conf 
	
	 # 子进程配置文件, ini or conf 均可, 只要和主进程文件配置保持一致 均可
	/etc/supervisor/conf.d/*ini  or /etc/supervisor/conf.d/*conf 
	
	# 这句执行不执行都可以,因为本身也有该文件。 下面我会附加 supervisord.conf(主进程设置)
	 echo_supervisord_conf > /etc/supervisor/supervisord.conf

/etc/supervisor/supervisord.conf 主进程配置文件

; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
;  - Shell expansion ("~" or "$HOME") is not supported.  Environment
;    variables can be expanded using this syntax: "%(ENV_HOME)s".
;  - Quotes around values are not supported, except in the case of
;    the environment= options as shown below.
;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
;  - Command will be truncated if it looks like a config file comment, e.g.
;    "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ".
;
; Warning:
;  Paths throughout this example file use /tmp because it is available on most
;  systems.  You will likely need to change these to locations more appropriate
;  for your system.  Some systems periodically delete older files in /tmp.
;  Notably, if the socket file defined in the [unix_http_server] section below
;  is deleted, supervisorctl will be unable to connect to supervisord.

[unix_http_server]
file=/var/run/supervisor.sock   ; the path to the socket file
;chmod=0700                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

; Security Warning:
;  The inet HTTP server is not enabled by default.  The inet HTTP server is
;  enabled by uncommenting the [inet_http_server] section below.  The inet
;  HTTP server is intended for use within a trusted environment only.  It
;  should only be bound to localhost or only accessible from within an
;  isolated, trusted network.  The inet HTTP server does not support any
;  form of encryption.  The inet HTTP server does not use authentication
;  by default (see the username= and password= options to add authentication).
;  Never expose the inet HTTP server to the public internet.

[inet_http_server]         ; inet (TCP
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值