gpt4 book ai didi

ubuntu - 在 Ubuntu 上托管 Net Core 应用程序

转载 作者:行者123 更新时间:2023-12-04 18:40:18 24 4
gpt4 key购买 nike

嘿伙计们,我在 Ubuntu 上托管我的 .net 核心时遇到了一些麻烦,我可以使用以下命令很好地托管它:

dotnet /home/bourdain/website/FrutaMargemCore/bin/Release/netcoreapp2.0/FrutaMargemCore.dll

这可以很好地托管应用程序,我可以通过 VM 的外部 IP 访问它,但它似乎将它锁定在某种 session 状态,终端只是托管它,我需要终止进程以运行任何其他命令。
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using'/home/bourdain/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Hosting environment: Production
Content root path: /home/bourdain/website/FrutaMargemCore/bin/Release/netcoreapp2.0
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

关闭 SSH 连接会终止该过程,并且不再托管该应用程序。

我试过使用
dotnet run /home/bourdain/website/FrutaMargemCore/bin/Release/netcoreapp2.0/FrutaMargemCore.dll

但它随机抛出异常
Using launch settings from /home/bourdain/website/FrutaMargemCore/Properties/launchSettings.json...

Unhandled Exception: System.FormatException: Value for switch '/home/bourdain/website/FrutaMargemCore/bin/Release/netcoreapp2.0/FrutaMargemCore.dll' is missing.
at Microsoft.Extensions.Configuration.CommandLine.CommandLineConfigurationProvider.Load()
at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at FrutaMargemCore.Program.BuildWebHost(String[] args) in /home/bourdain/website/FrutaMargemCore/Program.cs:line 21
at FrutaMargemCore.Program.Main(String[] args) in /home/bourdain/website/FrutaMargemCore/Program.cs:line 17

如何在我的 ubuntu 服务器上托管我的 netcore 核心,而不会在我关闭 SSH 连接时终止它?

最佳答案

您应该首先创建一个这样的服务文件:

sudo nano /etc/systemd/system/kestrel-yourApp.service

服务文件将包含以下内容:
[Unit]
Description=My ASPNET Core APP

[Service]
WorkingDirectory=/var/someFolder/yourApp
ExecStart=/usr/bin/dotnet /var/aspnetcore/yourApp/yourApp.dll
Restart=always
RestartSec=20
SyslogIdentifier=dotnet-example
User=yourUser
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

调整应用程序上下文的参数(如用户、路径等)。用户必须具有正确的权限。

这将启动服务:
systemctl enable kestrel-yourApp.service

这样做只是为了检查它是否正在运行:
systemctl status kestrel-yourApp.service

关于ubuntu - 在 Ubuntu 上托管 Net Core 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49343380/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com