Asp .Net Core 系列:集成 Ocelot+Consul实现网关、服务注册、服务发现

news2025/2/24 2:44:53

什么是Ocelot?

Ocelot是一个开源的ASP.NET Core微服务网关,它提供了API网关所需的所有功能,如路由、认证、限流、监控等。

Ocelot是一个简单、灵活且功能强大的API网关,它可以与现有的服务集成,并帮助您保护、监控和扩展您的微服务。

以下是Ocelot的一些主要功能:

  1. 路由管理:Ocelot允许您定义路由规则,将请求路由到正确的微服务。
  2. 认证和授权:Ocelot支持多种认证机制,如JWT、OAuth等,并允许您定义访问控制策略,确保只有授权的用户才能访问特定的API。
  3. 限流和速率限制:Ocelot提供了一些内置的限流和速率限制功能,以确保您的服务不会受到过度的请求压力。
  4. 监控和日志:Ocelot可以收集和显示各种度量指标,帮助您了解您的服务的性能和行为。此外,它还可以将日志记录到各种日志源,以便您进行分析和故障排除。
  5. 集成:Ocelot可以与现有的服务集成,包括Kubernetes、Consul等。
  6. 易于扩展:Ocelot的设计使其易于扩展,您可以编写自己的中间件来处理特定的逻辑,例如修改请求或响应、添加自定义的认证机制等。
  7. 可扩展的配置:Ocelot使用JSON配置文件进行配置,这意味着您可以轻松地根据需要进行配置更改,而无需重新编译代码。

总之,Ocelot是一个功能强大且易于使用的API网关,可以帮助您保护、监控和扩展您的微服务。

Asp .Net Core 集成 Ocelot

要在ASP.NET Core中集成Ocelot,您可以按照以下步骤进行操作:

  1. 安装Ocelot NuGet包:
    在您的ASP.NET Core项目中,打开终端或NuGet包管理器控制台,并运行以下命令来安装Ocelot的NuGet包:
dotnet add package Ocelot
  1. 添加Ocelot配置文件:
{  
  "Routes": [ //这里注意一下版本(旧版本用ReRoutes)
    {
      "DownstreamPathTemplate": "/api/{controller}", //下游路径模板
      "DownstreamScheme": "http", //下游方案
      //"DownstreamHostAndPorts": [
      //  {
      //    "Host": "localhost",
      //    "Port": "5014"
      //  }
      //], //下游主机和端口
      "UpstreamPathTemplate": "/api/product/{controller}", //上游路径模板
      "UpstreamHttpMethod": [], //上游请求方法,可以设置特定的 HTTP 方法列表或设置空列表以允许其中任何方法
      "ServiceName": "api-product-service", //请求服务名称
      "LoadBalancerOptions": {
        "Type": "LeastConnection" //负载均衡算法:目前 Ocelot 有RoundRobin 和LeastConnection算法
      }
    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:5015", //进行标头查找和替换以及某些管理配置
    "ServiceDiscoveryProvider": {
      "Scheme": "http",
      "Host": "127.0.0.1", //你的Consul的ip地址
      "Port": 8500, //你的Consul的端口
      "Type": "Consul" //类型
      //"ConfigurationKey": "Consul" //指定配置键,键入您的配置
    }
  }
}
  1. 配置Ocelot服务:
builder.Services.AddOcelot();

Configure方法中配置请求管道并添加Ocelot中间件:

app.UseOcelot().Wait();

Ocelot 集成 Consul

要将Ocelot集成到Consul中,您可以按照以下步骤进行操作:

  1. 安装依赖项:
    在您的ASP.NET Core项目中,安装Ocelot和Consul的NuGet包。您可以使用以下命令来安装这些包:
dotnet add package Ocelot.Provider.Consul
  1. 配置Ocelot:
    在Ocelot的配置中,您需要指定Consul作为服务发现和配置的提供者。在Ocelot的配置文件(例如appsettings.json)中,添加以下内容:
{  
  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:5015", //进行标头查找和替换以及某些管理配置
    "ServiceDiscoveryProvider": {
      "Scheme": "http",
      "Host": "127.0.0.1", //你的Consul的ip地址
      "Port": 8500, //你的Consul的端口
      "Type": "Consul" //类型
      //"ConfigurationKey": "Consul" //指定配置键,键入您的配置
    }
  } 
}

确保将ConsulHostConsulPort设置为Consul服务器的正确地址和端口。

  1. 启动Ocelot:
    在您的ASP.NET Core应用程序中启动Ocelot。您可以在Startup.cs文件中添加以下代码:
builder.Services.AddOcelot().AddConsul(); 

全部代码

Consul相关代码

namespace MCode.Common.Extensions.Consul
{
    public class ConsulOptions
    {
        /// <summary>
        /// 当前应用IP
        /// </summary>
        public string IP { get; set; }

        /// <summary>
        /// 当前应用端口
        /// </summary>
        public int Port { get; set; }

        /// <summary>
        /// 当前服务名称
        /// </summary>
        public string ServiceName { get; set; }

        /// <summary>
        /// Consul集群IP
        /// </summary>
        public string ConsulIP { get; set; }

        /// <summary>
        /// Consul集群端口
        /// </summary>
        public int ConsulPort { get; set; }

        /// <summary>
        /// 权重
        /// </summary>
        public int? Weight { get; set; }
    }
}
using Consul.AspNetCore;
using Consul;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Builder;

namespace MCode.Common.Extensions.Consul
{
    public static class ConsulServiceExtensions
    {
        /// <summary>
        /// 向容器中添加Consul必要的依赖注入
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static IServiceCollection AddMCodeConsul(this IServiceCollection services)
        {
            var configuration = services.BuildServiceProvider().GetRequiredService<IConfiguration>();
            // 配置consul服务注册信息
            var consulOptions = configuration.GetSection("Consul").Get<ConsulOptions>();
            // 通过consul提供的注入方式注册consulClient
            services.AddConsul(options => options.Address = new Uri($"http://{consulOptions.ConsulIP}:{consulOptions.ConsulPort}"));

            // 通过consul提供的注入方式进行服务注册
            var httpCheck = new AgentServiceCheck()
            {
                DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(5),//服务启动多久后注册
                Interval = TimeSpan.FromSeconds(10),//健康检查时间间隔,或者称为心跳间隔
                HTTP = $"http://{consulOptions.IP}:{consulOptions.Port}/health",//健康检查地址
                Timeout = TimeSpan.FromSeconds(10)
            };

            // Register service with consul
            services.AddConsulServiceRegistration(options =>
            {
                options.Checks = new[] { httpCheck };
                options.ID = Guid.NewGuid().ToString();
                options.Name = consulOptions.ServiceName;
                options.Address = consulOptions.IP;
                options.Port = consulOptions.Port;
                options.Meta = new Dictionary<string, string>() { { "Weight", consulOptions.Weight.HasValue ? consulOptions.Weight.Value.ToString() : "1" } };
                options.Tags = new[] { $"urlprefix-/{consulOptions.ServiceName}" }; //添加
            });

            return services;
        }

        /// <summary>
        /// 配置Consul检查服务
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseConsulCheckService(this IApplicationBuilder app)
        {
            app.Map("/health", app =>
            {
                app.Run(async context =>
                {
                    await Task.Run(() => context.Response.StatusCode = 200);
                });
            });

            return app;
        }
    }
}

Cors

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MCode.Common.Extensions.Cors
{
    public static class CorsServiceExtensions
    {
        private readonly static string PolicyName = "MCodeCors";

        /// <summary>
        /// 添加跨域
        /// </summary>
        /// <param name="services">服务集合</param>
        /// <returns></returns>
        public static IServiceCollection AddMCodeCors(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));
            //origin microsoft.aspnetcore.cors      
            return services.AddCors(options =>
            {
                options.AddPolicy(PolicyName, policy =>
                {
                    policy.SetIsOriginAllowed(_ => true).AllowAnyMethod().AllowAnyHeader().AllowCredentials();
                });
            });
        }
        /// <summary>
        /// 使用跨域
        /// </summary>
        /// <param name="app">应用程序建造者</param>
        /// <returns></returns>
        public static IApplicationBuilder UseMCodeCors(this IApplicationBuilder app)
        {
            return app.UseCors(PolicyName);
        }
    }
}

Swagger

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MCode.Common.Extensions.Swagger
{
    /// <summary>
    /// 网关Swagger配置
    /// </summary>
    public class OcelotSwaggerOptions
    {
        public List<SwaggerEndPoint> SwaggerEndPoints { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MCode.Common.Extensions.Swagger
{
    /// <summary>
    /// 网关Swagger配置
    /// </summary>
    public class OcelotSwaggerOptions
    {
        public List<SwaggerEndPoint> SwaggerEndPoints { get; set; }
    }
}
using Microsoft.OpenApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MCode.Common.Extensions.Swagger
{
    /// <summary>
    /// Swagger配置
    /// </summary>
    public class SwaggerOptions
    {
        /// <summary>
        /// 服务名称
        /// </summary>
        public string ServiceName { get; set; }

        /// <summary>
        /// API信息
        /// </summary>
        public OpenApiInfo ApiInfo { get; set; }

        /// <summary>
        /// Xml注释文件
        /// </summary>
        public string[] XmlCommentFiles { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="serviceName">服务名称</param>
        /// <param name="apiInfo">API信息</param>
        /// <param name="xmlCommentFiles">Xml注释文件</param>
        public SwaggerOptions(string serviceName, OpenApiInfo apiInfo, string[] xmlCommentFiles = null)
        {
            ServiceName = !string.IsNullOrWhiteSpace(serviceName) ? serviceName : throw new ArgumentException("serviceName parameter not config.");
            ApiInfo = apiInfo;
            XmlCommentFiles = xmlCommentFiles;
        }
    }
}
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;

namespace MCode.Common.Extensions.Swagger
{
    /// <summary>
    /// Swagger 服务扩展
    /// </summary>
    public static class SwaggerServiceExtensions
    {
        /// <summary>
        /// 添加 Swagger 服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="swaggerOptions"></param>
        /// <returns></returns>
        public static IServiceCollection AddMCodeSwagger(this IServiceCollection services, SwaggerOptions swaggerOptions)
        {
            services.AddSingleton(swaggerOptions);

            SwaggerGenServiceCollectionExtensions.AddSwaggerGen(services, c =>
            {
                c.SwaggerDoc(swaggerOptions.ServiceName, swaggerOptions.ApiInfo);

                if (swaggerOptions.XmlCommentFiles != null)
                {
                    foreach (string xmlCommentFile in swaggerOptions.XmlCommentFiles)
                    {
                        string str = Path.Combine(AppContext.BaseDirectory, xmlCommentFile);
                        if (File.Exists(str)) c.IncludeXmlComments(str, true);
                    }
                }

                SwaggerGenOptionsExtensions.CustomSchemaIds(c, x => x.FullName);

                c.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme
                {
                    Type = SecuritySchemeType.Http,
                    Scheme = "bearer",
                    BearerFormat = "JWT",
                    Description = "请输入 bearer 认证"
                });


                c.AddSecurityRequirement(new OpenApiSecurityRequirement
                                              {
                                                  {
                                                      new OpenApiSecurityScheme
                                                      {
                                                          Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "bearerAuth" }
                                                      },
                                                      new string[] {}
                                                  }
                                              });
            });

            return services;
        }

        /// <summary>
        /// 使用 Swagger UI
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseMCodeSwagger(this IApplicationBuilder app)
        {
            string serviceName = app.ApplicationServices.GetRequiredService<SwaggerOptions>().ServiceName;

            SwaggerUIBuilderExtensions.UseSwaggerUI(SwaggerBuilderExtensions.UseSwagger(app), c =>
            {
                c.SwaggerEndpoint("/swagger/" + serviceName + "/swagger.json", serviceName);
            });
            return app;
        }


        public static IServiceCollection AddMCodeOcelotSwagger(this IServiceCollection services, OcelotSwaggerOptions ocelotSwaggerOptions)
        {
            services.AddSingleton(ocelotSwaggerOptions);
            SwaggerGenServiceCollectionExtensions.AddSwaggerGen(services);
            return services;
        }

        public static IApplicationBuilder UseMCodeOcelotSwagger(this IApplicationBuilder app)
        {
            OcelotSwaggerOptions ocelotSwaggerOptions = app.ApplicationServices.GetService<OcelotSwaggerOptions>();

            if (ocelotSwaggerOptions == null || ocelotSwaggerOptions.SwaggerEndPoints == null)
            {
                return app;
            }

            SwaggerUIBuilderExtensions.UseSwaggerUI(SwaggerBuilderExtensions.UseSwagger(app), c =>
            {
                foreach (SwaggerEndPoint swaggerEndPoint in ocelotSwaggerOptions.SwaggerEndPoints)
                {
                    c.SwaggerEndpoint(swaggerEndPoint.Url, swaggerEndPoint.Name);
                }
            });
            return app;
        }
    }
}

MCode.ApiGateway.Program

using MCode.Common.Extensions.Swagger;
using MCode.Common.Extensions.Consul;
using MCode.Common.Extensions.Cors;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Provider.Consul;
using Microsoft.AspNetCore.Hosting;

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.UseUrls(builder.Configuration.GetValue<string>("Url") ?? "");

//builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("ocelot.json", false, true);

// Add services to the container.
builder.Services.AddMCodeConsul();

builder.Services.AddMCodeCors();

builder.Services.AddMCodeOcelotSwagger(new OcelotSwaggerOptions { SwaggerEndPoints = new List<SwaggerEndPoint> { new SwaggerEndPoint { Name = "api-product-service", Url= "http://localhost:5014/swagger/api-product-service/swagger.json" } } });

builder.Services.AddOcelot().AddConsul();

builder.Services.AddControllers();

var app = builder.Build();

app.UseMCodeCors();

app.UseMCodeOcelotSwagger();

app.UseConsulCheckService();

// Configure the HTTP request pipeline.

app.UseAuthorization();

app.UseOcelot().Wait();

app.Run();

appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "Routes": [ //这里注意一下版本(旧版本用ReRoutes)
    {
      "DownstreamPathTemplate": "/api/{controller}", //下游路径模板
      "DownstreamScheme": "http", //下游方案
      //"DownstreamHostAndPorts": [
      //  {
      //    "Host": "localhost",
      //    "Port": "5014"
      //  }
      //], //下游主机和端口
      "UpstreamPathTemplate": "/api/product/{controller}", //上游路径模板
      "UpstreamHttpMethod": [], //上游请求方法,可以设置特定的 HTTP 方法列表或设置空列表以允许其中任何方法
      "ServiceName": "api-product-service", //请求服务名称
      "LoadBalancerOptions": {
        "Type": "LeastConnection" //负载均衡算法:目前 Ocelot 有RoundRobin 和LeastConnection算法
      }
    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:5015", //进行标头查找和替换以及某些管理配置
    "ServiceDiscoveryProvider": {
      "Scheme": "http",
      "Host": "127.0.0.1", //你的Consul的ip地址
      "Port": 8500, //你的Consul的端口
      "Type": "Consul" //类型
      //"ConfigurationKey": "Consul" //指定配置键,键入您的配置
    }
  },
  "Url": "http://localhost:5015",
  "Consul": {
    "ConsulIP": "127.0.0.1",
    "ConsulPort": "8500",
    "ServiceName": "api-gateway",
    "Ip": "localhost",
    "Port": "5015",
    "Weight": 1
  },
  "AllowedHosts": "*"
}

MCode.Product.Api.Program

using MCode.Product.Api;
using MCode.Common.Extensions.Consul;
using MCode.Common.Extensions.Cors;
using MCode.Common.Extensions.Swagger;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.WebHost.UseUrls(builder.Configuration.GetValue<string>("Url") ?? "");

builder.Services.AddControllers();

builder.Services.AddMCodeConsul();

builder.Services.AddMCodeCors();

builder.Services.AddMCodeSwagger(new SwaggerOptions("api-product-service", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "产品服务" }, new string[] { "MCode.Product.Api.xml" }));


var app = builder.Build();

app.UseAuthorization();


app.UseMCodeCors();

app.UseMCodeSwagger();

app.UseConsulCheckService();


app.MapControllers();

app.Run();

appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "Url": "http://localhost:5014",
  "Consul": {
    "ConsulIP": "127.0.0.1",
    "ConsulPort": "8500",
    "ServiceName": "api-product-service",
    "Ip": "localhost",
    "Port": "5014",
    "Weight": 1
  }
}

效果

image

image

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1391666.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

编写RedisUtil来操作Redis

目录 ​编辑 Redis中文网 第一步&#xff1a;建springboot项目 第二步&#xff1a;导依赖 第三步&#xff1a;启动类 第四步&#xff1a;yml 第五步&#xff1a;Redis配置类 第六步&#xff1a;测试类 第七步&#xff1a;编写工具类 RedisUtil 第八步&#xff1a;编写…

C++核心编程——文件操作

本专栏记录C学习过程包括C基础以及数据结构和算法&#xff0c;其中第一部分计划时间一个月&#xff0c;主要跟着黑马视频教程&#xff0c;学习路线如下&#xff0c;不定时更新&#xff0c;欢迎关注。 当前章节处于&#xff1a; ---------第1阶段-C基础入门 ---------第2阶段实战…

基于python集成学习算法XGBoost农业数据可视化分析预测系统

文章目录 基于python集成学习算法XGBoost农业数据可视化分析预测系统一、项目简介二、开发环境三、项目技术四、功能结构五、功能实现模型构建封装类用于网格调参训练模型系统可视化数据请求接口模型评分 0.5*mse 六、系统实现七、总结 基于python集成学习算法XGBoost农业数据可…

国内小白最靠谱的充值chatgpt的方法是什么?

在AI越来越火得时代&#xff0c;大家都想尝试以下ChatGPT与ChatGPTPlus有什么不同&#xff0c;那么我们如何使用靠谱得方式来充值ChatGPT呢&#xff1f; 充值注意事项&#xff1a; 1、一个干净得环境 2、Fomepay得虚拟卡&#xff0c;5347/5561/都可以 3、登录ChatGPT 按图片…

LLM:Training Compute-Optimal Large Language Models

论文&#xff1a;https://arxiv.org/pdf/2203.15556.pdf 发表&#xff1a;2022 前文回顾&#xff1a; OpenAI在2020年提出《Scaling Laws for Neural Language Models》&#xff1a;Scaling Laws(缩放法则&#xff09;也一直影响了后续大模型的训练。其给出的结论是最佳计算效…

工具推荐 |Devv.ai — 最懂程序员的新一代 AI 搜索引擎

介绍 伴随 GPT 的出现&#xff0c;我们可以看到越来越多的 AI 产品&#xff0c;其中也不乏针对程序员做的代码生成工具。 今天介绍的这款产品是一款针对中文开发者的 AI 搜索引擎&#xff0c;Devv.ai 使用 Devv.ai 的使用非常简单&#xff0c;就是传统的搜索场景&#xff…

高级分布式系统-第10讲 分布式控制系统

高级分布式系统汇总&#xff1a;高级分布式系统目录汇总-CSDN博客 自动化是关于一切人造系统自动、智能、自主、高效和安全运行的科学与技术 计算机控制技术是实现自动化的主要方法和手段 分布式控制技术是伴随着机器大工业生产而诞生的特殊计算机控制技术 计算机控制系统 …

rust获取本地ip地址的方法

大家好&#xff0c;我是get_local_info作者带剑书生&#xff0c;这里用一篇文章讲解get_local_info的使用。 get_local_info是什么&#xff1f; get_local_info是一个获取linux系统信息的rust三方库&#xff0c;并提供一些常用功能&#xff0c;目前版本0.2.4。详细介绍地址&a…

MSSQL-识别扩展extended event(扩展事件)中的时间单位

经常使用sqlserver extended event(扩展事件)&#xff0c;但是总是忘记扩展事件使用的时间单位&#xff0c;不确定它们是 秒、毫秒、还是微秒&#xff1f; 以下下代码能够从 相关DMV中提取description字段内容来识别时间单位&#xff1a; SELECT [p].[name] [package_name],[o…

企业网站建站源码系统:Thinkphp5内核企业网站建站模板源码 带完整的安装代码包以及搭建教程

随着互联网的快速发展&#xff0c;企业对于网站的需求日益增强。为了满足这一市场需求&#xff0c;小编给大家分享一款基于Thinkphp5内核的企业网站建站源码系统。该系统旨在为企业提供一套功能强大、易于使用的网站建设解决方案&#xff0c;帮助企业快速搭建自己的官方网站&am…

探索数据的奥秘:一份深入浅出的数据分析入门指南

数据分析 书籍推荐 入门读物 深入浅出数据分析啤酒与尿布数据之美数学之美 数据分析 Scipy and NumpyPython for Data AnalysisBad Data Handbook集体智慧编程Machine Learning in Action机器学习实战Building Machine Learning Systems with Python数据挖掘导论Machine L…

LLM:Scaling Laws for Neural Language Models (上)

论文&#xff1a;https://arxiv.org/pdf/2001.08361.pdf 发表&#xff1a;2020 摘要1&#xff1a;损失与模型大小、数据集大小以及训练所用计算量成比例&#xff0c;其中一些趋势跨越了七个量级以上。 2&#xff1a;网络宽度或深度等其他架构细节在很大范围内影响较小。3&…

两道有挑战的问题(算法村第九关黄金挑战)

将有序数组转换为二叉搜索树 108. 将有序数组转换为二叉搜索树 - 力扣&#xff08;LeetCode&#xff09; 给你一个整数数组 nums &#xff0c;其中元素已经按 升序 排列&#xff0c;请你将其转换为一棵 高度平衡 二叉搜索树。 高度平衡 二叉树是一棵满足「每个节点的左右两个…

rust跟我学五:是否安装双系统

图为RUST吉祥物 大家好,我是get_local_info作者带剑书生,这里用一篇文章讲解get_local_info是怎么得到检测双系统的。 首先,先要了解get_local_info是什么? get_local_info是一个获取linux系统信息的rust三方库,并提供一些常用功能,目前版本0.2.4。详细介绍地址:[我的Ru…

【JVM】常用命令

一、前言 Java虚拟机&#xff08;JVM&#xff09;是Java程序运行的基础设施&#xff0c;它负责将Java字节码转换为本地机器代码并执行。在开发过程中&#xff0c;我们经常需要使用一些命令来监控和管理JVM的性能和状态。本文将详细介绍6个常用的JVM命令&#xff1a;jps、jstat…

C语言——编译和链接

&#xff08;图片由AI生成&#xff09; 0.前言 C语言是最受欢迎的编程语言之一&#xff0c;以其接近硬件的能力和高效性而闻名。理解C语言的编译和链接过程对于深入了解其运行原理至关重要。本文将详细介绍C语言的翻译环境和运行环境&#xff0c;重点关注编译和链接的各个阶段…

含并行连结的网络(GoogLeNet)

目录 1.GoogLeNet 2.代码 1.GoogLeNet inception不改变高宽&#xff0c;只改变通道数。GoogLeNet也大量使用1*1卷积&#xff0c;把它当作全连接用。 V3耗内存比较多&#xff0c;计算比较慢&#xff0c;但是精度比较准确。 2.代码 import torch from torch import nn from t…

未来的NAS:连接您的数字生活

未来的NAS&#xff1a;连接您的数字生活 引言 网络附加存储&#xff08;Network Attached Storage&#xff0c;简称NAS&#xff09;是一种通过网络连接的存储设备&#xff0c;用于集中存储和共享数据。传统的NAS设备通常包含一个或多个硬盘驱动器&#xff0c;可以通过局域网连…

2024.1.14每日一题

LeetCode 83.删除排序链表中的重复元素 83. 删除排序链表中的重复元素 - 力扣&#xff08;LeetCode&#xff09; 题目描述 给定一个已排序的链表的头 head &#xff0c; 删除所有重复的元素&#xff0c;使每个元素只出现一次 。返回 已排序的链表 。 示例 1&#xff1a; 输…

.NET 8.0 发布到 IIS

如何在IIS&#xff08;Internet信息服务&#xff09;上发布ASP.NET Core 8&#xff1f; 在本文中&#xff0c;我假设您的 Windows Server IIS 上已经有一个应用程序池。 按照步骤了解在 IIS 环境下发布 ASP.NET Core 8 应用程序的技巧。 您需要设置代码以支持 IIS 并将项目配…