Circus是一个Python程序,用来监控和控制进程和套接字。
Circus可以通过命令行接口、web接口或者以编程的方式调用它的Python接口。
在centos7中安装circus
pip install circus
配置circus
mkdir /etc/circus
vi /etc/circus/circus.ini
[circus]
check_delay = 5
include_dir = /etc/circus/conf.d
logoutput = /var/log/circus/system.log
statsd = True
创建服务
vi /etc/systemd/system/circus.service
[Unit]
Description=Circus process manager
After=syslog.target network.target nss-lookup.target
[Service]
Type=simple
ExecReload=/usr/bin/circusctl reload
ExecStart=/usr/bin/circusd /etc/circus/circus.ini
Restart=always
RestartSec=5
[Install]
WantedBy=default.target
创建日志文件
mkdir /var/log/circus
启动服务
service circus start
设置开机启动
systemctl enable circus
配置好项目.ini
例如:
vi /etc/circus/conf.d/myproject.ini
[watcher:myproject]
cmd = gunicorn myproject.wsgi #程序启动 非Django项目 直接python 文件.py
working_dir = /root/myproject
autostart = true
[env:myproject]
PATH=/root/.pyenv/versions/env363/bin:$PATH
PYTHONPATH=/root/.pyenv/versions/env363/lib/python3.6
SHELL = /bin/bash
HOME = /root/myproject
手工启动circus
circusd /etc/circus/circus.ini
[2017-12-05 15:20:26 +0800] [10938] [INFO] Starting gunicorn 19.7.1
[2017-12-05 15:20:26 +0800] [10938] [INFO] Listening at: http://127.0.0.1:8000 (10938)
[2017-12-05 15:20:26 +0800] [10938] [INFO] Using worker: sync
[2017-12-05 15:20:26 +0800] [10954] [INFO] Booting worker with pid: 10954
此时查看端口 netstat -ntl 看到
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5555 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5556 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5557 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:32000 0.0.0.0:* LISTEN
启动时可能会出现的坑
在手工启动命令输入后出现以下内容
此时并没有报错,但是circus就是启动不了,看第一行提示tornado/gen.py....
技术老大让尝试降低tornado的版本为4.5.3就成功了,因为系统中安装tornado会安装最新版本,circus不兼容,就会导致circus启动不了。(虽然我还是不能理解我部署Django项目跟tornado有毛线关系,但是问题就这样解决了,为什么要用circus,被这个折磨的快哭了!)
更新
现在在系统默认的Python2下面直接 pip install circus 直接连tornado4.5.3一块安装了