• 2019年1月22日

centos 7中部署.net core 3 preview 版的runtime运行时

只能说,部署.net core 运行时的文章基本上说的都是安装sdk版本的,所以研究了2天,百度了大量的文章,终于安装好了。步骤如下:

1、安装nginx环境

2、安装必须的东西,具体我也不知道,命令如下:
yum install libunwind libicu

3、下载runtime,要下载2个,一个是netcore runtime,一个是dotnet core runtime,下载下来后解压并安装:

sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet 
sudo ln -s /opt/dotnet/dotnet /usr/local/bin
sudo tar zxf aspnetcore.tar.gz /opt/dotnet

第一行是建立文件夹并解压缩
第二行是在/usr/local/bin创建一个dotnet的链接,连接到/opt/dotnet/dotnet上,这样子输入 dotnet命令就可以调用到命令了
第三行是将aspnet core runtime解压到netcore runtime目录下

到这里runtime环境算是搭好了,接下来就是创建一个网站,具体可以使用类似宝塔之类(安装完系统就先装个宝塔类的软件,可以快速搭建linux环境和管理网站)的软件来创建。

将visual studio的.net core项目发布,一种是独立部署,一种是依赖框架部署。

两种部署的简单区别如下(个人理解,不保证正确):

1、依赖框架部署,最精简的,相当于只发布了网站程序而已,能不能运行就看平台上支不支持你需要的运行环境了。

2、独立部署:比较臃肿,因为自带自需的运行时框架(但是前提应该是服务器已经安装了上面的基本环境),如果服务器的.net core runtime版本不是你的版本,那么程序还是可以运行的。

因为我安装的是.net core 3.0预览版,发现visual studio 2017只能支持目标框架2.0的所以无法正常发布,只能选择独立部署发布。发布到文件夹,将文件通过ftp上传到网站的根目录。

接下来就是运行网站程序了,输入命令:

dotnet netCoreStudy.dll

其中netCoreStudy我的项目名,发布出来后有一个netCoreStudy.dll

接着就能收到运行的提示了。

可能存在的错误:

1、Unable to bind to http://localhost:5000 on the IPv6 loopback interface.

这个问题好像是不能绑定5000端口,我给换了下端口,参考下图(往上转过来的):

先建立一个文档:port.json,或者你已经了自己配置的文件,增加下面这条内容:

"server.urls": "http://myname.com.cn:8000" 

例如我的port.json文件:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=_CHANGE_ME;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "server.urls": "http://myname.com.cn:8000" 
}

然后编辑program.cs文件,增加config的定义,然后引用config。

PS:内部的directory.getcurrentdirectory()我个人换成了appcontext.basedirectory

2、出现错误:

Error:
 An assembly specified in the application dependencies manifest (ZKEACMS.WebHost.deps.json) was not found:
 package: 'Microsoft.ApplicationInsights.AspNetCore', version: '2.1.1'
 path: 'lib/netstandard1.6/Microsoft.ApplicationInsights.AspNetCore.dll'
 This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:
 aspnetcore-store-2.0.0-linux-x64.xml;aspnetcore-store-2.0.0-osx-x64.xml;aspnetcore-store-2.0.0-win7-x64.xml;aspnetcore-store-2.0.0-win7-x86.xml

这个是没有安装aspnet core runtime,参考前面的步骤。

One thought on “centos 7中部署.net core 3 preview 版的runtime运行时

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注