在Linux服务器部署 .NET-Core 项目

一、文章概要

 这篇文章是讲述一个Linux 新手将 .NET-Core 项目部署在 Linux 服务器上的一个记录,以及在部署期间遇到的问题以及解决办法。有不恰当的地方。欢迎大神指正。

二、前期准备

 如果你要部署在Linux服务器上,首先你需要连接到Linux服务器。那么用什么工具连呢?1. 如果你是在Windows的系统环境下,我是采用 PuTTY来进行SSH 连接的。可以参考:使用Putty连接SSH管理linux图文教程 。2.如果你的系统是Mac 的,那直接用Terminal 就可以啦。输入:

ssh root@hostname

然后就连接上Linux 服务器啦。

   2.1 项目环境
  • .NET-Core 项目的版本为 .NET Core 1.1
  • Linux 服务器的版本为Ubuntu 14.04
   2.2 所需工具
  • PuTTY

三、文章内容

  在上面的步骤都做好了之后呢,我们登陆到Linux 服务器上,进行如下操作:

  1. 可以先用mkdir /data 创建一个发布用的文件夹。
  2. 然后进入cd data
  3. 操作 git ,先把你的项目clone 到 data文件夹 git clone 项目地址
  4. 进行dotnet 的命令操作。 dotnet restore 进行包的还原,有些因为是有些包是自己公司的,所以要加上自己公司包的地址
dotnet restore -s http://nuget.222.om/nuget/core -s http://nuget.565646.com/nuget/Default
  1. dotnet publish -c release 操作,进行发布。发布成功,得到发布后的路径为:/data/MyProject/MyProject.Web/bin/release/netcoreapp1.1/ubuntu.14.04-x64/publish
  2. supervisor 来管理
  3. 先安装 supervisor 通过 用apt-get install supervisor命令安装supervisor
  4. 在 /etc/supervisor/conf.d 目录中添加 q.conf 配置文件,其中的配置如下:
[program:q]
directory=/data/MyProject/MyProject.Web/bin/release/netcoreapp1.1/ubuntu.14.04-x64/publish
command=/data/MyProject/MyProject.Web/bin/release/netcoreapp1.1/ubuntu.14.04-x64/publish/MyProject.Web
autostart=true
autorestart=true
stderr_logfile=/var/log/q.err.log
stdout_logfile=/var/log/q.out.log
environment=Hosting__Environment=Production
user=root
stopsignal=INT
  1. 运行命令service supervisor restart重启supervisor,站点就会自动启动
  2. 在浏览器输入地址,成功运行。

四、问题解决

   4.1 错误:

Err https://apt-mo.trafficmanager.net trusty/main amd64 Packages
Bad header line

   解决:

https://www.idaima.com/a/6735.html

   4.2 错误:

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package dotnet-dev-1.0.0-preview2.1-003177
E: Couldn't find any package by regex 'dotnet-dev-1.0.0-preview2.1-003177'

   解决:

由于上一个问题没解决导致

   4.3 错误:

在Linux上还原包失败

   解决:

有些因为是有些包是自己公司的,所以要加上自己公司包的地址C# dotnet restore -s http://nuget.222.om/nuget/core -s http://nuget.565646.com/nuget/Default

   4.4 问题:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name correct and that SQL Server is configured to allow remote connections.(provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.AggregateException: One or more errors occurred. (No such device or address) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: No such device or address

   相关问题:

https://github.com/dotnet/corefx/issues/8086

五、参考文献

转载于:https://www.cnblogs.com/xiyin/p/6401305.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值