Supervisor安裝與配置文件

先下載最新的supervisor安裝包:

https://pypi.python.org/pypi/supervisor

安裝流程

--wget https://pypi.python.org/packages/7b/17/88adf8cb25f80e2bc0d18e094fcd7ab300632ea00b601cbbbb84c2419eae/supervisor-3.3.2.tar.gz
--tar -zxvf supervisor-3.3.2.tar.gz
--cd supervisor-3.3.2
--python setup.py install
如若運行報錯:
Traceback (most recent call last):
  File "setup.py", line 32, in <module>
    from setuptools import setup, find_packages
ImportError: No module named setuptools

則需要安裝setuptools模塊
setuptools-0.6c11-py2.6.egg

也可以到鏈接:http://download.csdn.net/download/l1028386804/10207047進行下載

然後運行:

sh setuptools-0.6c11-py2.6.egg

之後:echo_supervisord_conf

如出現pkg_resources.DistributionNotFound: meld3>=0.6.5

則  cd /usr/lib/python2.6/site-packages/supervisor-3.3.4-py2.6.egg/EGG-INFO/ 這個目錄下

vim requires.txt  註釋文件中的  meld3 >= 0.6.5

隨後進行

echo_supervisord_conf

echo_supervisord_conf >  /etc/supervisord.conf   --生成配置文件

下面展示配置文件中的內容,可根據需要進行修改


 1 [root@centos-011 ~ 07:50:00]#cat /etc/supervisord.conf.bak
  2 ; Sample supervisor config file.
  3  
  4 [unix_http_server]
  5 file=/var/run/supervisor/supervisor.sock   ; socket 路徑
  6  
  7 ;chmod=0700                 ; socket 文件的權限
  8 ;chown=nobody:nogroup       ; socket 所屬用戶及組
  9 ;username=user              ; 用戶名
 10 ;password=123               ; 密碼
 11  
 12 ;[inet_http_server]         ; 是否啓用服務,默認是關閉的(啓用的話可以看到supervisor 管理的服務狀態)
 13 ;port=127.0.0.1:9001        ; 監聽的IP及端口
 14 ;username=user              ; 用戶名
 15 ;password=123               ; 密碼
 16  
 17 [supervisord]               ; supervisord 全局配置
 18 logfile=/var/log/supervisor/supervisord.log  ; supervisor 日誌路徑
 19 logfile_maxbytes=50MB       ; 單個日誌文件最大數
 20 logfile_backups=10          ; 保留多少個日誌文件(默認10個)
 21 loglevel=info               ; (log level;default info; others: debug,warn,trace)
 22 pidfile=/var/run/supervisord.pid ; pid 文件路徑
 23 nodaemon=false              ; 啓動是否丟到前臺,設置爲false ,表示以daemon 的方式啓動
 24 minfds=1024                 ; 最小文件打開數,對應系統limit.conf 中的nofile ,默認最小爲1024,最大爲4096
 25 minprocs=200                ; 最小的進程打開數,對應系統的limit.conf 中的nproc,默認爲200
 26 ;umask=022                  ; (process file creation umask;default 022)
 27 ;user=chrism                 ; 啓動supervisord 服務的用戶,默認爲root
 28 ;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')
 29 ;directory=/tmp              ; 這裏的目錄指的是服務的工作目錄
 30 ;nocleanup=true              ; (don't clean up tempfiles at start;default false)
 31 ;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
 32 ;environment=KEY=value       ; (key value pairs to add to environment)
 33 ;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)
 34  
 35 ; the below section must remain in the config file for RPC
 36 ; (supervisorctl/web interface) to work, additional interfaces may be
 37 ; added by defining them in separate rpcinterface: sections
 38 [rpcinterface:supervisor]
 39 supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
 40  
 41 [supervisorctl]
 42 serverurl=unix:///var/run/supervisor/supervisor.sock ; use a unix:// URL  for a unix socket
 43 ;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
 44 ;username=chris              ; should be same as http_username if set
 45 ;password=123                ; should be same as http_password if set
 46 ;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
 47 ;history_file=~/.sc_history  ; use readline history if available
 48  
 49 ; The below sample program section shows all possible program subsection values,
 50 ; create one or more 'real' program: sections to be able to control them under
 51 ; supervisor.
 52  
 53 ;[program:theprogramname]      ; 定義一個守護進程 ,比如下面的elasticsearch 
 54 ;command=/bin/cat              ; 啓動程序使用的命令,可以是絕對路徑或者相對路徑
 55 ;process_name=%(program_name)s ; 一個python字符串表達式,用來表示supervisor進程啓動的這個的名稱,默認值是%(program_name)s
 56 ;numprocs=1                    ; Supervisor啓動這個程序的多個實例,如果numprocs>1,則process_name的表達式必須包含%(process_num)s,默認是1
 57 ;directory=/tmp                ; supervisord在生成子進程的時候會切換到該目錄
 58 ;umask=022                     ; umask for process (default None)
 59 ;priority=999                  ; 權重,可以控制程序啓動和關閉時的順序,權重越低:越早啓動,越晚關閉。默認值是999
 60 ;autostart=true                ; 如果設置爲true,當supervisord啓動的時候,進程會自動啓動
 61 ;autorestart=true              ; 設置爲隨 supervisord 重啓而重啓,值可以是false、true、unexpected。false:進程不會自動重啓
 62 ;startsecs=10                  ; 程序啓動後等待多長時間後才認爲程序啓動成功,默認是10秒
 63 ;startretries=3                ; supervisord嘗試啓動一個程序時嘗試的次數。默認是3
 64 ;exitcodes=0,2                 ; 一個預期的退出返回碼,默認是0,2。
 65 ;stopsignal=QUIT               ; 當收到stop請求的時候,發送信號給程序,默認是TERM信號,也可以是 HUP, INT, QUIT, KILL, USR1, or USR2
 66 ;stopwaitsecs=10               ; 在操作系統給supervisord發送SIGCHILD信號時等待的時間
 67 ;user=chrism                   ; 如果supervisord以root運行,則會使用這個設置用戶啓動子程序
 68 ;redirect_stderr=true          ; 如果設置爲true,進程則會把標準錯誤輸出到supervisord後臺的標準輸出文件描述符
 69 ;stdout_logfile=/a/path        ; 把進程的標準輸出寫入文件中,如果stdout_logfile沒有設置或者設置爲AUTO,則supervisor會自動選擇一個文件位置
 70 ;stdout_logfile_maxbytes=1MB   ; 標準輸出log文件達到多少後自動進行輪轉,單位是KB、MB、GB。如果設置爲0則表示不限制日誌文件大小
 71 ;stdout_logfile_backups=10     ; 標準輸出日誌輪轉備份的數量,默認是10,如果設置爲0,則不備份
 72 ;stdout_capture_maxbytes=1MB   ; 當進程處於stderr capture mode模式的時候,寫入FIFO隊列的最大bytes值,單位可以是KB、MB、GB
 73 ;stdout_events_enabled=false   ; 如果設置爲true,當進程在寫它的stderr
 74 ;stderr_logfile=/a/path        ; 把進程的錯誤日誌輸出一個文件中,除非redirect_stderr參數被設置爲true
 75 ;stderr_logfile_maxbytes=1MB   ; 錯誤log文件達到多少後自動進行輪轉,單位是KB、MB、GB。如果設置爲0則表示不限制日誌文件大小
 76 ;stderr_logfile_backups=10     ; 錯誤日誌輪轉備份的數量,默認是10,如果設置爲0,則不備份
 77 ;stderr_capture_maxbytes=1MB   ; 當進程處於stderr capture mode模式的時候,寫入FIFO隊列的最大bytes值,單位可以是KB、MB、GB
 78 ;stderr_events_enabled=false   ; 如果設置爲true,當進程在寫它的stderr到文件描述符的時候,PROCESS_LOG_STDERR事件會被觸發
 79 ;environment=A=1,B=2           ; 一個k/v對的list列表
 80 ;serverurl=AUTO                ; 是否允許子進程和內部的HTTP服務通訊,如果設置爲AUTO,supervisor會自動的構造一個url
 81  
 82 ; The below sample eventlistener section shows all possible
 83 ; eventlistener subsection values, create one or more 'real'
 84 ; eventlistener: sections to be able to handle event notifications
 85 ; sent by supervisor.
 86  #這個地方是自定義一個守護進程
 87 [program:elasticsearch]                       ; 定義一個守護進程 elasticsearch
 88 environment=ES_HOME=/usr/local/elasticsearch  ; 設置ES_HOME 環境變量
 89 user=elk                                      ; 啓動elasticsearch 的用戶
 90 directory=/usr/local/elasticsearch            ; 進入到這個目錄中
 91 command=/usr/local/elasticsearch/bin/elasticsearch ; 執行啓動命令
 92 numprocs=1                                    ; Supervisor啓動這個程序的多個實例,如果numprocs>1,則process_name的表達式必須包含%(process_num)s,默認是1
 93 autostart=true                                ; 設置爲隨 supervisord 啓動而啓動
 94 autorestart=true                              ; 設置爲隨 supervisord 重啓而重啓
 95 startretries=3                                ; 設置elasticsearch 重啓的重試次數
 96 priority=1                                    ; 權重,可以控制程序啓動和關閉時的順序,權重越低:越早啓動,越晚關閉。默認值是999  
 97  
 98 ;[eventlistener:theeventlistenername]
 99 ;command=/bin/eventlistener    ; the program (relative uses PATH, can take args)
100 ;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
101 ;numprocs=1                    ; number of processes copies to start (def 1)
102 ;events=EVENT                  ; event notif. types to subscribe to (req'd)
103 ;buffer_size=10                ; event buffer queue size (default 10)
104 ;directory=/tmp                ; directory to cwd to before exec (def no cwd)
105 ;umask=022                     ; umask for process (default None)
106 ;priority=-1                   ; the relative start priority (default -1)
107 ;autostart=true                ; start at supervisord start (default: true)
108 ;autorestart=unexpected        ; restart at unexpected quit (default: unexpected)
109 ;startsecs=10                  ; number of secs prog must stay running (def. 1)
110 ;startretries=3                ; max # of serial start failures (default 3)
111 ;exitcodes=0,2                 ; 'expected' exit codes for process (default 0,2)
112 ;stopsignal=QUIT               ; signal used to kill process (default TERM)
113 ;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
114 ;user=chrism                   ; setuid to this UNIX account to run the program
115 ;redirect_stderr=true          ; redirect proc stderr to stdout (default false)
116 ;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
117 ;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
118 ;stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
119 ;stdout_events_enabled=false   ; emit events on stdout writes (default false)
120 ;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
121 ;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
122 ;stderr_logfile_backups        ; # of stderr logfile backups (default 10)
123 ;stderr_events_enabled=false   ; emit events on stderr writes (default false)
124 ;environment=A=1,B=2           ; process environment additions
125 ;serverurl=AUTO                ; override serverurl computation (childutils)
126  
127 ; The below sample group section shows all possible group values,
128 ; create one or more 'real' group: sections to create "heterogeneous"
129 ; process groups.
130  
131 ;[group:thegroupname]          ; 服務組管理,可以將多個服務名寫到這裏管理(組名自定義)
132 ;programs=progname1,progname2  ; 上面配置好的服務名,比如elasticsearch,kibana,logstash
133 ;priority=999                  ; the relative start priority (default 999)
134  
135 ; The [include] section can just contain the "files" setting.  This
136 ; setting can list multiple files (separated by whitespace or
137 ; newlines).  It can also contain wildcards.  The filenames are
138 ; interpreted as relative to this file.  Included files *cannot*
139 ; include files themselves.
140  
141 [include]
142 files = supervisord.d/*.ini
啓動
4、確定supervisord 服務並設置爲隨機啓動:

 systemctl start supervisord.service && systemctl enable supervisord.service

或者加載的時候需要,supervisord -c /etc/supervisord.conf這樣就可以了。
--------------------- 
作者:Curry_Yuan 
來源:CSDN 
原文:https://blog.csdn.net/yuanqs_1992/article/details/80833898 
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章