linux自启动程序superver,CentOS 7安装Supervisor设置开机启动

Supervisor

Supervistor 是一个优秀的进程管理程序。它可以为系统UNIX服务器的运维人员,提供监控、操作服务进程的能力,可以作为长期运行的程序的坚实的守护进程。

---- Supvervisor

本文为CentOS 7 系统的安装指南,成文于2019年02月16日,主要提供以下两个安装操作过程:

CentOS 7 安装和配置Supervisor;

使用Systemd设置Supervisor开机启动服务;

执行权限前提说明

下方的所有命令操作,均在ROOT权限状态下,CentOS 7中,可以使用sudo命令来执行,但直接进入ROOT权限更省事。进入ROOT权限命令:

$ sudo -i

基本环境

在Minual Installation模式下安装的CentOS 7自带Python 2.7环境,但需要手动安装easy_install和pip。可以通过以下两个命令来安装:

yum install python-setuptools

easy_install pip

在当前CentOS 7版本,pip开始提示Python2.7快过期的警告信息,我们无须理会,程序员只处理ERROR,忽略WARNING。

安装Supervisor

使用Pip来安装supervisor:

pip install supervisor

创建Supervisor配置文件

CentOS 7系统在Supervisor完成后,不会创建默认配置文件。与CentOS不同,Ubuntu在软件安装自动化方面就相对省事,它会自动创建默认配置。

supervisor要求主配置文件的文件名为supervisord.conf,它会被supervisord和supervisorcrl两个程序使用。在CentOS中,我们使用supervisor提供的工具程序来生成配置:

echo_supervisor_conf > /etc/supervisord.conf

生成的配置文件位置在: /etc/supervisord.conf

Supervisor搜索配置的位置及顺序

$CWD/supervisord.conf

$CWD/etc/supervisord.conf

/etc/supervisord.conf

/etc/supervisor/supervisord.conf (since Supervisor 3.3.0)

../etc/supervisord.conf (Relative to the executable)

../supervisord.conf (Relative to the executable)

Supervisor根据上述位置及顺序,依次搜索,直接找到匹配的配置文件为止。

前两个是快捷搜索,$CWD是指当前工作目录。第3个是常规的配置文件储存位置。

使用nano或者vim打开配置文件。在配置文件的末尾[include]字段,修改include配置目录。

vim /etc/supervisord.conf

将原内容修改为:

[include]

files = /etc/supervisor/conf.d/*.conf

保存,退出: :wq

include字段是让Supervisor在 /etc/supervisor/conf.d/ 目录中查找 .conf 文件来读取它需要管理进程配置。

我们会在这个目录中,根据不同服务,创建一个独立的配置文件。在CentOS中,此目录依然需要我们手动创建:

mkdir -p /etc/supervisor/conf.d

设置Supervisor开机自启动

Supervisor在其Github开源项目中,提供了各个系统的脚本,详见:Supervisor/initscripts

这个文件的内容是Systemd的配置,关于Systemd的使用教程,参考阮一峰的教程:Systemd 入门教程:实战篇

# supervisord service for systemd (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

我们直接下载文件,储存至Systemd的配置目录即可。下面是Wget下载命令:

wget -O /usr/lib/systemd/system/supervisord.service https://raw.githubusercontent.com/Supervisor/initscripts/master/centos-systemd-etcs

启动Supervisor服务

重新加载Systemd配置,使得Supervisord配置生效:

systemctl daemon-reload

然后设置自启动,并启动Supervisor服务:

systemctl enable supervisord.service

systemctl start supervisord.service

Supervisor管理其它进程

安装CowProxy,并使用Supervisor管理自启动

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值