supervisord是一個進程管理工具,提供web頁面管理,能對進程進行自動重啓等操做。 優勢: - 能夠將非後臺運行程序後臺運行 - 自動監控,重啓進程 缺點: - 不能管理後臺運行程序 - 對多進程服務,不能使用kill關閉
1.pip安裝supervisordphp
pip install supervisor
2.生成配置文件html
echo_supervisord_conf > /etc/supervisord.conf
若是報錯:python
vim /usr/lib/python2.6/site-packages/supervisor-3.3.3-py2.6.egg-info/requires.txt # 註銷以下內容便可 #meld3 >= 0.6.5
3.修改配置文件nginx
[unix_http_server] file=/tmp/supervisor.sock ; the path to the socket file # 開啓web界面 [inet_http_server] ; inet (TCP) server disabled by default port=mweb07:9001 ; ip_address:port specifier, *:port for all iface username=admin ; default is no username (open server) password=123456 ; default is no password (open server) [supervisord] logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB logfile_backups=10 ; # of main logfile backups; 0 means none, default 10 loglevel=info ; log level; default info; others: debug,warn,trace pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid nodaemon=false ; start in foreground if true; default false minfds=1024 ; min. avail startup file descriptors; default 1024 minprocs=200 ; min. avail process descriptors;default 200 [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket [program:elasticsearch] command=/data/elk/elasticsearch/bin/elasticsearch ; 管理命令,supervisor不支持後太進程 process_name=%(program_name)s user=elk ;進程啓動用戶 autostart=true ;是否隨supervisor啓動 autorestart=true ;是否在掛了以後重啓,意外關閉後會重啓,好比kill掉! startretries=3 ;啓動嘗試次數 stderr_logfile=/tmp/tail1.err.log ;標準輸出的位置 stdout_logfile=/tmp/tail1.out.log ;標準錯誤輸出的位置 loglevel=info ;日誌的級別 [program:redis] command=/data/elk/redis/src/redis-server /data/elk/redis/redis.conf process_name=%(program_name)s user=elk directory=/data/elk/redi
4.啓動關閉
啓動:git
supervisord -c /etc/supervisord.conf
關閉:github
supervisorctl shutdown
管理命令:web
supervisorctl stop program_name # 中止某一個進程,program_name 爲 [program:x] 裏的 x supervisorctl start program_name # 啓動某個進程 supervisorctl restart program_name # 重啓某個進程 supervisorctl stop groupworker: # 結束全部屬於名爲 groupworker 這個分組的進程 (start,restart 同理) supervisorctl stop groupworker:name1 # 結束 groupworker:name1 這個進程 (start,restart 同理) supervisorctl stop all # 中止所有進程,注:start、restartUnlinking stale socket /tmp/supervisor.sock 、stop 都不會載入最新的配置文件 supervisorctl reload # 載入最新的配置文件,中止原有進程並按新的配置啓動、管理全部進程 supervisorctl update # 根據最新的配置文件,啓動新配置或有改動的進程,配置沒有改動的進程不會受影響而重啓
5.效果展現
redis
1.安裝shell
# 下載 git clone https://github.com/mlazarov/supervisord-monitor.git # 生成配置文件 cd supervisord-monitor/ cp application/config/supervisor.php.example application/config/supervisor.php
2.修改配置文件,添加supervisord主機
mweb08 展現名 url 服務器地址 port 端口vim
$config['supervisor_servers'] = array( 'mweb08' => array( 'url' => 'http://mweb08/RPC2', 'port' => '9001', 'username' => 'admin', 'password' => '123456' ), 'mweb07' => array( 'url' => 'http://mweb07/RPC2', 'port' => '9001', 'username' => 'admin', 'password' => '123456' ), );
3.添加nginx對supervisord-monitor的支持
server { listen 82; server_name localhost; set $web_root /data/web/supervisord-monitor/public_html; root $web_root; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $web_root$fastcgi_script_name; fastcgi_param SCHEME $scheme; } }
5.展現,重啓nginx後,訪問便可