.Net Core 项目发布到Linux - CentOS 7(二)用Supervisor守护netcore进程

简介

supervisor可以保证程序崩溃后,可以重新把程序启动起来等相关功能。

安装

yum install -y supervisor

安装好后在/etc/会生成一个supervisord.conf文件及一个supervisord.d文件目录

查看supervisor是否安装成功

supervisord --version

启动

supervisord -c /etc/supervisord.conf

查看supervisor是否启动成功

ps -ef|grep supervisord

设置supervisor 开机启动

systemctl enable supervisord

检查是否是开机启动

systemctl is-enabled supervisord

启动服务

systemctl start supervisord

启动时可能回报错:Another program is already listening on a port that one of our HTTP servers is config...rvisord.

 解决方案:

执行命令 find / -name supervisor.sock  然后 unlink /路径/supervisor.sock 最后再执行启动命令 systemctl start supervisord 

查看状态

systemctl status supervisord.service

配置supervisor ,web管理页面

修改配置信息,supervisor 默认配置文件,放在 /etc/supervisord.conf 路径中:

[inet_http_server]         ; HTTP 服务器,提供 web 管理界面
port=*:9001                ; Web 管理后台运行的 IP 和端口
username=user              ; 登录管理后台的用户名
password=1234               ; 登录管理后台的密码

 [include]                     
 files = supervisord.d/*.ini ;配置文件夹

修改完之后重启:

supervisorctl reload

然后通过http://ip:9001/访问web界面,账户名密码就是你配置的,效果如下:

 

创建配置文件

创建一个.ini文件,放在目录supervisord.d下

[program:demo] ;程序名称
command=dotnet demo.dll ; 运行命令
directory=/web/publish;目录
environment=ASPNETCORE_ENVIRONMENT=Production;环境变量
user=root;用户
stopsignal=INT
autostart=true;如果是true的话,子进程将在supervisord启动后被自动启动
autorestart=true;进程死掉后自动重启的情况
stderr_logfile=/var/log/demo/demo.err.log;错误日志文件
stdout_logfile=/var/log/demo/demo.out.log;输出日志文件

 重启

systemctl restart supervisord

查看是否生效

supervisorctl status

然后把Xshell关了,浏览器中输入:http://ip:8080/api/values,也能看到以下页面:

supervisorctl 常用命令

查看任务状态:supervisorctl status

启动任务:supervisorctl start <name>

停止任务:supervisorctl stop <name>

重启任务:supervisorctl restart <name>

清除日志文件:supervisorctl  clear <name>

清除多个日志文件:supervisorctl  clear <name> <name> 

清除所有日志文件:supervisorctl  clear all 

移除任务:supervisorctl  remove <name>

Nginx代理配置

安裝nginx:Linux - CentOS 7 通过Yum源安装 Nginx 

修改nginx.conf

添加一个服务

  server {
     listen       80;
     server_name  47.106.98.252;

    location / {
          root   html;
          index  index.html index.htm;
          proxy_pass http://localhost:8080;
    }
 }

检查配置文件是否成功

nginx -t

 成功之后重启Nginx服务

systemctl restart nginx.service

测试

浏览器输入http://ip:/api/values,效果是一样的:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Centos7发布说明 环境说明: 服务器系统:CentOS 7.2.1511 相关工具:Xshel、Xftp 服务器软件软件:.netcore、nginx、supervisor 准备好发布的程序 安装.NET Core SDK for CentOS7 打开网址:https://www.microsoft.com/net/core#linuxcentos 复制如下命令,单步执行: sudo yum install libunwind libicu curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=835019 sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet sudo ln -s /opt/dotnet/dotnet /usr/local/bin 输入 dotnet –info 来查看是否安装成功 配置Nginx 下载安装Nginx,单步执行如下命令: curl -o nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm rpm -ivh nginx.rpm yum install nginx systemctl start nginx 来启动nginx systemctl enable nginx 来设置nginx的开机启动(linux宕机、重启会自动运行nginx不需要连上去输入命令)。 配置防火墙 命令:firewall-cmd --zone=public --add-port=80/tcp --permanent(开放80端口) 命令:systemctl restart firewalld(重启防火墙以使配置即时生效) 测试nginx是否可以访问。 配置nginx对ASP.NET Core应用的转发 修改 /etc/nginx/conf.d/default.conf 文件,将文件内容替换为: server { listen 80; location / { proxy_pass http://localhost:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值