1. 程式人生 > >[4]supervisor使用管理:實現對異常中斷子進程的自動重啟(以mysql為例)

[4]supervisor使用管理:實現對異常中斷子進程的自動重啟(以mysql為例)

grep -v rem iad apple mysq round true com 子進程

實現進程服務管理,supervisort監聽到進程死後,會自動將它重新拉起,很方便的做到進程自動恢復的功能,不再需要自己寫shell腳本來控制
安裝過程
1、到官網下載最新版本,解壓編譯,
tar -zxvf supervisor-3.3.4.tar.gz
cd supervisor-3.3.4
python setup.py install
可能會遇到如下錯誤:
Installed /usr/lib/python2.7/site-packages/supervisor-3.3.4-py2.7.egg
Processing dependencies for supervisor==3.3.4
Searching for meld3>=0.6.5
Reading https://pypi.python.org/simple/meld3/
Download error on https://pypi.python.org/simple/meld3/: [Errno 1] _ssl.c:504: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed -- Some packages may not be found!
Couldn't find index page for 'meld3' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: [Errno 1] _ssl.c:504: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed -- Some packages may not be found!
No local packages or download links found for meld3>=0.6.5
error: Could not find suitable distribution for Requirement.parse('meld3>=0.6.5')
解決辦法:
tar -xf meld3-1.0.1.tar.gz
cd meld3-1.0.1
python setup.py install
重新執行安裝supervisor包
生成配置文件
echo_supervisord_conf > /etc/supervisord.conf
查看配置文件
cat /etc/supervisord.conf |grep -v ";"|grep -v "^$"

[root@host-172-16-32-152 ~]# cat /etc/supervisord.conf |grep -v ";"|grep -v "^$"
[unix_http_server]
[supervisord]
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
配置WEB管理進程
[inet_http_server]
port=127.0.0.1:9001 ; 服務器ip
username=xxx ;自定義
password=xxx ;自定義
創建管理配置文件目錄
mkdir /etc/supervisord

編輯配置文件,在配置文件底部,配置include
[include]
files=/etc/supervisord/*.conf
啟動
supervisord -c /etc/supervisord.conf

#在

/etc/supervisord目錄下添加mysql一個實例的配置文件,如下:


[root@host-172-16-32-152 supervisord]# cat mysql_3306.conf
[program:mysql_3306]
#command=/etc/init.d/mysql start --port=3306 --sleep=3 --tryies=3 --daemon
command=/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/var/lib/mysql/ --pid-file=/var/lib/mysql/host-172-16-32-152.pid --basedir=/usr/local/mysql --log-error=/var/lib/mysql/mariadb.log --user=mysql
autostart=true
user=mysql
autorestart=unexpected
numprocs=1
redirect_stderr=true
startsecs=10
stdout_logfile=/var/log/block_push.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/log/block_push.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB

最後執行:

supervisorctl reload


[4]supervisor使用管理:實現對異常中斷子進程的自動重啟(以mysql為例)