CentOS搭建.NET Core开发环境

参考:腾讯云手动实验 https://cloud.tencent.com/developer/labs/lab/10100
⁩⁨ ⁩


.NET Core 是.NET Framework的新一代版本,是微软开发的第一个官方版本,具有跨平台 (Windows、Mac OSX、Linux) 能力的应用程序开发框架
(Application Framework)。


安装.Net Core执行代码

安装.Net Core

[root@localhost ~]# yum -y install libunwind libicu
[root@localhost ~]# curl -SL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?linkid=848821
[root@localhost ~]# mkdir /usr/local/dotnet
[root@localhost ~]# tar zxf dotnet.tar.gz -C /usr/local/dotnet
[root@localhost ~]# ln -s /usr/local/dotnet/dotnet /usr/local/bin/

创建 Hello World 控制台程序

创建hwapp项目

[root@localhost ~]# dotnet new console -o hwapp
...
The template "Console Application" created successfully.

运行项目

[root@localhost ~]# cd hwapp
[root@localhost hwapp]# dotnet restore
[root@localhost hwapp]# dotnet run
Hello World!
创建并运行 ASP.NET Core Web 应用

[root@localhost hwapp]# cd /home
[root@localhost home]# mkdir aspnetcoreapp
[root@localhost home]# cd aspnetcoreapp/
[root@localhost aspnetcoreapp]# dotnet new web
Content generation time: 282.8633 ms
The template "ASP.NET Core Empty" created successfully.
[root@localhost aspnetcoreapp]# dotnet restore
# 阻塞方式,启动成功ctrl-c打断即可
[root@localhost aspnetcoreapp]# dotnet run
Hosting environment: Production
Content root path: /home/aspnetcoreapp
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

安装Jexus


通常情况下,对外提供的 Web 服务都在 80或者443 端口,而我们的 Web 应用程序默认运行在5000端口,在 Windows 上可以使用 IIS 来宿主 ASP.NET Core,在 Linux 下可以用 Nginx,Apache,Jexus 等来作为宿主。这里以Jexus为例


安装独立版Jexus

[root@localhost ~]# curl https://jexus.org/release/x64/install.sh|sh
...
OK, Jexus has been installed in /usr/jexus.

独立版 Jexus 自带 Mono,使用的是Mono的稳定版本 4.8。


配置Jexus

将aspnetcoreapp部署到Jexus

[root@localhost ~]# cd /home/aspnetcoreapp/
[root@localhost aspnetcoreapp]# dotnet publish -o /var/www/aspnetcore/
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.
 
  aspnetcoreapp -> /home/aspnetcoreapp/bin/Debug/netcoreapp1.1/aspnetcoreapp.dll

启动服务监听端口

# 阻塞,启动成功ctrl-c打断即可
[root@localhost aspnetcoreapp]# dotnet /var/www/aspnetcore/aspnetcoreapp.dll
Hosting environment: Production
Content root path: /home/aspnetcoreapp
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

配置Jexus网站

创建aspnetcore配置文件

[root@localhost aspnetcoreapp]# cd /usr/jexus/siteconf/
[root@localhost siteconf]# cp default aspnetcore
[root@localhost siteconf]# vim aspnetcore 
root=/ /var/www/aspnetcore
# 添加
AppHost={
    cmd=dotnet /var/www/aspnetcore/aspnetcoreapp.dll;
    root=/var/www/aspnetcore;
    port=0;
}

配置的重点就在于AppHost,AppHost中的port不代表Jexus对外服务的端口号,而是指要转发的 Asp.Net Core 应用程序的端口号。不建议使用 UsrUrls 自定义端口,端口号设置为 0,Jexus 会在运行时与 Asp.Net Core 进行”协商”具体使用的端口号,避免端口冲突的风险。


启动Jexus

[root@localhost siteconf]# sh /usr/jexus/jws start
Restarting ... OK

验证

[root@localhost ~]# curl 1.1.1.5
Hello World!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值