您的位置 首页 > 数码极客

解决方案中如何创建apivs如何创建解决方案…

.Net Core Web Api开发教程 Part 1

.Net Core Web Api开发教程 Part 2

接上一篇我们继续

5.发布接口程序到服务器( windows & centos & docker )

1.发布项目文件

1).在解决方案中项目上右键选择“发布”

2).在windows(我使用的是win11;win10和win7安装方法一样)下IIS中安装.net core运行环境

a).下载 .net core hosting Download .NET Core 3.1 (Linux, macOS, and Windows) )

b).IIS创建应用程序池

c).IIS创建站点(自定义网站名称,选择刚才创建的程序池,设置网站内容的物理路径【就是上面项目发布后的文件】,绑定网站是HTTP还是HTTPS类型,网站端口配置,如果是发布到服务器上通常是通过域名来访问,所以下面的主机名就是你解析到服务器的域名【访问前记得解析域名哟】)

d).测试站点是否能正常运行(在浏览器里访问一个我们之前编写好的接口)

到这里IIS部署.net core项目已经完成了,是不是很简单,下面我们就要开始在centos里部署.net core

3).在CentOS(我使用的是cen版本)上安装.net core运行环境

a),安装

sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/

需要先安装微软在Linux下的软件包,执行以上命令即可;

b),更新yum

sudo yum update

更新软件包,执行以上命令即可;

c),安装.Net Core (本文安装的是.Net Core 3.1)

sudo yum install do

至此,.Net Core在Linux下安装成功,如下图所示:

dotnet --version

整个过程输出如下:

[root@VM-0-2-centos ~]# sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/ Retrieving https://packages.microsoft.com/config/rhel/7/ Preparing... ################################# [100%] package is already installed [root@VM-0-2-centos ~]# sudo yum update Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile No packages marked for update [root@VM-0-2-centos ~]# sudo yum install do Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running Transaction check ---> Package do.x86_64 0:3.1.412-1 will be installed --> Processing Dependency: do for package: do-3.1.412-1.x86_64 --> Processing Dependency: a for package: do-3.1.412-1.x86_64 --> Running transaction check ---> Package a.x86_64 0:3.1.18-1 will be installed ---> Package do.x86_64 0:3.1.18-1 will be installed --> Processing Dependency: do >= 3.1.18 for package: do-3.1.18-1.x86_64 --> Running transaction check ---> Package do.x86_64 0:3.1.18-1 will be installed --> Processing Dependency: libicu for package: do-3.1.18-1.x86_64 --> Running transaction check ---> Package libicu.x86_64 0:50.2-4.el7_7 will be installed --> Finished Dependency Resolution Dependencies Resolved =========================================================================================================== Package Arch Version Repository Size =========================================================================================================== Installing: do x86_64 3.1.412-1 packages-microsoft-com-prod 71 M Installing for dependencies: a x86_64 3.1.18-1 packages-microsoft-com-prod 7.5 M do x86_64 3.1.18-1 packages-microsoft-com-prod 29 M do x86_64 3.1.18-1 packages-microsoft-com-prod 2.8 k libicu x86_64 50.2-4.el7_7 os 6.9 M Transaction Summary =========================================================================================================== Install 1 Package (+4 Dependent packages) Total download size: 114 M Installed size: 298 M Is this ok [y/d/N]: y Downloading packages: (1/5): a.18-x64.rpm | 7.5 MB 00:00:00 (2/5): do.18-rhel.7-x64.rpm | 2.8 kB 00:00:00 (3/5): libicu-50.2-4.el7_7.x86_64.rpm | 6.9 MB 00:00:00 (4/5): do.412-x64.rpm | 71 MB 00:00:08 (5/5): do.18-x64.rpm | 29 MB 00:00:39 ----------------------------------------------------------------------------------------------------------- Total 2.9 MB/s | 114 MB 00:00:39 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libicu-50.2-4.el7_7.x86_64 1/5 Installing : do-3.1.18-1.x86_64 2/5 Installing : do-3.1.18-1.x86_64 3/5 Installing : a-3.1.18-1.x86_64 4/5 Installing : do-3.1.412-1.x86_64 5/5 This software may collect information about you and your use of the software, and send that to Microsoft. Please visit for more information. Welcome to .NET Core! --------------------- Learn more about .NET Core: Use 'dotnet --help' to see available commands or visit: Telemetry --------- The .NET Core tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. Read more about .NET Core CLI Tools telemetry: Configuring... -------------- A command is running to populate your local package cache to improve restore speed and enable offline access. This command takes up to one minute to complete and only runs once. Verifying : do-3.1.412-1.x86_64 1/5 Verifying : do-3.1.18-1.x86_64 2/5 Verifying : a-3.1.18-1.x86_64 3/5 Verifying : do-3.1.18-1.x86_64 4/5 Verifying : libicu-50.2-4.el7_7.x86_64 5/5 Installed: do.x86_64 0:3.1.412-1 Dependency Installed: a.x86_64 0:3.1.18-1 do.x86_64 0:3.1.18-1 do.x86_64 0:3.1.18-1 libicu.x86_64 0:50.2-4.el7_7 Complete! [root@VM-0-2-centos ~]# dotnet --version 3.1.412

4).上传发布后的版本到服务器

4).运行.net core程序,进入sample01目录后执行以下命令

[root@VM-0-2-centos sample01]# dotnet

5).验证服务是否能够访问

说明我们发布的.net core web api服务已经在centos 7.5上运行起来了

下一篇我们再把.net core web api服务部署到docker容器上

源码地址:

同步系统视频会尽快发布,请有需要的朋友关注我



责任编辑: 鲁达

1.内容基于多重复合算法人工智能语言模型创作,旨在以深度学习研究为目的传播信息知识,内容观点与本网站无关,反馈举报请
2.仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证;
3.本站属于非营利性站点无毒无广告,请读者放心使用!

“解决方案中如何创建api,vs如何创建解决方案,在一个解决方案中可以创建多个项目,同一个解决方案创建多个项目,qt如何创建解决方案,如何写好解决方案”边界阅读