安装 net core
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpmsudo yum update -y#sdk runtime二选一sudo yum install dotnet-sdk-2.2sudo yum install aspnetcore-runtime-2.2dotnet --version #sdkdotnet --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/helloappExecStart=/usr/bin/dotnet /var/www/helloapp/helloapp.dllRestart=always# Restart service after 10 seconds if the dotnet service crashes:RestartSec=10KillSignal=SIGINTSyslogIdentifier=dotnet-exampleUser=www-dataEnvironment=ASPNETCORE_ENVIRONMENT=ProductionEnvironment=DOTNET_PRINT_TELEMETRY_MESSAGE=false[Install]WantedBy=multi-user.target
systemctl enable kestrel-helloapp.servicesystemctl start kestrel-helloapp.servicesystemctl status kestrel-helloapp.service
前后台切换
ctrl+z 后台暂停bg 添加到后台继续运行fg 回到前台
配置防火墙端口
firewall-cmd --permanent --zone=public --add-port=8083/tcpfirewall-cmd --permanent --zone=public --add-port=1433/tcpfirewall-cmd --reload
参考:
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-2.2
centos 安装部署.net core站点
原文地址:https://www.cnblogs.com/wswind/p/10346871.html