centos7下.net5环境搭建、创建.net5程序、设置开机自动启动

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

一:.netcore环境搭建

1、执行命令

rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm

 

2、更新yum

 yum update

 

3、安装.netcore 

yum install dotnet-sdk-5.0

 

二:创建.netcore web程序并运行

1、定位到你想放置项目的位置,创建项目

cd /home    dotnet new webApp -o testApp --no-https

2、直接发布项目到项目文件夹

cd testApp

dotnet publish -o /home/testApp/Release

 

3、测试运行.netcore程序

cd release

dotnet testApp.dll

 

三:设置.netcore程序开机启动

1、创建服务文件

vim /etc/systemd/system/testApp.service

 写入如下内容:

[Unit]
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

2、设置开机自动启动testApp.service服务

systemctl enable testApp.service

3、开启服务,并查询状态

systemctl start testApp.service
systemctl status testApp.service

 

安装图形GDI

yum install libgdiplus-devel -y

ln -s /usr/lib64/libgdiplus.so /usr/lib/gdiplus.dll

ln -s /usr/lib64/libgdiplus.so /usr/lib64/gdiplus.dll