一:安装环境命令:
1、签名密钥添加到受信任密钥列表,并添加 Microsoft 包存储库
sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
2、查看可以安装的 dotnet -SDK
yum search dotnet-sdk
3、安装适合的版本
sudo yum install dotnet-sdk-6.0
4、查看安装的环境
dotnet --list-sdks
dotnet --list-runtimes
5、发布 Core 项目,上传到Linux服务器
6、命令启动
dotnet myproduct_core.dll --urls=http://*:5000 //端口可以自己设置
运行项目http://192.168.203.134:5000
结果:成功/失败
失败原因:防火墙端口没有开启
#查看防火墙状态
sudo firewall-cmd --state
#开放永久5000端口
sudo firewall-cmd --zone=public --add-port=5000/tcp --permanent
#重启防火墙
sudo firewall-cmd --reload
#查看防火墙开放的端口
sudo firewall-cmd --list-ports
问题1:关闭远程链接后,发现访问不了,进程停了,所以要设置一个24小时的自动启动守护进程
问题2:Unable to configure HTTPS endpoint. No server certificate was specified, and the default
解决方案:
-
dotnet dev-certs https --clean
-
dotnet dev-certs https -t
二:CentOS 7 下设置.net core项目开机自动启动
1、在etc/systemd/system 下创建 xxx.service 文件
vi /etc/systemd/system/xxx.service
2、编辑 xxx.service 文件
[Unit]
Description="abc Service"
[Service]
Type=simple
GuessMainPID=true
WorkingDirectory=/www/core/ #项目路径
StandardOutput=journal
StadardError=journal
ExecStart=/usr/bin/dotnet MyCs.dll --urls=http://*:5000 # 执行启动命令
Restart=always
[Install]
WantedBy=multi-user.target
粘贴上去过后怎么保存?
首先先按Esc键 ,然后输入:号,然后输入wq,最后回车
顺序为:Esc-->:--->wq-->敲回车
3、自动启动生效
systemctl enable xxx.service
4、启动服务进程
systemctl start xxx.service
5、查看进程状态
systemctl status xxx.service
6、重启服务器
shutdown -r now
7、测试项目
访问:http://ip地址:5000