zoukankan      html  css  js  c++  java
  • netcore应用程序直接部署到ubuntu,supervisor守护进程

    运维需求:获取服务器的运行情况,是否CPU、内存较高等,上报到运维系统

    环境:ubuntu16.04

    工具::netcore2.1、supervisor 

    程序实现(代码就不贴了)参考:https://blog.csdn.net/u014518337/article/details/86291984

    因需要获取系统数据,部分命令行不支持在docker环境运行,因此直接由dotnet直接运行程序,守护进程由supervisor 守护

    1、安装netcore2.1

    wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
    sudo dpkg -i packages-microsoft-prod.deb
    sudo apt-get install apt-transport-https
    sudo apt-get update
    sudo apt-get install dotnet-sdk-2.1

    执行 dotnet --info  查看是否安装正确

    2、安装supervisor

    参考:https://www.cnblogs.com/savorboard/p/dotnetcore-supervisor.html

    sudo apt-get install supervisor

    安装完成之后,在 /ect/supervisor/conf.d/ 目录下新建一个配置文件(touch HelloWebApp.conf),取名为 HelloWebApp.conf

    打开HelloWebApp.conf (vim HelloWebApp.conf),写入如下命令:

    [program:HelloWebApp]
    command=dotnet HelloWebApp.dll  #要执行的命令
    directory=/home/xxx/publish #命令执行的目录
    environment=ASPNETCORE__ENVIRONMENT=Production #环境变量
    user=www-data  #进程执行的用户身份
    stopsignal=INT
    autostart=true #是否自动启动
    autorestart=true #是否自动重启
    startsecs=1 #自动重启间隔
    stderr_logfile=/var/log/HelloWebApp.err.log #标准错误日志
    stdout_logfile=/var/log/HelloWebApp.out.log #标准输出日志

    注意:上面代码需要把注释 #后面的中文删掉

    修改配置文件/etc/supervisor/supervisord.conf  添加supervisord web管理功能  红色为新增配置部分

    ;upervisor config file
    
    [unix_http_server]
    file=/var/run/supervisor.sock   ; (the path to the socket file)
    chmod=0700                       ; sockef file mode (default 0700)
    
    [inet_http_server]
    port=*:9001
    username=user
    password=123
    
    
    
    [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
    
    ; 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.
    
    [include]
    files = /etc/supervisor/conf.d/*.conf

    保存之后重启下程序

    sudo supervisorctl shutdown && sudo supervisord -c /etc/supervisor/supervisord.conf

    如果启动异常根据提示查看配置修改配置文件

  • 相关阅读:
    部署至Oracle数据库的注意事项
    当在centos上面部署项目时,mysql的一些驱动安装不上,
    drf利用redis做缓存是发生一点错误提示
    python字符串前面加个u代表什么
    在学习数据分析时,安装anaconda时遇到一点问题
    在使用scrapy框架爬取sina时,常见保存
    在linux上scrapyd部署scrapy项目时出现service_identity,并且不能识别其中的一个opentype模块
    如何在mysql增加一个和root权限一样的用户,安排
    mysq的root密码忘记,原来还有更优雅的解法
    mysql远程连接阿里云的Ubuntu服务器
  • 原文地址:https://www.cnblogs.com/chongerwangzi/p/10436466.html
Copyright © 2011-2022 走看看