1 安装.netCore运行时
#注册Microsoft密钥
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
#更新yum库,获取最新
sudo yum update
#安装.netcore3.1
sudo yum install aspnetcore-runtime-3.1
#查看是否安装成功
dotnet --version
dotnet --info
2.运行
cd /var
mkdir YunHosCore
cd YunHosCore
将生成的项目文件夹放到YunHosCore目录下
#进入文件夹路径
cd net5.0
启动方法1:(仅用于测试)
#启动(默认是5001端口启动,Program.cs里面使用UseUrls(“http://*:5001”)指定的)
dotnet YunHosCore.dll
启动方法2:(服务启动方式,推荐使用)
cd /etc/systemd/system
#创建服务文件
vi yunhoscore.service
[Unit]
Description=Example .NET Web API App running
[Service]
WorkingDirectory=/var/YunHosCore/net5.0/
ExecStart=/usr/bin/dotnet /var/YunHosCore/net5.0/YunHosCore.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
[Install]
WantedBy=multi-user.target
#保存并启动该服务
sudo systemctl enable yunhoscore.service
sudo systemctl start yunhoscore.service
#查看状态
sudo systemctl status yunhoscore.service
启动方法3:(使用Jexus,适合多个项目)
安装方法参考这篇文章
https://blog.csdn.net/qq_40112494/article/details/127110917?spm=1001.2014.3001.5502
3.开放端口,访问地址
#开放5001端口
firewall-cmd --zone=public --add-port=5001/tcp --permanent
#重启防火墙
firewall-cmd --reload
浏览其中输入http://192.168.8.35:7019/yunhos即可访问