[b]NetCore1.1+Linux部署初体验[/b]
[b]1.环境准备[/b]
Centaos7+Win10 虚拟机
Win10安装VS2017 注意勾选下.Net Core
[img]http://files.jb51.net/file_images/article/201706/20170620141345160.png[/img]
3.Centaos安装netcore 1.1参见[url=https://www.microsoft.com/net/core]https://www.microsoft.com/net/core[/url]
sudo yum install libunwind libicu
curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?linkid=848821
sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet
sudo ln -s /opt/dotnet/dotnet /usr/local/bin
[img]http://files.jb51.net/file_images/article/201706/20170620141346161.png[/img]
dotnet new console -o hwapp
cd hwapp
dotnet restore
主要是寻找当前目录下的项目文件,然后利用NuGet库还原整个项目的依赖库,然后遍历每个目录,生成项目文件,继续还原该项目文件中的依赖项;
dotnet run
如果是交互的就直接运行,否则编译然后执行
[img]http://files.jb51.net/file_images/article/201706/20170620141346162.png[/img]
[b]2.项目准备[/b]
1.我这边项目名称为: NetCore.Api
[img]http://files.jb51.net/file_images/article/201706/20170620141346163.png[/img]
[img]http://files.jb51.net/file_images/article/201706/20170620141346164.png[/img]
2.修改发布相关支持;
.NET Core彻底放弃project.json,全面改回.csproj
[url=http://www.1sucai.cn/article/116700.htm]Asp.NetCore1.1版本去掉project.json后如何打包生成跨平台包[/url]
打开:NetCore.Api.csproj 添加发布支持RuntimeIdentifiers配置
<PropertyGroup>
<RuntimeIdentifiers>win10-x64;centos.7-x64</RuntimeIdentifiers>
</PropertyGroup>
3.打开Program.cs修改端口支持
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseUrls("http://*:8088")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
4.编译运行没有问题,通过WinSCP上传到Centaos7服务器上
[img]http://files.jb51.net/file_images/article/201706/2017620142444037.jpg?201752014251[/img]
[b]3.Linux部署[/b]
进入上传的项目目录
[img]http://files.jb51.net/file_images/article/201706/20170620141346166.png[/img]
dotnet restore 命令进行还原依赖项
[i][img]http://files.jb51.net/file_images/article/201706/20170620141346167.png[/img]
[/i]
还原完成后,发布项目文件
dotnet publish
[img]http://files.jb51.net/file_images/article/201706/20170620141346168.png[/img]
复制发布后的文件到运行文件夹
cp -rf /home/xupp/website/bin/Debug/netcoreapp1.1/publish/ /home/xupp/web.test/
[img]http://files.jb51.net/file_images/article/201706/20170620141346169.png[/img]
[img]http://files.jb51.net/file_images/article/201706/20170620141346170.png[/img]
运行项目
nohup dotnet NetCore.Api.dll
只是做测试用,正式环境下可以使用Supervisor守护进程[/code]
[img]http://files.jb51.net/file_images/article/201706/20170620141346171.png[/img]
外网测试看能否访问,不能访问的话先用dotnet NetCore.Api.dll运行,并检查防火墙配置
[img]http://files.jb51.net/file_images/article/201706/20170620141346172.png[/img]
Ngiux配置(负载均衡下用)
[url=http://www.1sucai.cn/article/116710.htm]Ngiux安装[/url]
Ngiux简单配置
[img]http://files.jb51.net/file_images/article/201706/20170620141346173.png[/img]
[url=http://www.1sucai.cn/article/116700.htm]Asp.NetCore1.1版本去掉project.json后如何打包生成跨平台包[/url]
[img]http://files.jb51.net/file_images/article/201706/20170620141346174.png[/img]
NetCore2.0体验参见:
[url=http://www.cnblogs.com/linezero/p/nightlynetcore2.html]http://www.cnblogs.com/linezero/p/nightlynetcore2.html[/url]
[url=http://www.php.cn/csharp-article-363405.html]http://www.php.cn/csharp-article-363405.html[/url]
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。