superisor服务管理

superisor服务管理

superisor服务安装

  1. 安装
    sudo apt install supervisor
  2. 服务启动
    • 启动:systemctl start supervisor
    • 停用:systemctl stop supervisor
    • 状态:systemctl status supervisor
    • 开机启动:systemctl enable supervisor
    • 重载:systemctl reload supervisor
  3. 服务命令
    查看当前运行的进程列表:supervisorctl status

    其他命令:
    update 更新新的配置到supervisord(不会重启原来已运行的程序)
    reload,载入所有配置文件,并按新的配置启动、管理所有进程(会重启原来已运行的程序)
    start xxx: 启动某个进程
    restart xxx: 重启某个进程
    stop xxx: 停止某一个进程(xxx),xxx为[program:theprogramname]里配置的值
    stop groupworker: 重启所有属于名为groupworker这个分组的进程(start,restart同理)
    stop all,停止全部进程,注:start、restart、stop都不会载入最新的配置文
    reread,当一个服务由自动启动修改为手动启动时执行一下就ok

    带账户验证:supervisorctl -u admin -p Transfar@123 restart xxx

  4. 服务配置

    • supervisor参考配置(/etc/supervisor/supervisord.conf)
      
      ; supervisor config file

    [unix_http_server] file=/var/run/supervisor.sock ; (the path to the socket file) chmod=0700 ; sockef file mode (default 0700)

    [supervisord] logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)

    ; the below section must remain in the config file for RPC ; (supervisorctl/web interface) to work, additional interfaces may be ; added by defining them in separate rpcinterface: sections [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

    [supervisorctl] serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket ;serverurl=http://127.0.0.1:9001 ; The [include] section can just contain the "files" setting. This ; setting can list multiple files (separated by whitespace or ; newlines). It can also contain wildcards. The filenames are ; interpreted as relative to this file. Included files cannot ; include files themselves.

    [inet_http_server] ;cpu等资源占用高,可注释掉web功能 port=9001 username=
    password=

    [include] files = /etc/supervisor/conf.d/*.conf

    - 添加服务参考配置(/etc/supervisor/conf.d/**.conf)
    ```config
    [program:superisor-manage]                                                                                                                                                                                           
    directory = /opt/apps/cesi ; 程序的启动目录                                                                                                                                                                          
    command = python3 cesi/run.py                                                                                                                                                                                        
    autostart = true     ; 在 supervisord 启动的时候也自动启动                                                                                                                                                           
    startsecs = 5        ; 启动 5 秒后没有异常退出,就当作已经正常启动了                                                                                                                                                 
    autorestart = true   ; 程序异常退出后自动重启                                                                                                                                                                        
    startretries = 3     ; 启动失败自动重试次数,默认是 3                                                                                                                                                                
    user = root      ; 用哪个用户启动                                                                                                                                                                                    
    redirect_stderr = true  ; 把 stderr 重定向到 stdout,默认 false                                                                                                                                                      
    stdout_logfile_maxbytes = 50MB  ; stdout 日志文件大小,默认 50MB                                                                                                                                                     
    stdout_logfile_backups = 7 ; stdout 日志文件备份数                                                                                                                                                                   
    ; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件)                                                                                                    
    stdout_logfile = /home/lukelee/logs/cesi.log

superisor集群管理ceshi工具安装

准备工作

  1. 安装yarn
    sudo apt remove cmdtest
    sudo apt remove yarn
    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
    sudo apt-get update
    sudo apt-get install yarn
  2. 依赖安装
    sudo apt install -y git python3 python3-pip python3-venv
  3. 服务下载
    • 方式一:下载压缩包
      wget https://github.com/gamegos/cesi/releases/download/v2.7.1/cesi-extended.tar.gz -O cesi.tar.gz
      tar -xvf cesi.tar.gz
    • 方式二:git拉取
      git clone https://github.com/gamegos/cesi.git
      git checkout v2.7.1

      开始安装

    • 创建venv虚拟环境
      python3 -m venv venv
  • 激活venv虚拟环境
    source venv/bin/activate
  • 在venv虚拟环境中,使用pip3管道安装依赖
    pip3 install -r requirements.txt
  • 失效venv虚拟环境
    deactivate
  • 编译
    cd cesi/ui
    yarn install
    yarn build
  • 复制配置文件到/etc目录
    cp defaults/cesi.conf.toml /etc/cesi.conf

  • 复制服务配置文件到/etc/systemd/system目录,并注册为服务
    cp defaults/cesi.service /etc/systemd/system/cesi.service
    systemctl daemon-reload #服务生效

    管理界面

  • 地址:http://127.0.0.1:5000
  • 默认账户:admin/admin

    配置示例

  • 服务配置(/etc/cesi.conf)

    # This is the main CeSI toml configuration file. It contains CeSI web application and
    # supervisord information to connect
    
    # This is the CeSI's own configuration.
    [cesi]
    # Database Uri
    database = "sqlite:///users.db"                         # Relative path
    # Etc
    #database = "sqlite:////opt/cesi/< version >/users.db"  # Absolute path
    #database = "postgres://<user>:<password>@localhost:5432/<database_name>"
    #database = "mysql+pymysql://<user>:<password>@localhost:3306/<database_name>"
    activity_log = "activity.log"   # File path for CeSI logs
    admin_username = "admin"        # Username of admin user
    admin_password = "admin"        # Password of admin user
    
    # This is the definition section for new supervisord node.
    # [[nodes]]
    # name = "api"          # (String) Unique name for supervisord node.
    # environment = ""      # (String) The environment name provides logical grouping of supervisord nodes. It can be used as filtering option in the UI.
    # username = ""         # (String) Username of the XML-RPC interface of supervisord Set nothing if no username is configured
    # password = ""         # (String) Password of the XML-RPC interface of supervisord. Set nothing if no username is configured
    # host = "127.0.0.1"    # (String) Host of the XML-RPC interface of supervisord
    # port = "9001"         # (String) Port of the XML-RPC interface of supervisord
    
    # Default supervisord nodes
    [[nodes]]
    name = "local"
    environment = "local"
    username = "lukelee"
    password = "lukelee"
    host = "localhost"
    port = "9001"
    
    # [[[nodes]]
    # name = "products-server"
    # environment = ""
    # username = "root"
    # password = "root"
    # host = "products.example.com"
    # port = "9001"
  • 系统服务(/etc/systemd/system/cesi.service)

    [Unit]
    Description=cesi
    
    [Service]
    Environment=
    ExecStart=python3 /opt/apps/cesi/cesi/run.py --config-file /etc/cesi.conf
    ExecReload=/bin/kill -HUP $MAINPID
    KillSignal=TERM
    User=root
    WorkingDirectory=/opt/apps/cesi
    
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target