• supervisor初试


    Supervisor (http://supervisord.org) 是一个用 Python 写的进程管理工具,可以很方便的用来启动、重启、关闭进程(不仅仅是 Python 进程)。除了对单个进程的控制,还可以同时启动、关闭多个进程,比如很不幸的服务器出问题导致所有应用程序都被杀死,此时可以用 supervisor 同时启动所有应用程序而不是一个一个地敲命令启动。

    安装:

    1、首先配置epel源,这里省略

    2、安装

    yum install python-pip
    pip install supervisor

    上步骤可能遇到报错:

    pkg_resources.DistributionNotFound: meld3>=0.6.5

    解决办法:

    1. git clone https://github.com/Supervisor/meld3
    2. cd meld3
    3. python setup.py install

    安装完成后,做如下操作:

    生成默认配置文件:
    # echo_supervisord_conf > /etc/supervisord.conf
     
    简单的为nginx和weblogic服务配置,在上面生成的配置文件末尾添加:
    [program:weblogic]
    directory = /home/weblogic/Oracle/Middleware/user_projects/domains/base_domain
    command = sh startWebLogic.sh(记得weblogic的服务不要&,不要指定后台运行)
    user = weblogic
    startsecs = 90
    autorestart = true
    autostart = true
    stdout_logfile = /var/log/weblogic_stdout.log
    
    [program:nginx]
    command = /usr/sbin/nginx -c /etc/nginx/nginx.conf(配置nginx服务不要使用后台daemon运行:daemon  off;添加到nginx配置文件中)
    startsecs = 90
    autorestart = true
    autostart = true
    stdout_logfile = /var/log/nginx_stdout.log

    开启supervisor服务:

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

    查看该服务日志:

    [root@weblogic etc]# tail -f /tmp/supervisord.log                 
    2017-12-12 15:33:02,868 CRIT Supervisor running as root (no user in config file)
    2017-12-12 15:33:02,878 INFO RPC interface 'supervisor' initialized
    2017-12-12 15:33:02,878 CRIT Server 'unix_http_server' running without any HTTP authentication checking
    2017-12-12 15:33:02,880 INFO daemonizing the supervisord process
    2017-12-12 15:33:02,880 INFO supervisord started with pid 5173
    2017-12-12 15:33:03,887 INFO spawned: 'nginx' with pid 5174
    2017-12-12 15:33:03,897 INFO spawned: 'weblogic' with pid 5175
    2017-12-12 15:34:34,389 INFO success: nginx entered RUNNING state, process has stayed up for > than 90 seconds (startsecs)
    2017-12-12 15:34:34,389 INFO success: weblogic entered RUNNING state, process has stayed up for > than 90 seconds (startsecs)

    查看服务运行情况:

    [root@weblogic ~]# netstat -tunlp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
    tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      5174/nginx          
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1165/sshd           
    tcp        0      0 :::80                       :::*                        LISTEN      5174/nginx          
    tcp        0      0 :::22                       :::*                        LISTEN      1165/sshd           
    tcp        0      0 ::ffff:127.0.0.1:7001       :::*                        LISTEN      5232/java           
    tcp        0      0 fe80::20c:29ff:fe3b:78:7001 :::*                        LISTEN      5232/java           
    tcp        0      0 ::ffff:192.168.101.16:7001  :::*                        LISTEN      5232/java           
    tcp        0      0 ::1:7001                    :::*                        LISTEN      5232/java           
    tcp        0      0 :::7005                     :::*                        LISTEN      5232/java           
    udp        0      0 :::1161                     :::*                                    5232/java

    附加:上面配置文件的一些参数信息:

    [program:usercenter]
    directory = /home/leon/projects/usercenter ; 程序的启动目录
    command = gunicorn -c gunicorn.py wsgi:app  ; 启动命令,可以看出与手动在命令行启动的命令是一样的
    autostart = true     ; 在 supervisord 启动的时候也自动启动
    startsecs = 5        ; 启动 5 秒后没有异常退出,就当作已经正常启动了
    autorestart = true   ; 程序异常退出后自动重启
    startretries = 3     ; 启动失败自动重试次数,默认是 3
    user = leon          ; 用哪个用户启动
    redirect_stderr = true  ; 把 stderr 重定向到 stdout,默认 false
    stdout_logfile_maxbytes = 20MB  ; stdout 日志文件大小,默认 50MB
    stdout_logfile_backups = 20     ; stdout 日志文件备份数
    ; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件)
    stdout_logfile = /data/logs/usercenter_stdout.log
     
    ; 可以通过 environment 来添加需要的环境变量,一种常见的用法是修改 PYTHONPATH
    ; environment=PYTHONPATH=$PYTHONPATH:/path/to/somewhere
  • 相关阅读:
    BZOJ 2440: [中山市选2011]完全平方数 [容斥原理 莫比乌斯函数]
    [莫比乌斯反演]【学习笔记】[旧]
    BZOJ 3289: Mato的文件管理[莫队算法 树状数组]
    BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
    Waiting for possible shutdown message on port 4445
    linux对文件赋权限的命令chmod的详细说明
    查看防火墙状态
    Jmeter分布式测试的各种坑之jmeter-server修改ip
    linux服务器查看公网IP信息的方法
    jmeter-server中启动后端口总是不断在变化
  • 原文地址:https://www.cnblogs.com/jsonhc/p/8032802.html
Copyright © 2020-2023  润新知