五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動態(tài)

Linux系統(tǒng)下的進(jìn)程監(jiān)控工具Supervisor的基本使用方法

發(fā)布日期:2022-02-01 18:21 | 文章來源:站長之家

Supervisor是一個C/S系統(tǒng),它允許用戶在類UNIX系統(tǒng)上控制一些進(jìn)程。它具有以下特性:

1 簡單

Supervisor通過INI格式配置文件進(jìn)行配置,很容易掌握,它為每個進(jìn)程提供了很多配置選項,可以使你很容易的重啟進(jìn)程或者自動的輪轉(zhuǎn)日志。

2 統(tǒng)一

Supervisor提供了一種統(tǒng)一的方式來start、stop、monitor你的進(jìn)程, 進(jìn)程可以單獨控制,也可以成組的控制。你可以在本地或者遠(yuǎn)程命令行或者web接口來配置Supervisor。

3 有效

Supervisor通過fork/exec啟動它的子進(jìn)程,子進(jìn)程并不是守護(hù)進(jìn)程。當(dāng)一個進(jìn)程終止的時候,操作系統(tǒng)會立即給Supervisor發(fā)送一個信號,而不是像其他解決方案依賴PID文件。

4 可擴展

Supervisor包含一個簡單的事件通知協(xié)議,因此任何程序都可以監(jiān)控它,而且提供一個XML-RPC控制接口。

5 兼容

除了windows平臺,其他平臺都可運行。

Supervisor系統(tǒng)的組件:

supervisord:

服務(wù)會啟動supervisord服務(wù),它負(fù)責(zé)調(diào)用自己啟動子程序,響應(yīng)來自客戶端的命令,重啟crash或者退出的進(jìn)程,記錄進(jìn)程的輸出信息,收集事件信息。該服務(wù)的配置文件在/etc/supervisor/supervisord.conf

supervisorctl:

客戶端的命令行工具,提供一個類shell接口,通過它你可以連接到不同的supervisord進(jìn)程上來管理它們各自的子程序??蛻舳嗣钔ㄟ^UNIX socket或者TCP來和服務(wù)通訊,服務(wù)端可以要求客戶端提供身份驗證之后才能進(jìn)行操作([supervisorctl])。

Web Server:

一個小的web接口被集成進(jìn)了supervisorctl,重啟supervisord之后就可以訪問了([inet_http_server])。

XML-RPC Interface:

就像HTTP提供WEB UI一樣,同時還提供了XML-RPC接口來控制supervisor和由它運行的程序。

安裝:

supervisor是python編寫的,顯然用easy_install、pip都可以安裝,我懶,直接apt-get了,在ubuntu14.04下安裝完后版本是3.0b2。

Supervisor服務(wù)的啟動

其實啟動Supervisor很簡單,supervisord -h看看就知道了,最簡單的-c根配置文件即可:


復(fù)制代碼
代碼如下:

supervisord -- run a set of applications as daemons.

Usage: /usr/bin/supervisord [options]

Options:
-c/--configuration FILENAME -- configuration file
-n/--nodaemon -- run in the foreground (same as 'nodaemon true' in config file)
-h/--help -- print this usage message and exit
-v/--version -- print supervisord version number and exit
-u/--user USER -- run supervisord as this user (or numeric uid)
-m/--umask UMASK -- use this umask for daemon subprocess (default is 022)
-d/--directory DIRECTORY -- directory to chdir to when daemonized
-l/--logfile FILENAME -- use FILENAME as logfile path
-y/--logfile_maxbytes BYTES -- use BYTES to limit the max size of logfile
-z/--logfile_backups NUM -- number of backups to keep when max bytes reached
-e/--loglevel LEVEL -- use LEVEL as log level (debug,info,warn,error,critical)
-j/--pidfile FILENAME -- write a pid file for the daemon process to FILENAME
-i/--identifier STR -- identifier used for this instance of supervisord
-q/--childlogdir DIRECTORY -- the log directory for child process logs
-k/--nocleanup -- prevent the process from performing cleanup (removal of
old automatic child log files) at startup.
-a/--minfds NUM -- the minimum number of file descriptors for start success
-t/--strip_ansi -- strip ansi escape codes from process output
--minprocs NUM -- the minimum number of processes available for start success
--profile_options OPTIONS -- run supervisord under profiler and output
results based on OPTIONS, which is a comma-sep'd
list of 'cumulative', 'calls', and/or 'callers',
e.g. 'cumulative,callers')
不過既然我這懶人是用apt-get安裝的,那安裝包的規(guī)范必然符合debian系的風(fēng)格了,直接service supervisor start即可啟動,且慢,我們還沒配置supervisor的配置文件呢,啟動了也沒什么效果。我們后面詳解配置文件的配置。

supervisorctl客戶端的使用

supervisorctl有兩種模式,一種是交互模式,一種是命令行模式。在命令行輸入supervisorctl直接回車,即可進(jìn)入交互模式。

復(fù)制代碼
代碼如下:

supervisorctl -- control applications run by supervisord from the cmd line.

Usage: /usr/bin/supervisorctl [options] [action [arguments]]

Options:
-c/--configuration -- configuration file path (default /etc/supervisor.conf)
-h/--help -- print usage message and exit
-i/--interactive -- start an interactive shell after executing commands
-s/--serverurl URL -- URL on which supervisord server is listening
(default "http://localhost:9001").
-u/--username -- username to use for authentication with server
-p/--password -- password to use for authentication with server
-r/--history-file -- keep a readline history (if readline is available)

復(fù)制代碼
代碼如下:

action [arguments] -- see below

Actions are commands like "tail" or "stop". If -i is specified or no action is
specified on the command line, a "shell" interpreting actions typed
interactively is started. Use the action "help" to find out about available
actions.
Supervisor的開機自啟動

如果你是pip或者easy_install安裝的,開機服務(wù)自啟動還真是個麻煩事,不過官方已經(jīng)給出一些rc.d腳本示例了,在github上,不過由于我是apt-get安裝的,顯然這個開機自啟動是不用擔(dān)心的,用debian的update-rc.d即可搞定。

Supervisor的進(jìn)程安全

既然是用Supervisor來保證其他進(jìn)程的正常運行,但是萬一Supervisor進(jìn)程掛了怎么辦,我們可以使用daemontools來保證Supervisor正常運行,就類似于監(jiān)控的監(jiān)控。

supervisord的配置文件主要由幾個配置段構(gòu)成,配置項以K/V格式呈現(xiàn),下面就看看各個配置端需要怎樣配置:

[unix_http_server]

在該配置塊的參數(shù)項表示的是一個監(jiān)聽在socket上的HTTP server,如果[unix_http_server]塊不在配置文件中,則不會啟動基于socket的HTTP server。

file:一個unix domain socket的文件路徑,HTTP/XML-RPC會監(jiān)聽在這上面
chmod:在啟動時修改unix domain socket的mode
chown:修改socket文件的屬主
username:HTTP server在認(rèn)證時的用戶名
password:認(rèn)證密碼<span style="font-family:'Microsoft YaHei';font-size:16px;line-height:1.5;"></span>
eg:

復(fù)制代碼
代碼如下:

[unix_http_server]
file = /tmp/supervisor.sock
chmod = 0777
chown= nobody:nogroup
username = user
password = 123
[inet_http_server]

在該配置塊的參數(shù)項表示的是一個監(jiān)聽在TCP上的HTTP server,如果[inet_http_server]塊不在配置文件中,則不會啟動基于TCP的HTTP server。

port:TCP監(jiān)聽的地址和端口(ip:port),這個地址會被HTTP/XML-RPC監(jiān)聽
username:HTTP server在認(rèn)證時的用戶名
password:認(rèn)證密碼
eg:

復(fù)制代碼
代碼如下:

[inet_http_server]
port = 127.0.0.1:9001
username = user
password = 123
[supervisord]

該配置塊的參數(shù)項是關(guān)于supervisord進(jìn)程的全局配置項。
logfile:log文件路徑
logfile_maxbytes:log文件達(dá)到多少后自動進(jìn)行輪轉(zhuǎn),單位是KB、MB、GB。如果設(shè)置為0則表示不限制日志文件大小
logfile_backups:輪轉(zhuǎn)日志備份的數(shù)量,默認(rèn)是10,如果設(shè)置為0,則不備份
loglevel:error、warn、info、debug、trace、blather、critical
pidfile:pid文件路徑
umask:umask值,默認(rèn)022
nodaemon:如果設(shè)置為true,則supervisord在前臺啟動,而不是以守護(hù)進(jìn)程啟動
minfds:supervisord在成功啟動前可用的最小文件描述符數(shù)量,默認(rèn)1024
minprocs:supervisord在成功啟動前可用的最小進(jìn)程描述符數(shù)量,默認(rèn)200
nocleanup:防止supervisord在啟動的時候清除已經(jīng)存在的子進(jìn)程日志文件
childlogdir:自動啟動的子進(jìn)程的日志目錄
user:supervisord的運行用戶
directory:supervisord以守護(hù)進(jìn)程運行的時候切換到這個目錄
strip_ansi:消除子進(jìn)程日志文件中的轉(zhuǎn)義序列
environment:一個k/v對的list列表
eg:

復(fù)制代碼
代碼如下:

[supervisord]
logfile = /tmp/supervisord.log
logfile_maxbytes = 50MB
logfile_backups=10
loglevel = info
pidfile = /tmp/supervisord.pid
nodaemon = false
minfds = 1024
minprocs = 200
umask = 022
user = chrism
identifier = supervisor
directory = /tmp
nocleanup = true
childlogdir = /tmp
strip_ansi = false
environment = KEY1="value1",KEY2="value2"
[supervisorctl]

該配置塊參數(shù)是關(guān)于supervisorctl

serverurl:這個url是用來訪問supervisord服務(wù)的(http://localhost:9001),或者是個sockets文件(unix:///absolute/path/to/file.sock)
username:supervisorctl連接supervisord的認(rèn)證用戶
password:認(rèn)證密碼
prompt:默認(rèn)是supervisor
history_file:history文件路徑
eg:

復(fù)制代碼
代碼如下:

[supervisorctl]
serverurl = unix:///tmp/supervisor.sock
username = chris
password = 123
prompt = mysupervisor
[program:x]

該配置塊包含一個或者多個program段,program來表明supervisord要控制哪些程序。該配置塊的頭部是有固定格式的,一個關(guān)鍵字program,后面跟著一個冒號,接下來才是程序名。例如:[program:foo],foo就是程序名,在使用supervisorctl來操作程序的時候,就是以foo來標(biāo)明的。

command:啟動程序使用的命令,可以是絕對路徑或者相對路徑
process_name:一個python字符串表達(dá)式,用來表示supervisor進(jìn)程啟動的這個的名稱,默認(rèn)值是%(program_name)s
numprocs:Supervisor啟動這個程序的多個實例,如果numprocs>1,則process_name的表達(dá)式必須包含%(process_num)s,默認(rèn)是1
numprocs_start:一個int偏移值,當(dāng)啟動實例的時候用來計算numprocs的值
priority:權(quán)重,可以控制程序啟動和關(guān)閉時的順序,權(quán)重越低:越早啟動,越晚關(guān)閉。默認(rèn)值是999
autostart:如果設(shè)置為true,當(dāng)supervisord啟動的時候,進(jìn)程會自動重啟。
autorestart:值可以是false、true、unexpected。false:進(jìn)程不會自動重啟,unexpected:當(dāng)程序退出時的退出碼不是exitcodes中定義的時,進(jìn)程會重啟,true:進(jìn)程會無條件重啟當(dāng)退出的時候。
startsecs:程序啟動后等待多長時間后才認(rèn)為程序啟動成功
startretries:supervisord嘗試啟動一個程序時嘗試的次數(shù)。默認(rèn)是3
exitcodes:一個預(yù)期的退出返回碼,默認(rèn)是0,2。
stopsignal:當(dāng)收到stop請求的時候,發(fā)送信號給程序,默認(rèn)是TERM信號,也可以是 HUP, INT, QUIT, KILL, USR1, or USR2。
stopwaitsecs:在操作系統(tǒng)給supervisord發(fā)送SIGCHILD信號時等待的時間
stopasgroup:如果設(shè)置為true,則會使supervisor發(fā)送停止信號到整個進(jìn)程組
killasgroup:如果設(shè)置為true,則在給程序發(fā)送SIGKILL信號的時候,會發(fā)送到整個進(jìn)程組,它的子進(jìn)程也會受到影響。
user:如果supervisord以root運行,則會使用這個設(shè)置用戶啟動子程序
redirect_stderr:如果設(shè)置為true,進(jìn)程則會把標(biāo)準(zhǔn)錯誤輸出到supervisord后臺的標(biāo)準(zhǔn)輸出文件描述符。
stdout_logfile:把進(jìn)程的標(biāo)準(zhǔn)輸出寫入文件中,如果stdout_logfile沒有設(shè)置或者設(shè)置為AUTO,則supervisor會自動選擇一個文件位置。
stdout_logfile_maxbytes:標(biāo)準(zhǔn)輸出log文件達(dá)到多少后自動進(jìn)行輪轉(zhuǎn),單位是KB、MB、GB。如果設(shè)置為0則表示不限制日志文件大小
stdout_logfile_backups:標(biāo)準(zhǔn)輸出日志輪轉(zhuǎn)備份的數(shù)量,默認(rèn)是10,如果設(shè)置為0,則不備份
stdout_capture_maxbytes:當(dāng)進(jìn)程處于stderr capture mode模式的時候,寫入FIFO隊列的最大bytes值,單位可以是KB、MB、GB
stdout_events_enabled:如果設(shè)置為true,當(dāng)進(jìn)程在寫它的stderr到文件描述符的時候,PROCESS_LOG_STDERR事件會被觸發(fā)
stderr_logfile:把進(jìn)程的錯誤日志輸出一個文件中,除非redirect_stderr參數(shù)被設(shè)置為true
stderr_logfile_maxbytes:錯誤log文件達(dá)到多少后自動進(jìn)行輪轉(zhuǎn),單位是KB、MB、GB。如果設(shè)置為0則表示不限制日志文件大小
stderr_logfile_backups:錯誤日志輪轉(zhuǎn)備份的數(shù)量,默認(rèn)是10,如果設(shè)置為0,則不備份
stderr_capture_maxbytes:當(dāng)進(jìn)程處于stderr capture mode模式的時候,寫入FIFO隊列的最大bytes值,單位可以是KB、MB、GB
stderr_events_enabled:如果設(shè)置為true,當(dāng)進(jìn)程在寫它的stderr到文件描述符的時候,PROCESS_LOG_STDERR事件會被觸發(fā)
environment:一個k/v對的list列表
directory:supervisord在生成子進(jìn)程的時候會切換到該目錄
umask:設(shè)置進(jìn)程的umask
serverurl:是否允許子進(jìn)程和內(nèi)部的HTTP服務(wù)通訊,如果設(shè)置為AUTO,supervisor會自動的構(gòu)造一個url

eg:

復(fù)制代碼
代碼如下:

[program:cat]
command=/bin/cat
process_name=%(program_name)s
numprocs=1
directory=/tmp
umask=022
priority=999
autostart=true
autorestart=true
startsecs=10
startretries=3
exitcodes=0,2
stopsignal=TERM
stopwaitsecs=10
user=chrism
redirect_stderr=false
stdout_logfile=/a/path
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/a/path
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
environment=A="1",B="2"
serverurl=AUTO

海外穩(wěn)定服務(wù)器

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部