Linux下使用Supervisord管理服务点击进入 Supervisord官方网站
部署Supervisord 安装Supervisord1 2 3 4 5 6 7 8 $ pip install supervisor $ su -c 'curl https://download.mono-project.com/repo/centos7-stable.repo | tee /etc/yum.repos.d/mono-centos7-stable.repo' $ yum install mono-devel -y $ yum install python-setuptools -y $ easy_install supervisor
配置Supervisord1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 $ echo_supervisord_conf > /etc/supervisord.conf $ cat > /usr/lib/systemd/system/supervisord.service << EOF [Unit] Description=supervisord - Supervisor process control system for UNIX Documentation=http://supervisord.org After=network.target [Service] Type=forking ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf ExecReload=/usr/bin/supervisorctl reload ExecStop=/usr/bin/supervisorctl shutdown KillMode=process Restart=on-failure RestartSec=50s [Install] WantedBy=multi-user.target EOF
编辑Supervisord需要管理的服务例如我需要Supervisord管理我的一个微服务api_server 微服务存放在/data/servers/apiapps/,启动方式是api_server server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 $ vim /data/config/supervisor/api_server.conf [program:api_server] directory=/data/servers/apiapps/ command =/data/servers/apiapps/api_server serverautostart=true autorestart=true startsecs=10 stdout_logfile=/data/servers/apiapps/log /stdout.log stdout_logfile_maxbytes=1MB stdout_logfile_backups=10 stdout_capture_maxbytes=1MB stderr_logfile=/data/servers/apiapps/log /stderr.log stderr_logfile_maxbytes=1MB stderr_logfile_backups=10 stderr_capture_maxbytes=1MB $ vim /etc/supervisord.conf [include] files = /data/config/supervisor/*.conf $ systemctl daemon-reload $ systemctl enable supervisord $ systemctl start supervisord
Supervisord常用命令1 2 3 4 5 6 $ supervisorctl start api_server $ supervisorctl stop api_server $ supervisorctl restart api_server
其实在CentOS 7中,你使用系统的Systemd管理你的微服务等其他服务已经大大满足你的所有需求了,如果你技术OK的话,哈哈