安装 net core
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
sudo yum update -y
#sdk runtime二选一
sudo yum install dotnet-sdk-2.2
sudo yum install aspnetcore-runtime-2.2
dotnet --version #sdk
dotnet --info #runtime
#runtime使用
dotnet xx.dll
#sdk切换到代码目录使用
dotnet run
指定ip端口
public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseUrls("http://*:80;")
.UseStartup<Startup>()
.Build();
}
服务守护
sudo nano /etc/systemd/system/kestrel-helloapp.service
[Unit]
Description=Example .NET Web API App running on Ubuntu
[Service]
WorkingDirectory=/var/www/helloapp
ExecStart=/usr/bin/dotnet /var/www/helloapp/helloapp.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
systemctl enable kestrel-helloapp.service
systemctl start kestrel-helloapp.service
systemctl status kestrel-helloapp.service
前后台切换
ctrl+z 后台暂停
bg 添加到后台继续运行
fg 回到前台
配置防火墙端口
firewall-cmd --permanent --zone=public --add-port=8083/tcp
firewall-cmd --permanent --zone=public --add-port=1433/tcp
firewall-cmd --reload
参考:
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-2.2
原文地址:https://www.cnblogs.com/wswind/p/10346871.html
时间: 2024-10-06 17:47:40