部署方式(二)-Ubuntu18+.netcore+Nginx+Supervisor部署ASP.NET项目

  上文讲了Ubuntu18+mono+Nginx部署ASP.NET项目,再讲讲Ubuntu18+.netcore+Nginx部署ASP.NET项目吧(下次可能是讲.NET5了或是讲使用KubeOperator工具部署ks8再到项目部署

这里我参照微软文档

一,项目环境:

  系统:UbuntuServer18.04

  ASP.NET项目:.NetCore MVC工程,框架是Core2.2,启动文件是工程dll。

二,安装NetCore环境:

1.将 Microsoft 包签名密钥添加到受信任密钥列表,并添加包存储库。

wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

2.安装.NET Core SDK或安装运行时(服务器不需要开发应用使用运行时就可以

  安装SDK:

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-2.2

  安装运行时:

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y aspnetcore-runtime-2.2

   查看安装完成的信息(dotnet --info):

root@servercore:~# dotnet --info

Host (useful for support):
  Version: 2.2.8
  Commit:  b9aa1abc51

.NET Core SDKs installed:
  No SDKs were found.

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

  可以看到我只安装了runtime没有安装SDK。

三,安装Nginx

root@root:~# apt-get install nginx  #安装命令 (sudo service nginx start #启动命令)

root@root:~# nginx -v  #查看版本
nginx version: nginx/1.14.0 (Ubuntu)

局域网其他主机输入:http://服务器IP/index.nginx-debian.html,查看安装效果

四,上传网站文件,配置Nginx文件

  1.使用Xftp或者其它ftp工具把网站网站文件上传到服务器上。

  2.修改nginx配置文件(etc/nginx/sites-available/default):

server {
    #监听端口
    listen 80;
    listen [::]:80;
    #域名可以有多个,用空格隔开
    #server_name apelearn.com;
    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;
    }
}

在网站文件夹下输入下面命令,启动网站(默认使用端口5000)

dotnet 你的启动项.dll 

备注:这里我的网站一部分功能不能用,所以我又装了SDK。

root@servercore:~# dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.402
 Commit:    c7f2f96116

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  18.04
 OS Platform: Linux
 RID:         ubuntu.18.04-x64
 Base Path:   /usr/share/dotnet/sdk/2.2.402/

Host (useful for support):
  Version: 2.2.8
  Commit:  b9aa1abc51

.NET Core SDKs installed:
  2.2.402 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

还是不行,后来发现是数据库链接写了多个漏改了。

五,设置Supervisor守护程序

  mono里我们用了shell脚本设置开机启动,这次用Supervisor实现。

1.安装supervisor:

apt-get install supervisor

2.新建supervisor配置文件。

echo_supervisord_conf > /etc/supervisord.conf

3.修改/etc/supervisord.conf配置文件,添加

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

4. 新增.net core 启动的配置文件

vim /etc/supervisor/conf.d/hwappService.conf

5.填写以下内容:

[program:hwappService]
command=dotnet /usr/www/Czar.Cms.Admin.dll  #要执行的命令
directory=/usr/www/  #dll所在的文件夹
autostart=true
autorestart=true
stderr_logfile=/var/log/sampleMicroService.err.log #错误日志

stdout_logfile=/var/log/sampleMicroService.out.log #输出日志
user=root #用户
stopsignal=INT

引自:https://www.cnblogs.com/haoliansheng/p/6611714.html

补充:

1.ASP.NET Core Runtime与.NET Core Runtime的区别

镜像地址

镜像名称 镜像说明

mcr.microsoft.com/dotnet/core/runtime

.NET Core Runtime 部署.NET Core控制台程序
mcr.microsoft.com/dotnet/core/runtime-deps 

.NET Core Runtime Dependencies

部署自包含的部署应用程序

mcr.microsoft.com/dotnet/core/sdk 

.NET Core SDK 构建.NET Core(或ASP.NET Core应用程序)

mcr.microsoft.com/dotnet/core/aspnet 

ASP.NET Core Runtime 部署ASP.NET Core应用程序

   引自:https://blog.csdn.net/weixin_30349597/article/details/102124560

2.ubuntu下.NET Core手动更换版本(卸载再安装)

posted @ 2021-02-23 14:27  ꧁执笔小白꧂  阅读(310)  评论(0编辑  收藏  举报