linux守护进程管理

在Linux系统中,进程守护是一种常见的管理方式,它可以帮助我们监控和管理进程的运行状态,Supervisor是Linux下的一个进程守护工具,它可以帮助我们启动、停止、重启和管理进程,本文将详细介绍如何在Linux中安装配置和使用Supervisor。

Supervisor简介

Supervisor是一个C/S模式的进程管理工具,它通过fork一个supervisord进程来监听配置文件中的进程管理指令,当指定的进程出现异常时,supervisord会自动处理并重新启动该进程,supervisord还提供了进程日志记录、进程状态监控等功能。

linux守护进程管理

Supervisor的安装

1、使用包管理器安装

在基于Debian的系统(如Ubuntu)中,可以使用apt-get命令安装:

sudo apt-get update
sudo apt-get install supervisor

在基于RPM的系统(如CentOS)中,可以使用yum命令安装:

sudo yum install epel-release
sudo yum install supervisor

2、从源码编译安装

首先从官方网站下载源码包:https://github.com/supervisor/supervisor/releases

linux守护进程管理

然后解压源码包,进入解压后的目录,执行以下命令进行编译和安装:

tar xzf supervisor-x.y.z.tar.gz
cd supervisor-x.y.z
make
sudo make install

Supervisor的配置

1、创建配置文件

Supervisor的配置文件为supervisord.conf,通常位于/etc/目录下,我们可以使用任何文本编辑器创建和编辑该文件,使用vim编辑器创建一个名为supervisord.conf的文件:

sudo vim /etc/supervisord.conf

2、配置示例

以下是一个简单的supervisord.conf配置文件示例:

linux守护进程管理

[unix_http_server]
file=/tmp/supervisor.sock   ; (the path to the socket file)
chmod=0700                 ; sockef file mode (default 0700)
[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
numprocs=1                  ; (the number of autostart processes)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket
httpport=127.0.0.1:9001        ; use port 9001 for HTTP server, default is 9001

3、启动Supervisor

配置完成后,可以使用以下命令启动Supervisor:

sudo /usr/bin/supervisord -c /etc/supervisord.conf

Supervisor的使用

1、添加进程管理指令

在配置文件中添加进程管理指令,

[program:myapp]
command=/path/to/myapp           ; command to start your program
autostart=true                    ; start your program at supervisord startup (default: true)
startsecs=10                      ;  of secs prog must stay up to be considered running (default: 10)
autorestart=true                  ; when prog exits, automatically restart it (default: true)
exitcodes=0,2                     ; possible exit codes (default: 0,2)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ; if prog gives stdio to stdout/stderr, redirect to log file (default is no)                                                                                                                ; status check method, empty means use default status check function (default: status)                           ; directory to store the program's log files (default is <logdir>/<progname>)                        ; maximum number of seconds that the program will be allowed to run without generating an error message (default: 3600)       ; wait that many seconds after the process has started before sending SIGKILL to it if it doesn't exit on its own within <startsecs> seconds (default: 75)     ; if set, send a SIGKILL signal to the program if it doesn't exit after <stopwaitsecs> seconds after receiving a SIGTERM (default: false)    ; stop program with SIGINT (default: true)                                                              ; stop program when receiving SIGTERM, SIGINT and SIGQUIT (default: true)                                                              ; stop program when SIGWINCH occurs (default: false)                           ; how to send SIGKILL to the program: 'SIGKILL' will send SIGKILL to all processes in the process group (default: 'SIGTERM')   ; kill only processes belonging to this group, when sending a signal to the master process (default: false)                    ; whether or not to clear environment from the process (default: false)                           ; whether or not to set umask in the process (default: false)                                                              ; whether or not to create a lock file as PID directory (default: false)                           ; if set, don't change working directory in the child process (default: false)                                                              ; if set, don't chdir to the cwd specified in the config file in the child process (default: false)                                                              ; extra arguments to be passed to the program (default: none)                           ; logging level for syslog messages of this process (default: notice)                           ; syslog facility for logging messages of this process (default: daemon)                           ; setsid() call in the child process (default: true)                                                              ; whether or not to create a private temporary directory for this process (default: false)                       ; whether or not to create a private user ID for this process (default: false)                           ; whether or not to cleanup service connection files after process termination (default: true)                       ; whether or not to reset standard I/O handles after process termination (default: true)                       ; whether or not to execute a custom prestart script before starting the process (default: false)                       ; whether or not to execute a custom poststart script after starting the process (default: false)                       ; whether or not to execute a custom prestop script before stopping the process (default: false)                       ; whether or not to execute a custom poststop script after stopping the process (default: false)                       ; whether or not to execute a custom postrestart script after stopping and re-starting the process (default: false)      ; command to execute when killing process (default: kill -TERM {{process_name}}). Note that this is executed with root privileges!               ; command to execute when starting process (default: "")                           ; command to execute when stopping process (default: "kill -TERM {{process_name}}")                           ; command to execute when resuming process after stoppage (default: "")                           ; command to execute when attempting to daemonize a process that requires it (default: "")                           ; name of the xinetd style init script that will be called instead of starting the process directly (default: "")         ; additional environment variables you want to set in this process's environment (default: none)                   ; other valid key-value pairs are passed as-is to the program specified in "command"                                ; see full documentation at http://supervisord.org/configuration.htmlprogram-x-section-settings for details about these options.                                                                                                          ; note that all settings in this section are optional!                                                                        ; [program:myapp]                                                                                                          ; [group:one]                                                                                                           ; programs = one two three                                                               ; [program:one]                                      -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------																																										[program:two]                                      ----------------------------------------------------------------------------------------------------------------

原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/337127.html

Like (0)
Donate 微信扫一扫 微信扫一扫
K-seo的头像K-seoSEO优化员
Previous 2024-02-28 12:28
Next 2024-02-28 12:32

相关推荐

  • 在Linux系统中,MySQL数据库文件存储在哪个目录下?

    在Linux系统中,MySQL数据库文件的默认位置通常位于"/var/lib/mysql"目录下。这个目录包含了所有的数据库和表的数据文件。

    2024-07-24
    076
  • linux html图片路径怎么写

    在Linux操作系统中,HTML图片路径的编写与Windows系统有所不同,在Windows系统中,路径通常使用反斜杠(\)作为分隔符,而在Linux系统中,路径则使用正斜杠(/)作为分隔符,以下是关于如何在Linux中编写HTML图片路径的详细介绍。绝对路径与相对路径1、绝对路径绝对路径是从根目录开始的完整路径,在Linux系统中,……

    2024-02-06
    0252
  • Linux系统下 centos7下搭建ElasticSearch中间件及常用接口演示

    在Linux系统下,CentOS7是一个非常流行的操作系统,广泛应用于服务器环境中,ElasticSearch是一个基于Lucene的搜索服务器,它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口,Elasticsearch是用Java开发的,并作为Apache许可条款下的开源发布,是当前主流的企业级搜索引擎,……

    2024-03-04
    0213
  • linux的yum源怎么配

    Linux下yum源配置1、添加yum源在Linux系统中,我们可以通过编辑/etc/yum.repos.d/目录下的.repo文件来添加yum源,以添加阿里云的yum源为例,首先创建一个新的.repo文件:sudo vi /etc/yum.repos.d/aliyun-release.repo然后将以下内容粘贴到文件中:[aliyu……

    2023-12-24
    0209
  • Linux系统中pwd命令的使用技巧

    在Linux系统中,pwd命令是一个非常实用的命令,它可以显示当前工作目录的绝对路径,本文将详细介绍pwd命令的使用技巧,帮助大家更好地理解和掌握这个命令。pwd命令简介1、功能:显示当前工作目录的绝对路径。2、语法:pwd [选项]。3、常用选项: -L:显示长格式的绝对路径。 -P:显示绝对路径,但不包括&quot;/&a……

    2023-12-23
    0403
  • linux和vxworks的区别有哪些

    Linux和VxWorks都是操作系统,但是它们之间有很多区别,下面是一些主要的区别:1、架构:Linux是基于UNIX的开源操作系统,而VxWorks是专有的实时操作系统。2、内存管理:Linux使用虚拟内存技术,而VxWorks使用分页和段页表管理内存。3、多任务处理:Linux支持多任务处理,而VxWorks也支持多任务处理,但……

    2023-12-14
    0380

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

免备案 高防CDN 无视CC/DDOS攻击 限时秒杀,10元即可体验  (专业解决各类攻击)>>点击进入