參考環(huán)境:
centos 6.5
1、Beanstalkd
Beanstalkd,一個(gè)高性能、輕量級(jí)的分布式內(nèi)存隊(duì)列系統(tǒng),最初設(shè)計(jì)的目的是想通過(guò)后臺(tái)異步執(zhí)行耗時(shí)的任務(wù)來(lái)降低高容量Web應(yīng)用系統(tǒng)的頁(yè)面訪問(wèn)延遲,支持過(guò)有9.5 million用戶的Facebook Causes應(yīng)用。后來(lái)開(kāi)源,現(xiàn)在有PostRank大規(guī)模部署和使用,每天處理百萬(wàn)級(jí)任務(wù)。Beanstalkd是典型的類Memcached設(shè)計(jì),協(xié)議和使用方式都是同樣的風(fēng)格,所以使用過(guò)memcached的用戶會(huì)覺(jué)得Beanstalkd似曾相識(shí)。
參考鏈接:
Beanstalkd
Beanstalkd介紹
Beanstalkd安裝
1、安裝Beanstalkd
# yum install beanstalkd
2、開(kāi)啟Beanstalkd
》Usage: beanstalkd -l [ip address] -p [port #]
# beanstalkd -l 127.0.0.1 -p 11301 &
如果安裝包管理器(i.e. aptitude),你將能夠管理Beanstalkd作為服務(wù)守護(hù)進(jìn)程。
》 To start the service:
# service beanstalkd start
》 To stop the service:
# service beanstalkd stop
》 To restart the service:
# service beanstalkd restart
》 To check the status:
# service beanstalkd status
2、Supervisor
C/S架構(gòu)的進(jìn)程控制系統(tǒng),可使用戶在類UNIX系統(tǒng)中監(jiān)控、管理進(jìn)程。常用于管理與某個(gè)用戶或項(xiàng)目相關(guān)的進(jìn)程。
參考鏈接:
Supervisor官網(wǎng)
參考1
參考2
參考3
參考4
1、安裝Supervisor
1、安裝python自動(dòng)化工具
# yum install python-setuptools
2、安裝supervisor
# easy_install supervisor
3、測(cè)試安裝是否成功
# echo_supervisord_conf
2、修改配置
1、創(chuàng)建配置文件
# mkdir -m 755 -p /etc/supervisor/
# echo_supervisord_conf > /etc/supervisor/supervisord.conf
2、編輯配置文件
在supervisord.conf最后增加如下:
[program:test]
command=/opt/soft/php/bin/php /home/m/test/app/cli.php ;被監(jiān)控進(jìn)程
;process_name=%(process_num)02d
;numprocs=5 ;啟動(dòng)幾個(gè)進(jìn)程
autostart=true ;隨著supervisord的啟動(dòng)而啟動(dòng)
autorestart=true ;自動(dòng)啟動(dòng)
startsecs=1 ;程序重啟時(shí)候停留在runing狀態(tài)的秒數(shù)
startretries=10 ;啟動(dòng)失敗時(shí)的最多重試次數(shù)
stderr_logfile=/tmp/supervisor/test_err.log ;錯(cuò)誤日志
stdout_logfile=/tmp/supervisor/test.log ;日志
3、啟動(dòng)supervisor
1、啟動(dòng)supervisor
# supervisord -c /etc/supervisor/supervisord.conf
# pstree -p | grep supervisord 查看supervisord進(jìn)程
2、進(jìn)入supervisor管理
# supervisorctl -c /etc/supervisor/supervisord.conf
status 查看狀態(tài)
》test RUNNING pid 2554,uptime 0:00:10
stop all停止
reload重啟監(jiān)控服務(wù)
注意:
(1)每次修改配置文件后**需進(jìn)入supervisorctl,
執(zhí)行reload**, 改動(dòng)部分才能生效。
(2)兩個(gè)命令
supervisord :
supervisor的服務(wù)器端部分,用于supervisor啟動(dòng)
supervisorctl:
啟動(dòng)supervisor的命令行窗口,在該命令行中可執(zhí)行start、stop、status、reload等操作。
錯(cuò)誤:
Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
解決:
sudo unlink /tmp/supervisor.sock
or
sudo unlink /var/run/supervisor.sock