(来自百度百科)Supervisor是一套用Python开发的通用进程管理程序。它可以将一个普通的命令行进程变成后台守护进程,监控进程状态,异常退出时自动重启。它使用fork/exec将这些托管进程作为主管的子进程启动。这样只需要在supervisor配置文件中写上要管理的进程的可执行文件的路径即可。也实现了当子进程挂掉的时候,父进程可以准确的获取到子进程挂掉的信息,并且可以选择是否自己启动和报警。Supervisor还提供了一个功能,可以为supervisord或者每个子进程设置一个非root用户,这个用户可以管理它对应的进程。[阅读全文]Supervisor安装'''环境:Centos7安装wget:yuminstallwget下载Supervisor源码包'''#[root@localhost软件]#yuminstallwget#加载插件:fastestmirror#从缓存的hostfile加载镜像速度#*base:mirror.lzu.edu.cn#*extras:mirror.lzu.edu.cn#*updates:mirrors.163.com#Resolvingdependencies#-->Checkingtransactions#--->Packagewget.x86_64.0.1.14-18.el7_6.1将被安装#[root@localhostsoftware]#wgethttps://files.pythonhosted.org/packages/d3/7f/c780b7471ba0ff4548967a9f7a8b0bfce222c3a496c3dfad0164172222b0.2.2visor.targz#--2021--2415:45:28--https://files.pythonhosted.org/packages/d3/7f/c780b7471ba0ff4548967a9f7a8b0bfce222c3a496c3dfad0164172222b0/supervisor-4.2.2.tar.gz#解析python托管的主机文件。.org(files.pythonhosted.org)...151.101.77.63,2a04:4e42:12::319#正在连接到files.pythonhosted.org(files.pythonhosted.org)|151.101.77.63|:443...已经连接。#HTTP请求已发送,等待响应...200OK#Length:463657(453K)[application/x-tar]#Savingto:"supervisor-4.2.2.tar.gz"SupervisorConfiguration'''1,解压源码包tar-zxvfsupervisor-4.2.2.tar.gz'''#root@localhostsoftware]#tar-zxvfsupervisor-4.2.2.tar.gz#supervisor-4.2.2/#supervisor-4.2。2/CHANGES.rst#supervisor-4.2.2/COPYRIGHT.txt'''2、安装python支持yuminstallpython-setuptools'''#[root@localhostsupervisor-4.2.2]#yuminstallpython-setuptools#already加载插件:fastestmirror#Loadingmirrorspeedsfromcachedhostfile'''3、编译源码包pythonsetup.pyinstall'''#[root@localhostsupervisor-4.2.2]#pythonsetup.pyinstall#runninginstall#runningbdist_egg#runningegg_info#将需求写入supervisor.egg-info/requires.txt'''4.编译完成后,删除其他多余的文件,除了build和dist文件夹,其他都是多余的'''#[root@localhostsupervisor-4.2.2]#ll#Totalusage0#drwxr-xr-x。4rootroot43September2415:51build#drwxr-xr-x。2rootroot40September2415:51dist'''5.创建配置文件,编辑配置文件,授予文件权限'''#echo_supervisord_conf>/usr/etc/supervisord.conf#[root@localhostsupervisor-4.2.2]#vi/usr/etc/supervisord.conf#chmod777/usr/etc/supervisord.conf#[root@localhostsupervisor-4.2.2]#mkdirconfig#/usr/etc/supervisord.conf文件主要配置了两个关键项#[supervisord]#user=普通用户名;在启动时将setuid设置为该UNIX帐户;recommendedifroot#[include]#files=/software/supervisor-4.2.2/config#这个是以后的项目路径'''6.查看版本'''#[root@localhostsupervisor-4.2.2]#supervisord-v#4.2.2'''7.解决python2.7.sock报错'''#[root@localhostsupervisor-4.2.2]#/usr/bin/python2/usr/bin/supervisord-c/usr/etc/supervisord.conf'''8.更新配置'''#supervisorctlupdate'''9.配置一个程序工程配置注意:这里使用hello_world只是为了说明。通用项目是指一直在运行的进程服务,如:redis、tomcat、nginx等。'''#[root@localhostconfig]#vihello_world.config#[program:hello_world]#command=/usr/bin/python2/software/supervisor-4.2.2/hello_world.py#priority=998#autostart=true#autorestart=true#startsecs=60#startretries=3#stopsignal=TERM#stopwaitsecs=10#user=root#stdout_logfile=/software/supervisor-4.2.2/logs/hello_world.log#stdout_logfile_maxbytes=100MB#stdout_logfile_backups=10#stdout_capture_maxbytes=1MB#stderr_logfile=/software/supervisor-4.2.2/logs/hello_world.log#stderr_logfile_maxbytes=100MB#stderr_logfile_backups=10#stderr_capture_maxbytes=1MB'''10.创建hello_world工程一般工程指的是一直运行的进程服务,如:redis、tomcat、nginx等'''#[root@localhostsupervisor-4.2.2]#vihello_world.py##-*-coding:utf-8-*-#print"我是hello_world程序"'''11.重启所有配置的程序'''#[root@localhostsupervisor-4.2.2]#supervisorctlreload#Restartedsupervisord'''12.启动或停止某个项目注:这里使用hello_world只是举例说明,一般项目指的是一直运行的Process服务,如:redis、tomcat、nginx等。'''#supervisorctlstartprojectname#supervisorctlstarthello_world#supervisorctlstopprojectname#supervisorctlstophello_world【往期精选】●如何将python应用作为docker镜像运行?●python-celery是分布式异步任务处理和任务调度的插件!●Python远程服务操作工具:fabric、远程命令、本地命令、服务器操作工具!●You-get是一款非常棒的python插件,单行命令即可下载,推荐使用命令行下载工具!●办公自动化:Python-win32com自动将word文档转为pdf格式!●妙用pandas数据统计插件的连接函数concat(),灵活处理数据对象!●GitLFS3.0.0发布,大文件版本控制的Git扩展●python有序序列的字典序列推导技巧的使用!●Django4.0alpha1发布●python经典有序序列表理解的实战应用●python常用转义字符串总结:不同的转义字符,如何取消转义字符的作用?●Python内置函数以字符串形式执行函数代码块,类似java的反射机制相当强大!●磨刀不误砍柴工,定期配置PyCharm开发工具,全面提升开发效率!●python-openpyxlExcel单元格样式设置,包括字体、样式、宽高等!
