centos netcore开机启动
#centos 安装.net6
https://learn.microsoft.com/zh-tw/dotnet/core/install/linux-centos
1.注册Microsoft密钥,安装.NET之前,需要注册Microsoft密钥,注册产品存储库并安装所需的依赖项
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
2.然后安装.Net Core SDK
sudo yum install dotnet-sdk-6.0
3. Install .NET Core Runtime【安装.Net Core Runtime】
sudo yum update sudo yum install aspnetcore-runtime-6.0
4.安装完成后,查看安装环境版本信息
安装完成后,查看安装环境版本信息
#centos 安装.net7
https://learn.microsoft.com/zh-tw/dotnet/core/install/linux-centos
1.注册Microsoft密钥,安装.NET之前,需要注册Microsoft密钥,注册产品存储库并安装所需的依赖项
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
2.然后安装.Net Core SDK
sudo yum install dotnet-sdk-7.0
3. Install .NET Core Runtime【安装.Net Core Runtime】
sudo yum update sudo yum install aspnetcore-runtime-7.0
4.安装完成后,查看安装环境版本信息
安装完成后,查看安装环境版本信息
vi /etc/systemd/system/demoNetCore.service
[Unit]
Description=AspnetCoreDemo running on Centos8
[Service]
# 应用程序所在的文件目录
WorkingDirectory=/www/wwwroot/demo.cn/
ExecStart=/usr/share/dotnet/dotnet /www/wwwroot/demo.cn/Jb.Web.dll
Restart=always
# 如果dotnet服务崩溃,10秒后重新启动服务
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=AspNetCoreDemo
User=root
#Production:生产环境 Development:开发环境
Environment=ASPNETCORE_ENVIRONMENT=Development
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
# 重载系统
systemctl daemon-reload
# 开机自启动
systemctl enable aspnetCore.service
2.使自启动生效
systemctl enable demoNetCore.service
3.立即启动项目服务
systemctl start demoNetCore.service
systemctl stop demoNetCore.service
systemctl restart demoNetCore.service
systemctl list-units --type=service