linux部署.Net

[删除(380066935@qq.com或微信通知)]

更好的阅读体验请查看原文:https://github.com/chi8708/Linux-.Net/blob/main/linux%E9%83%A8%E7%BD%B2.Net.md

1. 在线安装

介绍centos8下.net5环境搭建、创建.net5程序、设置开机自动启动(注册为服务运行)

  1. 执行命令 rpm -Uvh https://packages.microsoft.com/config/centos/8/packages-microsoft-prod.rpm
  2. 安装SDK yum install dotnet-sdk-5.0
  3. 将.net发布的项目上传至一个目录如/home/testApp
  4. 运行项目cd /home/testApp dotnet testApp.dll
  5. 设置为服务,并开机启动
    1. 创建服务vim /etc/systemd/system/testApp.service 写入下面内容
        Description=testApp for centos7
    
        [Service]
        WorkingDirectory=/home/testApp/Release
        ExecStart=/usr/bin/dotnet /home/testApp/Release/testApp.dll
        Restart=always
        RestartSec=10  # Restart service after 10 seconds if dotnet service crashes
        SyslogIdentifier=dotnet-testApp
        User=root
        Environment=ASPNETCORE_ENVIRONMENT=Production
        Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
    
        [Install]
        WantedBy=multi-user.target ``` 
    
    1. 设置开机自动启动testApp.service服务 systemctl enable testApp.service
    1. 开启服务,并查询状态 systemctl start testApp.service systemctl status testApp.service