GVKun编程网logo

Linux 后台进程管理利器:supervisor(linux进程管理工具supervisor)

1

以上就是给各位分享Linux后台进程管理利器:supervisor,其中也会对linux进程管理工具supervisor进行解释,同时本文还将给你拓展CentOS安装supervisor以及设置Lar

以上就是给各位分享Linux 后台进程管理利器:supervisor,其中也会对linux进程管理工具supervisor进行解释,同时本文还将给你拓展CentOS 安装 supervisor 以及设置 Laravel 队列设置、Daemontools 和 Supervisor 管理 linux 常驻进程、Django笔记 生产环境部署 gunicorn+nginx+supervisor c&b supervisor store supervisor piping superviso、Django,nginx,gunicorn,supervisor:UnicodeEncodeError – 上传非拉丁文的命名文件等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

Linux 后台进程管理利器:supervisor(linux进程管理工具supervisor)

Linux 后台进程管理利器:supervisor(linux进程管理工具supervisor)

一、安装:

1、yum 方式 (推荐):

$ sudo su - #切换为root用户

# yum install epel-release
# yum install -y supervisor
# systemctl enable supervisord # 开机自启动
# systemctl start supervisord # 启动supervisord服务

# systemctl status supervisord # 查看supervisord服务状态
# ps -ef|grep supervisord # 查看是否存在supervisord进程

2、pip 安装 (不推荐)

sudo pip install supervisor

二、生成配置文件

echo_supervisord_conf > /etc/supervisord.conf

配置:

[program:django]
command=python  /opt/Automation_platform/manage.py runserver localhost:8080
user = wanghua.zhou
autostart=true
autorestart=true
startsecs=3
stopasgroup=true
stderr_logfile=/home/wanghua.zhou/log/django/bandwidth_err.log
stdout_logfile=/home/wanghua.zhou/log/django/bandwidth.log

三、启动

sudo supervisord -c /etc/supervisord.conf

四、进程管理

sudo supervisorctl start process
sudo supervisorctl stop process
sudo supervisorctl restart process
sudo supervisorctl stop all
也可以进入 supervision 控制台:
sudo supervisorctl
stop django  停止服务
start django 启动服务

五。重启服务,重新加载配置文件

停止然后重启所有子程序:

sudo supervisorctl reload

只重启配置更新的子程序

sudo supervisorctl update

六.Web 管理

vim /etc/supervisord.conf

访问: http://10.241.11.223:9001

输入图片说明

输入图片说明

CentOS 安装 supervisor 以及设置 Laravel 队列设置

CentOS 安装 supervisor 以及设置 Laravel 队列设置

安装 supervisor

安装

先安装 Python 的 easy_install,再通过 easy_install 安装 supervisor

# yum install python-setuptools
# easy_install supervisor

生成配置文件

# echo_supervisord_conf > /etc/supervisord.conf

自动启动

在 https://github.com/Supervisor/initscripts 下载 CentOS 使用的自动启动服务脚本 centos-systemd-etcs

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

supervisord 服务设为自启动

# systemctl enable supervisord.service

启动 supervisord

# supervisord -c /etc/supervisord.conf

输入 supervisorctl 命令可以进入 supervisor 控制台

设置 Laravel 队列

编辑 /etc/supervisord.conf ,在在文件结尾添加如下内容

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/PHP/bin/PHP /data/wwwroot/app.com/artisan queue:work database --sleep=3 --tries=3 --daemon
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/data/wwwroot/app.com/storage/logs/queue.log

这里开启了 8 个 queue:work 进程,并监视他们,如果失败的话,自动重启;在项目的 storage/logs/queue.log 记录日志。

执行以下命令更新 supervisor 配置并启动进程:

# supervisord -c /etc/supervisord.conf
# supervisorctl -c /etc/supervisord.conf
# supervisorctl reread
# supervisorctl update
# supervisorctl start laravel-worker:*

至此, supervisor 安装及 Laravel 队列设置完毕

Daemontools 和 Supervisor 管理 linux 常驻进程

Daemontools 和 Supervisor 管理 linux 常驻进程

linux 主要使用 supervise 来管理常驻进程。基于 supervise 的两个比较重要的工具是 Daemontools 和 Supervisor。

实际上,supervise 也算 Daemontools 的一个工具。Daemontools 是 svscanboot,svscan,supervise,svc,svok,svstat 等一系列工具的合集。

安装

执行安装后,所有的命令都放到了 /command 目录,并软链到 /usr/local/bin/ 下面。

并且新建了 /service 目录来放置常驻脚本。

关系

安装完后,可以看到两个进程启动了。

root     19907  0.0 0.0 1936 508 ? Ss 17:12 0:00 /bin/sh /command/svscanboot root 19909 0.0 0.0 1880 376 ? S 17:12 0:00 svscan /service

svscanboot 启动 svscan 监视 /service 目录,svscan 则为 /service 的每个进程都启动一个 supervise 服务。

supervise s 执行./s/run,如果 s/down 文件存在,则需要使用 svc 手动启用。(机器重启的时候防止自动启用)

如果往 /service 下面加入服务脚本,则可以在后台看到下面的进程。

root@test2:/opt/tiger/graphite_client/tsar-client_run# ps aux|grep supervise root 3945 0.0 0.0 3932 40 ? S 2013 0:00 supervise location_search_8920 root 3946 0.0 0.0 3932 28 ? S 2013 0:00 supervise fenci_run root 3952 0.0 0.0 3932 76 ? S 2013 44:04 supervise tsar-client_run root 3953 0.0 0.0 3932 52 ? S 2013 0:00 supervise sentinel_run root 3954 0.0 0.0 3932 20 ? S 2013 0:00 supervise qiuzu_solr

supervise 的状态信息以 2 进制的形式存放在 s/supervise 下面,并且提供了下面的工具来操作:

  • svstat: 读取状态信息
  • svc: 启动 / 停止 / 挂起等
  • svok: 检查是否运行成功
  • svscan:可靠的启动 /service 目录下的服务。如果某个服务加入后,没有启动,可以调用此命令,强制启动。

加入一个新服务

最简单的方式是建立一个文件夹

testsvc
├── main.py └── run

写入文件内容:

yijingping@yjp-pc:~/testsvc$ cat main.py #!/usr/bin/python import time import logging while True: time.sleep(1) logging.info(''sleep 1 second'') logging.error(''sleep 1 second'') yijingping@yjp-pc:~/testsvc$ cat run #!/bin/sh exec ./main.py 1>/var/log/main.py.log 2>&1

然后在 /service 目录下建立软链接

$ sudo ln -s /path/to/testsvc

这个时候可以检查一下服务是否正在运行:

yijingping@yjp-pc:~$ sudo svstat /service/testsvc /service/testsvc: up (pid 4204) 962 seconds yijingping@yjp-pc:~$ ps aux|grep supervise root 4203 0.0 0.0 1716 248 ? S 09:37 0:00 supervise testsvc 1000 5631 0.0 0.0 3784 792 pts/3 S+ 09:54 0:00 grep supervise yijingping@yjp-pc:~$ tree /service/testsvc /service/testsvc ├── main.py ├── run └── supervise [error opening dir] 1 directory, 2 files

上面这种方式的坏处是必须以 root 用户运行,如果想以其他用户运行,则需要做如下改进,假设用户为 tiger,id 为 1001:

tigersvc
├── main.py ├── real_run └── run

文件内容:

tiger@yjp-pc:~/tigersvc$ cat run #!/bin/sh who=$(id -u) if [ $who -eq 0 ]; then exec /usr/local/bin/setuidgid tiger ./real_run elif [ $who -eq 1001 ];then exec ./real_run else echo "neither root nor tiger" fi tiger@yjp-pc:~/tigersvc$ cat real_run #!/bin/sh exec ./main.py 1>/var/log/tiger/main2.py.log 2>&1

加入服务后,查看后台进程以 tiger 为用户在运行:

yijingping@yjp-pc:/service$ ps aux|grep main.py tiger 24682 0.0 0.1 7052 3924 ? S 13:47 0:00 /usr/bin/python ./main.py

管理服务

使用 svstat 来查看服务

yijingping@yjp-pc:/service$ sudo svstat testsvc testsvc: down 20 seconds, normally up yijingping@yjp-pc:/service$ sudo svstat tigersvc tigersvc: up (pid 25046) 230 seconds

使用 svc 来管理服务

command mnemonic    signal  action
svc -u  up                  bring service up
svc -d down put service down (stays down) svc -o once run service once (don''t restart) svc -k kill SIGKILL send service KILL signal

如果要重启,必须先 svc -d s,再 svc -u s

其他工具

log 工具:

  • The readproctitle program
  • The multilog program
  • The tai64n program
  • The tai64nlocal program

环境工具:

  • The setuidgid program
  • The envuidgid program
  • The envdir program
  • The softlimit program
  • The setlock program

阅读原文

Django笔记 生产环境部署 gunicorn+nginx+supervisor c&b supervisor store supervisor piping superviso

Django笔记 生产环境部署 gunicorn+nginx+supervisor c&b supervisor store supervisor piping superviso

Django,nginx,gunicorn,supervisor:UnicodeEncodeError – 上传非拉丁文的命名文件

Django,nginx,gunicorn,supervisor:UnicodeEncodeError – 上传非拉丁文的命名文件

当我上传一些非拉丁名字的文件时,我得到错误:

UnicodeEncodeError at /profiles/ 'ascii' codec can't encode characters in position 39-41: ordinal not in range(128)

我已经尝试过更改主pipe环境, 在这里如何描述,但没有帮助。 我在/etc/supervisor/supervisord.conf中添加了这一行:

[supervisord] environment=LANG="ru_RU.utf8",LC_LANG="ru_RU.UTF-8",LC_ALL="ru_RU.UTF-8" logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) childlogdir=/var/log/supervisor ; ('AUTO' child log dir,default $TEMP)

当我把这一行放在程序特定的conf文件中时,它也没有开始工作。

我试图找出我的编码,所以我已经添加到模板上下文这个variables:

国际化Django(在OSX上)

使用Django进行静态文件版本控制

Python 2.6.2,Django 1.0.3,Windows XP,找不到页面:/

Djangopipe理员后端“操作错误”试图写一个只读数据库

Django说所有图片都是无效的,但是PIL工作

context['locale'] = sys.getfilesystemencoding()

并在模板中显示“ANSI_X3.4-1968”

可以请一个人解释为什么改变环境没有解决问题?

谢谢。

用Nginx,django下载文件

gunicorn,Nginx(v 1.3.14),django和gevent-socket.io,在dotcloud

在Apache mod_python上部署django应用程序

Django芹菜socket.error:连接被拒绝

Django中的并发加载处理

确保你已经完全重新启动了supervisord,如下所述。 希望能帮助到你!

我们今天的关于Linux 后台进程管理利器:supervisorlinux进程管理工具supervisor的分享就到这里,谢谢您的阅读,如果想了解更多关于CentOS 安装 supervisor 以及设置 Laravel 队列设置、Daemontools 和 Supervisor 管理 linux 常驻进程、Django笔记 生产环境部署 gunicorn+nginx+supervisor c&b supervisor store supervisor piping superviso、Django,nginx,gunicorn,supervisor:UnicodeEncodeError – 上传非拉丁文的命名文件的相关信息,可以在本站进行搜索。

本文标签: