侧边栏壁纸
博主头像
一揽芳华 博主等级

行动起来,活在当下

  • 累计撰写 265 篇文章
  • 累计创建 24 个标签
  • 累计收到 4 条评论

目 录CONTENT

文章目录

04.使用supervisord管理nginx

芳华是个男孩!
2024-10-14 / 0 评论 / 0 点赞 / 16 阅读 / 0 字
广告 广告

title: 04-管理nginx
order: 4

icon: lightbulb

1.启动一个容器

[root@172-0-110-100 ~]# docker run -itd --name supervisor_nginx -p 80:80 -p 9002:9001 --privileged=true supervisor:1.0 /usr/sbin/init

2.修改配置文件信息,实现可以web访问

[root@172-0-110-100 ~]# docker exec -it supervisor_nginx bash
[root@01b7074f700e /]# vim /etc/supervisord.conf
……
[inet_http_server]         ; inet (TCP) server disabled by default
port=172.17.0.3:9001        ; (ip_address:port specifier, *:port for all iface)
username=user              ; (default is no username (open server))
password=123               ; (default is no password (open server))
……
## 结束掉旧的的supervisord进程,重新启动
[root@01b7074f700e /]# ps -ef |grep supervisord
root          99       1  0 09:00 ?        00:00:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
root         103      72  0 09:02 pts/1    00:00:00 grep --color=auto supervisord
[root@01b7074f700e /]# kill 99
[root@01b7074f700e /]# supervisord -c /etc/supervisord.conf 
[root@01b7074f700e /]# ps -ef |grep supervisord
root         107       1  0 09:03 ?        00:00:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
root         109      72  0 09:03 pts/1    00:00:00 grep --color=auto supervisord

3.安装nginx服务

[root@01b7074f700e /]# yum install nginx -y
[root@01b7074f700e /]# nginx -v
nginx version: nginx/1.20.1

4.编写nginx在supervisor子进程里面的配置文件

[root@01b7074f700e /]# cd /etc/supervisord.d/
[root@01b7074f700e supervisord.d]# vim nginx.ini
##设置进程的名称,使用 supervisorctl 来管理进程时需要使用该进程名 我这里就叫做nginx了!
[program:nginx]
##命令执行的目录或者说执行 command 之前,先切换到工作目录 可以理解为在执行命令前会切换到这个目录 在我这基本没啥用
directory=/etc/nginx
##需要执行的命令,以前台方式运行
command=/usr/sbin/nginx -g 'daemon off;'
##是否自动启动
autostart=true
##程序意外退出是否自动重启
autorestart=true
##如果为true,则stderr的日志会被写入stdout日志文件中  理解为重定向输出的日志
redirect_stderr=true
##启动优先级
priority=10
##子进程的stdout的日志路径 输出日志文件
stdout_logfile=/data/logs/supervisord/nginx.log
##错误日志文件 当redirect_stderr=true。这个就不用
stderr_logfile=/data/logs/supervisord/nginx.err.log
[root@01b7074f700e supervisord.d]# mkdir /data/logs/supervisord/ -p

5.启动supervisor服务,查看nginx是否启动

[root@01b7074f700e ~]# supervisorctl reload       ##或者命令:supervisorctl update
Restarted supervisord
[root@01b7074f700e ~]# ps -ef | grep nginx
root         199     107  0 09:19 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon off;
nginx        200     199  0 09:19 ?        00:00:00 nginx: worker process
nginx        201     199  0 09:19 ?        00:00:00 nginx: worker process
nginx        202     199  0 09:19 ?        00:00:00 nginx: worker process
nginx        203     199  0 09:19 ?        00:00:00 nginx: worker process
root         208      72  0 09:19 pts/1    00:00:00 grep --color=auto nginx

通过supervisor服务的web端口查看nginx服务

6.手动停止nginx服务,查看supervisor是否能启动nginx服务

[root@01b7074f700e ~]# systemctl stop nginx
[root@01b7074f700e ~]# ps -ef | grep nginx
root         199     107  0 09:19 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon off;
nginx        200     199  0 09:19 ?        00:00:00 nginx: worker process
nginx        201     199  0 09:19 ?        00:00:00 nginx: worker process
nginx        202     199  0 09:19 ?        00:00:00 nginx: worker process
nginx        203     199  0 09:19 ?        00:00:00 nginx: worker process
root         213      72  0 09:22 pts/1    00:00:00 grep --color=auto nginx
[root@01b7074f700e ~]# 

点击web控制台stop按钮,查看nginx服务是否运行

[root@01b7074f700e ~]# ps -ef | grep nginx
root         233      72  0 09:27 pts/1    00:00:00 grep --color=auto nginx

点击web控制台start按钮,查看nginx服务是否运行

[root@01b7074f700e ~]# ps -ef | grep nginx
root         223     107  0 09:26 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon off;
nginx        224     223  0 09:26 ?        00:00:00 nginx: worker process
nginx        225     223  0 09:26 ?        00:00:00 nginx: worker process
nginx        226     223  0 09:26 ?        00:00:00 nginx: worker process
nginx        227     223  0 09:26 ?        00:00:00 nginx: worker process
root         231      72  0 09:27 pts/1    00:00:00 grep --color=auto nginx
0
广告 广告

评论区