记录Dotnet6Webapi项目部署到阿里云Centos8的操作步骤

192 阅读1分钟

1.使用vs2022创建一个webapi项目,并且发布

image.png

2.将publish文件夹内的文件上传至阿里云linux系统你能找到的位置

image.png

image.png

3.阿里云服务器控制台开启项目运行需要的端口

image.png

4.在阿里云服务器linux系统开放指定端口

image.png sudo firewall-cmd --zone=public --add-port=5134/tcp --permanent

sudo firewall-cmd --reload

5.运行webapi项目

image.png

浏览器访问成功

image.png

6.设置Supervisor后台守护进程

当关闭xshell会话连接时会发现webapi无法访问了,这是因为终端关闭时,依附于这个终端的相应进程会自动关闭,设置守护进程能解决这个问题。

安装supervisor

yum install epel-release

yum install supervisor

进入/etc/supervisord.d 目录新建 .ini配置文件

image.png

image.png

.ini 文件内容

[program:test2]
command= dotnet test2.dll
directory=/usr/local/dotnet6Demo/webapiDemo1
environment=ASPNETCORE_ENVIRONMENT=Production
user=root
autostart=true
autorestart=true
stderr_logfile=/var/log/test2.err.log
stdout_logfile=/var/log/test2.out.log

设置supervisor开机自启

systemctl enable supervisord.service

启动supervisor进程守护

systemctl start supervisord.service

加载新的配置

supervisorctl update

重新启动webapi

supervisorctl restart test2

image.png

此时关闭了xshell终端,webapi依然可以正常访问。