安装supervisord
yum install epel-release
yum install -y supervisor
#yum -y install python-setuptools zlib
easy_install supervisor
echo_supervisord_conf > /etc/supervisord.conf
mkdir -p /data/etc/supervisord/
mkdir -p /data2/logs/supervisord/
chmod 777 /data2/logs/supervisord/
修改 /etc/supervisord.conf
sed -i -e "s#logfile=/tmp/supervisord.log#logfile=/data2/logs/supervisord/supervisord.log#g" /etc/supervisord.conf
sed -i -e "s#file=/tmp/supervisor.sock#file=/var/run/supervisor.sock#g" /etc/supervisord.conf
sed -i -e "s#pidfile=/tmp/supervisord.pid#pidfile=/var/run/supervisord.pid#g" /etc/supervisord.conf
sed -i -e "s#serverurl=unix:///tmp/supervisor.sock#serverurl=unix:///var/run/supervisor.sock#g" /etc/supervisord.conf
echo "[include]" >> /etc/supervisord.conf
echo "files = /data/www/supervisord/*.ini" >> /etc/supervisord.conf
操作脚本:
vi /usr/lib/systemd/system/supervisord.service
#输入下面内容,并保存
[Unit]
Description=Supervisord
After=network.target
[Service]
Type=forking
PIDFile=/var/run/supervisord.pid
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecStop=/bin/kill -TERM $MAINPID
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
[Install]
WantedBy=multi-user.target
保存
#修改权限
chmod +x /usr/lib/systemd/system/supervisord.service
systemctl enable supervisord.service
启用:systemctl start supervisord
#其它控制命令
systemctl stop supervisord
systemctl reload supervisord
查看进程列表:
systemctl status supervisord
#supervisorctl status
停止进程 mq_test_worker:
supervisorctl stop mq_test_worker:
开始进程 mq_test_worker::
supervisorctl start mq_test_worker:
启动程序如果提示:Starting supervisor: 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.
unlink /var/run/supervisor.sock
sudo chmod 777 /run
sudo chmod 777 /var/log
sudo touch /var/run/supervisor.sock
sudo chmod 777 /var/run/supervisor.sock
supervisord -c /etc/supervisord.conf
ps aux | grep supervisord
最后效果
supervisord -c /etc/supervisord.conf 开启supervisord服务
supervisorctl start mq_test_worker 开启需要常驻的脚本服务
执行脚本test.php
然后tail -f mq_test_worker.log 里面可以看到队列的数据
代码附件 : msg_broker.zip
参考网站
RabbitMQ:https://www.cnblogs.com/fengyumeng/p/11133924.html
supervisord(碰到的坑):
https://www.missshi.cn/api/view/blog/5aafcf405b925d681e000000
https://www.cnblogs.com/ruanraun/p/supervisor.html
https://blog.csdn.net/weixin_41762173/article/details/88901970
声明:此文系舞林cuzn(www.wulinlw.org)原创稿件,转载请保留版权
说点什么吧