Linux部署运行asp.net core

  • 下载安装Net Core

详细的安装步骤参考微软Net Core网址,不同的Linux选择不同的版本。
CentOS下第一次安装先得执行这二句注册一下,然后安装sdk。

 $sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
$sudo sh -c 'echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl= https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/dotnetdev.repo'
 
$sudo yum install libunwind libicu
$sudo yum install dotnet-sdk-2.1.4
$sudo yum install aspnetcore-runtime-2.1
 
$dotnet --version
2.1.4

Ubuntu下第一次安装也得注册,执行语句根据不同的Ubuntu的版本还有些许差异,注册后执行安装sdk。

 $curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
$sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
$sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
 
$sudo apt-get install apt-transport-https
$sudo apt-get update
$sudo apt-get install dotnet-sdk-2.1.4
 
$dotnet --version
2.1.4
  • 配置Nginx
location / {
       proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade; 
    }
  • 监视应用程序
    创建配置文件
sudo nano /etc/systemd/system/kestrel-hellomvc.service
[Unit]
Description=simpleWeixin .NET Web API App running on centos7
[Service]
WorkingDirectory=/www/wwwroot/xxx
ExecStart=/usr/bin/dotnet /www/wwwroot/xxx/xxx.Web.dll
Restart=always
RestartSec=10  # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=dotnet-example
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
 [Install]
WantedBy=multi-user.target

保存和开启服务:

systemctl enable kestrel-hellomvc.service

启动并查看状态:

systemctl start kestrel-hellomvc.service 
systemctl status kestrel-hellomvc.service

你可能感兴趣的:(Linux部署运行asp.net core)