一、安装服务
使用yum命令安装(推荐)
$ sudo su -
# yum install epel-release
# yum install -y supervisor
# systemctl enable supervisord
# systemctl start supervisord
# systemctl status supervisord
# ps -ef|grep supervisord
使用pip手工安装配置(不推荐)
自行百度
二、常用命令
echo_supervisord_conf > /etc/supervisord.conf
ps -ef|grep supervisord
systemctl enable supervisord
systemctl start supervisord
systemctl status supervisord
supervisorctl reload
其他:
systemctl stop supervisord
systemctl start supervisord
systemctl status supervisord
systemctl reload supervisord
systemctl restart supervisord
sudo supervisorctl restart server_name
sudo supervisorctl start server_name
sudo supervisorctl stop server_name
sudo supervisorctl status server_name
sudo supervisorctl
三、基本使用和案例
- 准备项目代码
# 此处使用go项目,需要先部署golang环境,详见Linux部署golang环境文档,其他语言项目也需要部署对应环境
vim /usr/local/server-path/go-http/http-server.go
package main
import(
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello Supervisor")
})
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
- 编译
cd vim /usr/local/server-path/go-http
go build http-server.go
- supervisor配置文件更新,使用常用的.conf文件
vim /etc/supervisord.conf
找到末尾,加上:
[include]
files = supervisord.d/*.ini
files = supervisord.d/*.conf
- 在supervisord.d/目录下新建配置test.conf
mkdir /etc/supervisord.d/test.conf
- 写入配置,更多参考:blog.csdn.net/antch620/article/det...
[program:服务名称]
directory = 服务二进制文件执行路径
command= 服务二进制文件执行路径/二进制程序名称
autostart=true
autorestart=true
startsecs=10
stdout_logfile_maxbytes=1MB
stdout_logfile_backuos=10
stderr_logfile_maxbytes=1MB
stderr_logfile_backuos=10
stderr_capture_maxbytes=1MB
- 例如本例:
[program:go-http-server]
directory = /usr/local/server-path/go-http
command= /usr/local/server-path/go-http/http-server
autostart=true
autorestart=true
startsecs=10
stdout_logfile_maxbytes=1MB
stdout_logfile_backuos=10
stderr_logfile_maxbytes=1MB
stderr_logfile_backuos=10
stderr_capture_maxbytes=1MB
- supervisor重加载配置
supervisorctl reload
systemctl restart supervisord
或者:
systemctl start supervisord
- 查看进程,可以看到新进程实现了托管
supervisorctl