当前位置:首页 > 实用技巧 >

gg修改器怎样运行守护进程(gg修改器守护进程怎么设置)

来源:原点资讯(www.yd166.com)时间:2023-11-16 14:20:52作者:YD166手机阅读>>

supervisor是用python开发的一个在linux系统下的进程管理工具, 可以方便的监听, 启动, 停止一个或多个进程。当一个进程被意外*死后, supervisor监听到后, 会自动重新拉起进程。

Supervisord 是用 Python 实现的一款非常实用的进程管理工具, supervisord 还要求管理的程序是非 daemon 程序, supervisord 会帮你把它转成 daemon 程序, 因此如果用 supervisord 来管理 NGINX 的话,

必须在 nginx 的配置文件里添加一行设置 daemon off 让 nginx 以非 daemon 方式启动。

程序崩溃或者退出Supervisord会自动启动程序。这样就再不也不怕go的执行文件挂掉或者退出或者死掉, Supervisord只要监控到异常状态就会重启执行文件并且记录日志。

官网:

http://supervisord.org/

一、supervisor的安装

1、通过easy_install安装

yum -y install python-setuptools

easy_install supervisor

2、通过yum安装

yum -y install supervisor

3、通过pip安装

yum -y install epel-release

yum -y install python-pip

pip install supervisor

安装好后, 会生成三个执行命令, echo_supervisord_conf, supervisorctl, supervisord。

注意:安装方式推荐第三种方式, 能够优先下载最新版本

二、supervisor的配置文件

supervisor的默认配置文件在 /etc/supervisord.conf 下, 如果没有可以通过如下命令生成

echo_supervisord_conf > /etc/supervisord.conf

常用的配置项如下:

[unix_http_server]

file=/tmp/supervisor.sock ; unix socket文件,supervisorctl会使用

;chmod=0700 ; socket文件权限

;chown=nobody:nogroup ; socket文件所属用户和用户组

[inet_http_server] ; web管理界面

port=127.0.0.1:9001 ; 管理界面的IP和端口

username=admin ; 登陆管理界面的用户名

password=123456 ; 登陆管理界面的密码

[supervisord]

logfile=/tmp/supervisord.log ; 日志文件

logfile_maxbytes=50MB ; 日志文件大小,为0表示不限制

logfile_backups=10 ; 日志文件备份数量,为0表示不备份

loglevel=info ; 日志级别,也可设置为 debug,warn,trace

pidfile=/tmp/supervisord.pid ; PID文件路径

nodaemon=false ; 是否前台启动,为false表示守护进程方式

minfds=1024 ; 打开文件描述符的最小值

minprocs=200 ; 创建进程数的最小值

[supervisorctl]

serverurl=unix:///tmp/supervisor.sock ; 通过 unix sokcet 连接supervisord

;serverurl=http://127.0.0.1:9001 ; 通过http方式连接supervisord

[include]

files = /etc/supervisord/confs/*.conf ; 包含其他配置文件,可以是.conf或.ini

我们需要把 [include] 前面的注释打开,并配置 files 的路径。

创建 files 中配置的目录。

mkdir -p /etc/supervisord/confs/

启动supervisor

> # supervisord -c /etc/supervisord.conf

三、管理进程。

管理进程, 需要我们启动 supervisor 服务, 这里我们配置 systemctl, 开机自动启动 supervisor。

创建 /usr/lib/systemd/system/supervisord.service 文件, 配置如下:

[Unit]

Description=Supervisor daemon

[Service]

Type=forking

ExecStart=/usr/bin/supervisord

ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown

ExecReload=/usr/bin/supervisorctl $OPTIONS reload

KillMode=process

Restart=on-failure

RestartSec=42s

[Install]

WantedBy=multi-user.target

启用配置

systemctl enable supervisord.service

启动 supervisord

systemctl start supervisord.service

成功后, 就可以通过 supervisorctl 交互命令管理进程脚本了。

读取有更新的配置文件

supervisorctl reread

更新配置文件修改过的程序

supervisorctl update

如果修改过 /etc/supervisord.conf 请使用如下命令

supervisorctl reload

启动, 停止, 重启, 程序。

supervisorctl start 程序名

supervisorctl stop 程序名

supervisorctl restart 程序名

supervisorctl restart all; 重启所有应用

supervisorctl stop all; 停止所有应用

supervisorctl start all; 启动所有应用

四、supervisor图形化管理界面

需要开启 /etc/supervisord.conf 文件中的 [inet_http_server]

[inet_http_server]

port=0.0.0.0:9001

username=admin

password=123456

设置完后, 要开放 9001 端口, 并重启 supervisor

># firewall-cmd --zone=public --add-port=9001/tcp --permanent

># firewall-cmd --reload

重启 supervisor

># supervisorctl reload

访问面板

http://192.168.199.128:9001/

账号:admin 密码:123456

获取安装的版本:

> # supervisorctl version

4.2.0

五、安装nginx

> # cd ~

> # wget http://nginx.org/download/nginx-1.13.8.tar.gz

> # tar -zxvf nginx-1.13.8.tar.gz

> # cd nginx-1.13.8

> # ./configure --prefix=/usr/local/nginx --with-http_ssl_module

> # make && make install

> # echo $?

0

给Nginx添加启动脚本配置文件, Nginx启动脚本配置文件不自带的, 需要在/etc/init.d目录下创建配置文件nginx。

vim /etc/init.d/nginx

#!/bin/bash # chkconfig: - 30 21 # description: http service. # Source Function Library . /etc/init.d/functions # Nginx Settings NGINX_SBIN="/usr/local/nginx/sbin/nginx" NGINX_CONF="/usr/local/nginx/conf/nginx.conf" NGINX_PID="/usr/local/nginx/logs/nginx.pid" RETVAL=0 prog="Nginx" start() { echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL } reload() { echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL } restart() { stop start } configtest() { $NGINX_SBIN -c $NGINX_CONF -t return 0 } case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1 esac exit $RETVAL

> # chmod 755 /etc/init.d/nginx

> # chkconfig --add nginx

> # chkconfig nginx on

Nginx本身自带nginx.conf配置文件, 这里不使用它自带的

> # cd /usr/local/nginx/conf

> # mv nginx.conf nginx.conf.bak

> # vim nginx.conf

user nobody nobody; worker_processes 2; error_log /usr/local/nginx/logs/nginx_error.log crit; pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 6000; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 3526; server_names_hash_max_size 4096; log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' ' $host "$request_uri" $status' ' "$http_referer" "$http_user_agent"'; sendfile on; tcp_nopush on; keepalive_timeout 30; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; connection_pool_size 256; client_header_buffer_size 1k; large_client_header_buffers 8 4k; request_pool_size 4k; output_buffers 4 32k; postpone_output 1460; client_max_body_size 10m; client_body_buffer_size 256k; client_body_temp_path /usr/local/nginx/client_body_temp; proxy_temp_path /usr/local/nginx/proxy_temp; fastcgi_temp_path /usr/local/nginx/fastcgi_temp; fastcgi_intercept_errors on; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 8k; gzip_comp_level 5; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css text/htm application/xml; server { listen 80; server_name 192.168.0.33; index index.html index.htm index.php; root /usr/local/nginx/html; location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/tmp/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; } } }

配置环境变量

> # vim /etc/profile.d/nginx.sh

export PATH=/usr/local/nginx/sbin:$PATH

> # source /etc/profile.d/nginx.sh

测试nginx配置语法

> # nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

> # /etc/init.d/nginx restart

开放端口号

> # firewall-cmd --permanent --zone=public --add-port=80/tcp

> # firewall-cmd --reload

浏览器访问:

http://192.168.117.131:9001/

> # vim /etc/supervisord/confs/nginx.conf

[program:nginx]

command = /usr/local/nginx/sbin/nginx -g 'daemon off;'

startsecs = 3

autostart = true

autorestart = true

user = root

stderr_logfile = /tmp/nginx-error.log

stdout_logfile = /tmp/nginx.out.log

修改后记得更新 Supervisor 以及重启 Nginx 进程, 命令:

> # supervisorctl reread # 重新读取配置

> # supervisorctl update # 更新配置

> # supervisorctl reload # 重启 supervisor

六、邮件报警

安装superlance

> # pip install superlance

下载和安装sendEmail

> # wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz

> # tar -zxvf sendEmail-v1.56.tar.gz

> # cp sendEmail-v1.56/sendEmail /usr/bin/sendemail

发送邮件的格式

sendemail -f 发件人邮箱 -t 收件人邮箱 -s 发件人邮箱smtp服务器 -u "sendEmail" -m "haha" -xu 发件人 -xp 发件人邮箱密码

-f 发件人

-t 收件人

-s 发件人smtp服务器

-u 主题

-m 内容

-xu 发件人用户名

-xp 发件人密码

> # vim /etc/supervisord/confs/mail.conf

[eventlistener:crashmail-exited]

command=crashmail -a -s "/usr/bin/sendemail -f xxxxxx@163.com -t xxxxxx@qq.com -s smtp.163.com -u 'nginx' -xu xxxxxxx@163.com -xp xxxxxxxx -m" -m xxxxxxxx@qq.com

events=PROCESS_STATE_EXITED

redirect_stderr=false

问题:

> # supervisorctl reread

Server requires authentication

......

解决方法: 需要输入账号和密码

> # supervisorctl

Server requires authentication

Username:admin

Password:123456

发布日期: 20220623

操作系统: CentOS7.6

PHP版本: PHP7.2.31

测试日期: 20220623

栏目热文

gg修改器怎么启动守护模式(gg修改器怎么开启守护进程教学)

gg修改器怎么启动守护模式(gg修改器怎么开启守护进程教学)

写在前面之前分享过两篇比亚迪宋Plus DM-i 110KM版本使用一年的心得,以及相关的槽点,得到了很多车友和网友的支...

2023-11-16 14:48:59查看全文 >>

容颜和相貌的区别(外貌与容貌有什么区别)

容颜和相貌的区别(外貌与容貌有什么区别)

年轻和年老的人脸差别很大,即使抹平皮肤表面的皱纹,我们也能看出形状不同。因为年龄增长不仅让表面皮肤失去弹性和光泽,深层的...

2023-11-16 14:43:54查看全文 >>

生理成熟的定义(怎么算生理成熟)

生理成熟的定义(怎么算生理成熟)

成熟有几种不同的意思进行分别是什么成熟有两种含义:(1)是指生理成熟,即身体各器官的形态、结构和功能发育到一个完整的状态...

2023-11-16 14:50:51查看全文 >>

生理年龄特征含义(生理年龄和实际年龄的区别)

生理年龄特征含义(生理年龄和实际年龄的区别)

一.什么是老年人国内外老年人学家对老年人的定义有十几种观点,世界卫生组织和卫生部规定,60岁以上老年人。但在现实中,不难...

2023-11-16 14:50:54查看全文 >>

容颜和面貌的区别(容颜和容貌区别是什么)

容颜和面貌的区别(容颜和容貌区别是什么)

387“颜”和“貌”有何区别?“顏”是眉目之间面容脸色者。“顏”读yán ㄧㄢˊ 。“彦”读yàn ㄧㄢˋ。“页”、“彦...

2023-11-16 14:55:58查看全文 >>

gg修改器怎么设置守护进程(gg修改器怎样获得守护进程)

gg修改器怎么设置守护进程(gg修改器怎样获得守护进程)

Haproxy调度器介绍和配置文件详解1.haproxy介绍 (四层TCP和七层HTTP都可用)是一个开源的、高性能的基...

2023-11-16 14:38:36查看全文 >>

gg 修改器怎么开启守护进程(gg修改器要怎么开守护进程)

gg 修改器怎么开启守护进程(gg修改器要怎么开守护进程)

第一章 概 述继电保护测试装置是保证电力系统安全可靠运行的一种重要测试工具。随着现代电力系统规模的不断扩大,对电力系统运...

2023-11-16 14:11:35查看全文 >>

gg修改器怎么才可以启动守护模式(gg修改器守护模式在哪)

gg修改器怎么才可以启动守护模式(gg修改器守护模式在哪)

图源自视觉中国人脸识别一键开启,小孩再也不能熬夜肝游戏了。7月5日,腾讯游戏正式上线“零点巡航”功能,旨在对夜间游戏超过...

2023-11-16 14:11:22查看全文 >>

gla200自动启停可以长期开吗(gla200自动启停打开没反应)

gla200自动启停可以长期开吗(gla200自动启停打开没反应)

启停这个功能,刚换车的时候觉得这东西挺好玩的而且一四年的时候有启停功能的车也不是很多所以每次只要启动之后这个功能就一直开...

2023-11-16 14:33:53查看全文 >>

奔驰gla200自动启停功能怎么关闭(奔驰gla200怎么关掉车子启停功能)

奔驰gla200自动启停功能怎么关闭(奔驰gla200怎么关掉车子启停功能)

实测车型奔驰GLA260 年款:2016年 VIN:LE40*************操作指引1. 进行自动搜索,如图1...

2023-11-16 14:29:40查看全文 >>

文档排行