(摘自百度百科)Supervisor是用Python開發的一套通用的行程管理程式,能將一個普通的命令列行程變為后臺daemon,并監控行程狀態,例外退出時能自動重啟,它是通過fork/exec的方式把這些被管理的行程當作supervisor的子行程來啟動,這樣只要在supervisor的組態檔中,把要管理的行程的可執行檔案的路徑寫進去即可,也實作當子行程掛掉的時候,父行程可以準確獲取子行程掛掉的資訊的,可以選擇是否自己啟動和報警,supervisor還提供了一個功能,可以為supervisord或者每個子行程,設定一個非root的user,這個user就可以管理它對應的行程,

【閱讀全文】
Supervisor安裝
'''
環境:Centos7
安裝wget:yum install wget
下載Supervisor原始碼包
'''
# [root@localhost software]# yum install wget
# 已加載插件:fastestmirror
# Loading mirror speeds from cached hostfile
# * base: mirror.lzu.edu.cn
# * extras: mirror.lzu.edu.cn
# * updates: mirrors.163.com
# 正在解決依賴關系
# --> 正在檢查事務
# ---> 軟體包 wget.x86_64.0.1.14-18.el7_6.1 將被 安裝
# [root@localhost software]# wget https://files.pythonhosted.org/packages/d3/7f/c780b7471ba0ff4548967a9f7a8b0bfce222c3a496c3dfad0164172222b0/supervisor-4.2.2.tar.gz
# --2021-09-24 15:45:28-- https://files.pythonhosted.org/packages/d3/7f/c780b7471ba0ff4548967a9f7a8b0bfce222c3a496c3dfad0164172222b0/supervisor-4.2.2.tar.gz
# 正在決議主機 files.pythonhosted.org (files.pythonhosted.org)... 151.101.77.63, 2a04:4e42:12::319
# 正在連接 files.pythonhosted.org (files.pythonhosted.org)|151.101.77.63|:443... 已連接,
# 已發出 HTTP 請求,正在等待回應... 200 OK
# 長度:463657 (453K) [application/x-tar]
# 正在保存至: “supervisor-4.2.2.tar.gz”
Supervisor配置
'''
1、解壓原始碼包
tar -zxvf supervisor-4.2.2.tar.gz
'''
# root@localhost software]# tar -zxvf supervisor-4.2.2.tar.gz
# supervisor-4.2.2/
# supervisor-4.2.2/CHANGES.rst
# supervisor-4.2.2/COPYRIGHT.txt
'''
2、安裝python支持
yum install python-setuptools
'''
# [root@localhost supervisor-4.2.2]# yum install python-setuptools
# 已加載插件:fastestmirror
# Loading mirror speeds from cached hostfile
'''
3、編譯原始碼包
python setup.py install
'''
# [root@localhost supervisor-4.2.2]# python setup.py install
# running install
# running bdist_egg
# running egg_info
# writing requirements to supervisor.egg-info/requires.txt
'''
4、編譯后洗掉其他多余檔案、除了build、dist兩個檔案夾其他都是多余的
'''
# [root@localhost supervisor-4.2.2]# ll
# 總用量 0
# drwxr-xr-x. 4 root root 43 9月 24 15:51 build
# drwxr-xr-x. 2 root root 40 9月 24 15:51 dist
'''
5、創建組態檔、編輯組態檔、賦予檔案權限
'''
# echo_supervisord_conf > /usr/etc/supervisord.conf
# [root@localhost supervisor-4.2.2]# vi /usr/etc/supervisord.conf
# chmod 777 /usr/etc/supervisord.conf
# [root@localhost supervisor-4.2.2]# mkdir config
# /usr/etc/supervisord.conf檔案主要配置兩個關鍵項
# [supervisord]
# user=普通用戶名稱 ; setuid to this UNIX account at startup; recommended if root
# [include]
# files = /software/supervisor-4.2.2/config # 這個是以后的專案路徑
'''
6、查看版本
'''
# [root@localhost supervisor-4.2.2]# supervisord -v
# 4.2.2
'''
7、解決python2.7.sock報錯的問題
'''
# [root@localhost supervisor-4.2.2]# /usr/bin/python2 /usr/bin/supervisord -c /usr/etc/supervisord.conf
'''
8、更新配置
'''
# supervisorctl update
'''
9、配置一個程式專案配置
注意:這里使用hello_world只是作為一個說明,一般專案指的都是一直運行的行程服務,比如:redis、tomcat、nginx等等,
'''
# [root@localhost config]# vi hello_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專案
注意:這里使用hello_world只是作為一個說明,一般專案指的都是一直運行的行程服務,比如:redis、tomcat、nginx等等,
'''
# [root@localhost supervisor-4.2.2]# vi hello_world.py
# # -*- coding:utf-8 -*-
# print "我是hello_world程式"
'''
11、重啟配置的所有程式
'''
# [root@localhost supervisor-4.2.2]# supervisorctl reload
# Restarted supervisord
'''
12、啟動或停止某個專案
注意:這里使用hello_world只是作為一個說明,一般專案指的都是一直運行的行程服務,比如:redis、tomcat、nginx等等,
'''
# supervisorctl start 專案名稱
# supervisorctl start hello_world
# supervisorctl stop 專案名稱
# supervisorctl stop hello_world
【往期精選】
● 如何將一個python應用以docker鏡像的方式來運行?
● python-celery專注于實作分布式異步任務處理、任務調度的插件!
● python遠程服務操作工具:fabric,遠程命令、本地命令、服務器操作利器!
● python超贊插件you-get,執行一行命令即可下載、命令列下載工具推薦!
● 辦公自動化:Python-win32com自動將word檔案轉換成pdf格式!
● pandas資料統計插件的連接函式concat()妙用,靈活處理資料物件!
● Git LFS 3.0.0 發布,對大檔案進行版本控制的 Git 擴展
● python有序序列的字典序列推導式運用技巧!
● Django 4.0 alpha 1 發布
● python經典有序序列的list串列推導式實踐運用
● python常用轉義字串總結:各種字符轉義的不同、如何取消轉義字符效果?
● python內置函式通過字串的方式來執行函式代碼塊,類似java的反射機制相當強大!
● 磨刀不誤砍柴工,PyCharm開發工具的常規配置,充分提高開發效率!
● python-openpyxl Excel的單元格樣式設定,包括字體、樣式、寬高等等!
歡迎關注作者公眾號【Python 集中營】,專注于后端編程,每天更新技術干貨,不定時分享各類資料!轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/322968.html
標籤:Python
