红联Linux门户
Linux帮助

ASP.net Core部署说明(CentOS)

发布时间:2016-07-12 10:13:02来源:blog.csdn.net/lanwilliam/作者:b哈利路亚d
其实CentOS部署Asp.net Core和Ubuntu差不太多(Ubuntu部署方法:http://www.linuxdiyf.com/linux/22296.html),主要区别在于.net Core SDK的安装这里。
 
安装脚本
sudo yum install libunwind libicu  
curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131  
sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet  
sudo ln -s /opt/dotnet/dotnet /usr/local/bin  
 
login as: root  
root@192.168.1.5's password:  
Last login: Fri Jul  8 15:05:14 2016 from 192.168.1.2  
-bash-4.2# sudo yum install libunwind libicu  
已加载插件:fastestmirror, langpacks  
base | 3.6 kB 00:00  
docker-main-repo | 2.9 kB 00:00  
dockerrepo   | 2.9 kB 00:00  
epel/x86_64/metalink | 5.2 kB 00:00  
epel | 4.3 kB 00:00  
extras   | 3.4 kB 00:00  
remi-safe| 2.9 kB 00:01  
updates  | 3.4 kB 00:00  
(1/4): epel/x86_64/updateinfo  | 582 kB   00:05  
(2/4): updates/7/x86_64/primary_db | 5.7 MB   00:08  
epel/x86_64/primary_db FAILED  
https://ftp.yzu.edu.tw/Linux/Fedora-EPEL/7/x86_64/repodata/ad26bd0be462ecdd6efad4c26c0ff76ad57cc7555cbb878ceb7ec798b6a927b7-primary.sqlite.xz: [Errno 14] curl#56 - "TCP connection reset by peer"  
正在尝试其它镜像。  
(3/4): epel/x86_64/primary_db  | 4.2 MB   00:13  
(4/4): remi-safe/primary_db| 471 kB   01:38  
Loading mirror speeds from cached hostfile  
* epel: mirrors.neusoft.edu.cn  
* remi-safe: mirrors.tuna.tsinghua.edu.cn  
软件包 2:libunwind-1.1-5.el7_2.2.x86_64 已安装并且是最新版本  
软件包 libicu-50.1.2-15.el7.x86_64 已安装并且是最新版本  
无须任何处理  
-bash-4.2# curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131  
-bash-4.2# ls  
dotnet.tar.gz  
-bash-4.2# pwd  
/root  
-bash-4.2# sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet  
-bash-4.2# sudo ln -s /opt/dotnet/dotnet /usr/local/bin  
-bash-4.2# ls  
dotnet.tar.gz  
-bash-4.2# cd /opt  
-bash-4.2# ls  
dotnet  rh  
-bash-4.2# cd dotnet  
-bash-4.2# ls  
dotnet  host  LICENSE.txt  sdk  shared  ThirdPartyNotices.txt  
-bash-4.2# pwd  
/opt/dotnet  
-bash-4.2# ls  
dotnet  host  LICENSE.txt  sdk  shared  ThirdPartyNotices.txt  
-bash-4.2# cd root  
-bash: cd: root: 没有那个文件或目录  
-bash-4.2# cd /  
-bash-4.2# cd root  
-bash-4.2# ls  
dotnet.tar.gz  
-bash-4.2# mkdir hwapp  
-bash-4.2# cd hwapp  
-bash-4.2# dotnet new
Welcome to .NET Core!  
---------------------  
Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.  
Telemetry  
--------------  
The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and shared with the community.  
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.  
You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.  
Configuring...  
-------------------  
A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.  
Decompressing 100% 1888 ms  
Expanding 100% 8029 ms  
Created new C# project in /root/hwapp.  
-bash-4.2# dotnet resotre  
No executable found matching command "dotnet-resotre"  
-bash-4.2# dotnet restore  
log  : Restoring packages for /root/hwapp/project.json...  
log  : Writing lock file to disk. Path: /root/hwapp/project.lock.json  
log  : /root/hwapp/project.json  
log  : Restore completed in 586ms.  
-bash-4.2# dotnet run  
Project hwapp (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing  
Compiling hwapp for .NETCoreApp,Version=v1.0
Compilation succeeded.  
0 Warning(s)  
0 Error(s)
Time elapsed 00:00:01.8941387
Hello World!  
-bash-4.2# ls  
bin  obj  Program.cs  project.json  project.lock.json  
-bash-4.2# pwd  
/root/hwapp  
-bash-4.2# cd ..  
-bash-4.2# ls  
dotnet.tar.gz  hwapp  publish  
-bash-4.2# cd publish  
-bash-4.2# ls  
appsettings.json  
Microsoft.ApplicationInsights.AspNetCore.dll  
Microsoft.ApplicationInsights.dll  
Microsoft.AspNetCore.Antiforgery.dll  
Microsoft.AspNetCore.Authentication.Cookies.dll  
Microsoft.AspNetCore.Authentication.dll  
Microsoft.AspNetCore.Authorization.dll  
Microsoft.AspNetCore.Cors.dll  
Microsoft.AspNetCore.Cryptography.Internal.dll  
Microsoft.AspNetCore.Cryptography.KeyDerivation.dll  
Microsoft.AspNetCore.DataProtection.Abstractions.dll  
Microsoft.AspNetCore.DataProtection.dll  
Microsoft.AspNetCore.Diagnostics.Abstractions.dll  
Microsoft.AspNetCore.Diagnostics.dll  
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.dll  
Microsoft.AspNetCore.Hosting.Abstractions.dll  
Microsoft.AspNetCore.Hosting.dll  
Microsoft.AspNetCore.Hosting.Server.Abstractions.dll  
Microsoft.AspNetCore.Html.Abstractions.dll  
Microsoft.AspNetCore.Http.Abstractions.dll  
Microsoft.AspNetCore.Http.dll  
Microsoft.AspNetCore.Http.Extensions.dll  
Microsoft.AspNetCore.Http.Features.dll  
Microsoft.AspNetCore.HttpOverrides.dll  
Microsoft.AspNetCore.Identity.dll  
Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll  
Microsoft.AspNetCore.JsonPatch.dll  
Microsoft.AspNetCore.Localization.dll  
Microsoft.AspNetCore.Mvc.Abstractions.dll  
Microsoft.AspNetCore.Mvc.ApiExplorer.dll  
Microsoft.AspNetCore.Mvc.Core.dll  
Microsoft.AspNetCore.Mvc.Cors.dll  
Microsoft.AspNetCore.Mvc.DataAnnotations.dll  
Microsoft.AspNetCore.Mvc.dll  
Microsoft.AspNetCore.Mvc.Formatters.Json.dll  
Microsoft.AspNetCore.Mvc.Localization.dll  
Microsoft.AspNetCore.Mvc.Razor.dll  
Microsoft.AspNetCore.Mvc.Razor.Host.dll  
Microsoft.AspNetCore.Mvc.TagHelpers.dll  
Microsoft.AspNetCore.Mvc.ViewFeatures.dll  
Microsoft.AspNetCore.Razor.dll  
Microsoft.AspNetCore.Razor.Runtime.dll  
Microsoft.AspNetCore.Routing.Abstractions.dll  
Microsoft.AspNetCore.Routing.dll  
Microsoft.AspNetCore.Server.IISIntegration.dll  
Microsoft.AspNetCore.Server.Kestrel.dll  
Microsoft.AspNetCore.StaticFiles.dll  
Microsoft.AspNetCore.WebUtilities.dll  
Microsoft.DotNet.InternalAbstractions.dll  
Microsoft.EntityFrameworkCore.dll  
Microsoft.EntityFrameworkCore.Relational.dll  
Microsoft.EntityFrameworkCore.SqlServer.dll  
Microsoft.Extensions.Caching.Abstractions.dll  
Microsoft.Extensions.Caching.Memory.dll  
Microsoft.Extensions.Configuration.Abstractions.dll  
Microsoft.Extensions.Configuration.dll  
Microsoft.Extensions.Configuration.EnvironmentVariables.dll  
Microsoft.Extensions.Configuration.FileExtensions.dll  
Microsoft.Extensions.Configuration.Json.dll  
Microsoft.Extensions.Configuration.UserSecrets.dll  
Microsoft.Extensions.DependencyInjection.Abstractions.dll  
Microsoft.Extensions.DependencyInjection.dll  
Microsoft.Extensions.DependencyModel.dll  
Microsoft.Extensions.DiagnosticAdapter.dll  
Microsoft.Extensions.FileProviders.Abstractions.dll  
Microsoft.Extensions.FileProviders.Composite.dll  
Microsoft.Extensions.FileProviders.Physical.dll  
Microsoft.Extensions.FileSystemGlobbing.dll  
Microsoft.Extensions.Globalization.CultureInfoCache.dll  
Microsoft.Extensions.Localization.Abstractions.dll  
Microsoft.Extensions.Localization.dll  
Microsoft.Extensions.Logging.Abstractions.dll  
Microsoft.Extensions.Logging.Console.dll  
Microsoft.Extensions.Logging.Debug.dll  
Microsoft.Extensions.Logging.dll  
Microsoft.Extensions.ObjectPool.dll  
Microsoft.Extensions.Options.dll  
Microsoft.Extensions.PlatformAbstractions.dll  
Microsoft.Extensions.Primitives.dll  
Microsoft.Extensions.WebEncoders.dll  
Microsoft.Net.Http.Headers.dll  
Microsoft.VisualStudio.Web.BrowserLink.Loader.dll  
Newtonsoft.Json.dll  
npgsql.dll  
Npgsql.EntityFrameworkCore.PostgreSQL.dll  
refs  
Remotion.Linq.dll  
runtimes  
System.Collections.NonGeneric.dll  
System.Collections.Specialized.dll  
System.ComponentModel.Primitives.dll  
System.ComponentModel.TypeConverter.dll  
System.Data.Common.dll  
System.Diagnostics.Contracts.dll  
System.Interactive.Async.dll  
System.Net.WebSockets.dll  
System.Runtime.Serialization.Primitives.dll  
System.Text.Encodings.Web.dll  
Views  
WebApplication1.deps.json  
WebApplication1.dll  
WebApplication1.pdb  
WebApplication1.runtimeconfig.json  
web.config  
wwwroot  
-bash-4.2# firewall-cmd --list-all  
public (default, active)  
interfaces: eth0  
sources:  
services: dhcpv6-client http mysql ssh  
ports:  
masquerade: no  
forward-ports:  
icmp-blocks:  
rich rules:
-bash-4.2# firewall-cmd --add-port=5000/tcp  
success  
-bash-4.2# firewall-cmd --list-all  
public (default, active)  
interfaces: eth0  
sources:  
services: dhcpv6-client http mysql ssh  
ports: 5000/tcp  
masquerade: no  
forward-ports:  
icmp-blocks:  
rich rules:
-bash-4.2# dotnet WebApplication1.dll  
info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0]  
User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.  
Hosting environment: Production  
Content root path: /root/publish  
Now listening on: http://*:5000  
 
这里不贴图了,把我执行的脚本贴出来把,上传图片太麻烦。
 
重点是,要在CentOS中配置防火墙端口开放。
CentOS7默认使用的firewall防火墙,默认启用,所以不配置的话,可能无法外部访问。
firewall-cmd --add-port=5000/tcp  
这个是临时开放端口,如果想要永久生效,请使用
firewall-cmd --add-port=5000/tcp --permanent  
 
由于笔者测试虚机部署了apache,也就是httpd,这里暂时就不安装nginx了。
Nginx和Superversior请参照ubuntu安装部分说明(http://www.linuxdiyf.com/linux/22296.html)。
 
本文永久更新地址:http://www.linuxdiyf.com/linux/22297.html