我是扶摇 發表於 2021-11-19 09:16:00

.net core api 部署 Linux Debian 11

<p>1、安装 .net core 3.1&nbsp;</p>
<p>安装步骤参考微软文档</p>
<p>https://docs.microsoft.com/zh-cn/dotnet/core/install/linux-debian</p>
<p>第一步执行:</p>
<p>wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb<br>sudo dpkg -i packages-microsoft-prod.deb<br>rm packages-microsoft-prod.deb</p>
<p>第二步执行(我这采用的是.net core 3.1版本):</p>
<p>sudo apt-get update; \<br>sudo apt-get install -y apt-transport-https &amp;&amp; \<br>sudo apt-get update &amp;&amp; \<br>sudo apt-get install -y dotnet-sdk-3.1</p>
<p>&nbsp;</p>
<p>2、打包发布 net core 到liunx系统 我这采用 国产&nbsp;FinalShell 工具连接</p>
<p>直接上传到 home 文件夹用户文档,其他文件要提升权限才可以</p>
<p>3、启动</p>
<p>启动命令指定 端口:5000,前面用“*” 可以同时监听本地地址和ip4地址</p>
<p>dotnet FAST.API.Core.dll --urls http://*:5000</p>
<p>&nbsp;</p>
<p>这边我报了一个错,</p>
<p>日志时间:2021-11-18 20:49:41.822 未知异常: System.TypeInitializationException: The type initializer for 'System.DrawingCore.GDIPlus' threw an exception.<br> ---&gt; System.DllNotFoundException: Unable to load shared library 'gdiplus' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libgdiplus: cannot open shared object file: No such file or directory<br>   at System.DrawingCore.GDIPlus.GdiplusStartup(UInt64&amp; token, GdiplusStartupInput&amp; input, GdiplusStartupOutput&amp; output)<br>   at System.DrawingCore.GDIPlus..cctor()<br>   --- End of inner exception stack trace ---<br>   at System.DrawingCore.GDIPlus.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, PixelFormat format, IntPtr scan0, IntPtr&amp; bmp)<br>   at System.DrawingCore.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)<br>   at System.DrawingCore.Bitmap..ctor(Int32 width, Int32 height)<br>   at FAST.API.Utils.VerificationCode.YZM1.Create(String&amp; code, Int32 numbers)<br>   at FAST.API.Core.Controllers.YZMController.ValidateCode1() in D:\GitSourceCode\tgyth3\SourceCode\Declare\TYB\FAST_API\FAST.API.Core\Controllers\YZMController.cs:line 26<br>   at lambda_method(Closure , Object , Object[] )<br>   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)<br>   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)<br>   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()<br>   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)<br>   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()<br>--- End of stack trace from previous location where exception was thrown ---<br>   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)<br>   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)<br>   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()<br>--- End of stack trace from previous location where exception was thrown ---<br>   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeFilterPipelineAsync&gt;g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)<br>   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeAsync&gt;g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)<br>   at Microsoft.AspNetCore.Routing.EndpointMiddleware.&lt;Invoke&gt;g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)<br>   at FAST.API.Core.Middlewares.ExceptionMiddleWare.Invoke(HttpContext context) in D:\GitSourceCode\tgyth3\SourceCode\Declare\TYB\FAST_API\FAST.API.Core\Middlewares\ExceptionMiddleWare.cs:line 25</p>
<p>&nbsp;</p>
<p>需要安装包</p>
<p>执行命令:</p>
<p>sudo apt-get install libgdiplus&nbsp;</p>
<p>在重启API</p>
<p>dotnet FAST.API.Core.dll --urls http://*:5000</p>
<p>&nbsp;</p>
<p>3、开启外网访问</p>
<p>&nbsp;</p>
<p>iptables -A INPUT -p tcp --dport 5000:6000 -j ACCEPT</p>
<p>我这设置了,没有效果</p>
<p>重启电脑生效了</p>
<p>其他:</p>
<p>查看端口占用:</p>
<p>netstat &nbsp;-anp &nbsp;|grep &nbsp;3306</p>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/piaoxuewuming/p/15574502.html
頁: [1]
查看完整版本: .net core api 部署 Linux Debian 11