惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

Supervisord - 标签 - cywhat's blog

暂无文章

supervisord管理常驻进程uwsgi/nginx/redis/mongodb
cywhat · 2021-05-24 · via Supervisord - 标签 - cywhat's blog

解决部署的一些项目,因机器关机/重启导致项目需要手动重新启动的问题

1.安装supervisor(3种选一种)

1
2
3
4
5
6
7
8
#yum安装
yum install supervisor

#pip安装
pip install supervisor

#easy_install安装
easy_install supervisor

2.配置supervisor

1
2
3
4
5
#生成配置supervisor文件
echo_supervisord_conf > /etc/supervisord.conf

#创建存放配置文件目录
mkdir -p /etc/supervisord.d/conf

3.修改默认配置

1
2
3
#文件最后一行,目录修改为配置文件地址,我的.ini文件是在/etc/supervisord.d/conf/存放,而且本身配置文件也在etc中,所以目录直接写supervisord.d/conf/就可以了
[include]
files = /etc/supervisord.d/conf/*.ini

4.通过配置文件启动supervisor

1
2
#这里一定要用配置文件的绝对路径
$ supervisord -c /etc/supervisord.conf

5.设置开机自启动

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#打开文件
vim /lib/systemd/system/supervisor.service

# 输入内容
[Unit]
Description=supervisor
After=network.target

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

# 保存并开启
:wq

systemctl enable supervisor.service

6.编写要管理进程的配置文件

1
2
#因为我这里配置文件中通配符是以.ini结尾 所以新建的文件后缀为.ini
$ touch uwsgi.ini
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#uwsgi 配置如下
$ [program:uwsgi]  #uwsgi这个名称是管理进程的别名,可以自定义
  user=root #启动用户
  command=/root/pyenv/myenv/bin/uwsgi --ini  /root/pyenv/myenv/my_uwsgi.ini   #启动的命令
  directory=/root/pyenv/myenv    #文件目录
  autostart=true   #是否跟随supervisor启动
  autorestart=true   #程序故障是否重启
  stopasgroup=true   #
  startsecs=3   #启动3s后无异常判断为正常
  startretries=3   #启动尝试次数
  redirect_stderr=true   #把stderr重定向到stdout,默认为flase
  stdout_logfile=/var/log/uwsgi_out.log   #标准输出日志路径 这里一定要把uwsgi本身的日志输出关掉
  stderr_logfile=/var/log/uwsgi_err.log   #输出错误日志路径

7.启动应用

1
2
3
4
5
6
7
8
#重启supervisor配置中的所有程序
supervisorctl reload

#查看supervisor状态 出现启动项目name即可
supervisorctl status

#重启单个应用
supervisorctl restart uwsgi

8.supervisor命令详解

1
2
3
4
5
6
7
8
supervisorctl restart <application name>  #重启指定应用
supervisorctl stop <application name>  #停止指定应用
supervisorctl start <application name>  #启动指定应用
supervisorctl restart all  #重启所有应用
supervisorctl stop all  #停止所有应用
supervisorctl start all  #启动所有应用
supervisorctl update  #配置文件修改后可以使用该命令加载新的配置
supervisorctl reload  #重新启动配置中的所有程序

9.其他配置

1.nginx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[program:nginx]
user=root
directory=/usr/local/nginx
command=/usr/local/nginx/sbin/nginx -g 'daemon off;'
autostart=true
autorestart=true
stopasgroup=true
startsecs=10
startretries=5
stopasgroup=true
redirect_stderr=true
stdout_logfile=/etc/supervisord.d/logs/nginx/nginx_out.log
stderr_logfile=/etc/supervisord.d/logs/nginx/nginx_err.log

2.redis

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[program:redis]
user=root
directory=/usr/local/redis
command=/usr/local/redis/bin/redis-server redis.conf
autostart=true
autorestart=true
stopasgroup=true
startsecs=10
startretries=5
stopasgroup=true
redirect_stderr=true
stdout_logfile=/home/cywhat/logs/redis/redis_out.log
stderr_logfile=/home/cywhat/logs/redis/redis_err.log

注意事项

使用supervisorctl status查看发现有进程被不断重启,报错如下:

1
#XXX(项目名)      FATAL     Exited too quickly (process log may have details)
原因:

```bash
supervisor只支持前台程序的托管到后台 #(启动前需要kill掉已经存在的进程),例如:

    #uwsgi
    uwsgi如果出现不断重启,一定是启动命令中加了-d的参数,去掉就好了

    #redis
    redis就需要把redis.conf配置文件中的daemonize设置为no

    #nginx
    nginx就需要在命令行后缀增加 -g ‘daemon off;’

    #mongodb
    mongodb如果不断重启,多半也是因为启动命令中加了后台运行的参数 & 同样的去掉就可以了

关注一下再走吧

公众号 小程序

赞赏支持

微信打赏 支付宝打赏