首页 > 系统相关 >consul 使用总结 & Nginx 负责均衡,最大连接数据,超时次数,超时等待时间,权重

consul 使用总结 & Nginx 负责均衡,最大连接数据,超时次数,超时等待时间,权重

时间:2023-07-13 16:44:06浏览次数:34  
标签:http weight -- ip consul 等待时间 proxy 超时 port

consul 使用总结 & Nginx 负责均衡,最大连接数据,超时次数,超时等待时间,权重

  1. consul agnet -dev 启动consul

  2. 启动服务,注册服务:
    dotnet OrderServer.dll --urls="http://:5189" --ip="127.0.0.1“ --port=5189
    dotnet OrderServer.dll --urls="http://
    :5188" --ip="127.0.0.1“ --port=5188

3.服务注入及健康检查接口:
program.cs:
app.MapGet("/Api/Health/Index", (HttpContext httpContext) =>
{
Console.WriteLine($"This is Health Check");
httpContext.Response.StatusCode = (int)HttpStatusCode.OK;
return "OK";
});
app.Configuration.ConsulRegist();//在进程启动过程完成-且只完成一次.

4.注册服务代码:
ConsulRegist():
public static class ConsulHelper
{
public static void ConsulRegist(this IConfiguration configuration)
{
ConsulClient client = new ConsulClient(c =>
{
c.Address = new Uri("http://localhost:8500/");
c.Datacenter = "dc1";
});//找到consul
string ip = string.IsNullOrWhiteSpace(configuration["ip"]) ? "127.0.0.1" : configuration["ip"];
int port = string.IsNullOrWhiteSpace(configuration["port"]) ? 5726 : int.Parse(configuration["port"]);//命令行参数必须传入
int weight = string.IsNullOrWhiteSpace(configuration["weight"]) ? 1 : int.Parse(configuration["weight"]);
client.Agent.ServiceRegister(new AgentServiceRegistration()
{
ID = "service" + Guid.NewGuid(),
Name = "OrderService",//Group--分组,通过这个方法注册的服务都属于OrderService
Address = ip,//
Port = port,//
Tags = new string[] { weight.ToString() },//标签
Check = new AgentServiceCheck()
{
Interval = TimeSpan.FromSeconds(12),//间隔12s一次
HTTP = $"http://{ip}:{port}/Api/Health/Index",//控制器
Timeout = TimeSpan.FromSeconds(5),//检测等待时间
DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(120)//失败后多久移除
}
});
//命令行参数获取
Console.WriteLine($"注册成功:{ip}:{port}--weight:{weight}");
}
}

--------------Nginx 负责均衡,最大连接数据,超时次数,超时等待时间,权重 -----------------------
1.api:
dotnet OrderServer.dll --urls="http://:5177" --ip="127.0.0.1“ --port=5177
dotnet OrderServer.dll --urls="http://
:5177" --ip="127.0.0.1“ --port=5178

2.nginx配置:

代理服务

upstream myserver{
  server 127.0.0.1:5177 max_fails=3 fail_timeout=20s weight=100 max_conns=10;
  server 127.0.0.1:5178 max_fails=3 fail_timeout=20s weight=100 max_conns=10;
}

server {
    listen       8082;
    server_name  localhost;

    location / {
		proxy_next_upstream error timeout invalid_header http_502 http_504 http_404;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header   X-Forwarded-Proto $scheme;
		proxy_connect_timeout 20s;
		proxy_read_timeout 300s;
		proxy_send_timeout 300s;
		proxy_pass http://myserver;
    }

nginx -s reload

标签:http,weight,--,ip,consul,等待时间,proxy,超时,port
From: https://www.cnblogs.com/chenshaojun2008/p/17551372.html

相关文章

  • 【Netty】「源码解析」(三)设置连接超时:深入分析 ChannelFuture.sync() 的执行过程
    前言本篇博文是《从0到1学习Netty》中源码系列的第三篇博文,主要内容是深入分析连接超时的实现原理,包括了connect方法的源码解析和ChannelFuture.sync()执行过程的解析。,往期系列文章请访问博主的Netty专栏,博文中的所有代码全部收集在博主的GitHub仓库中;介绍在实际应用中,当......
  • python 执行超时装饰器
    代码:importsignalclassTimeoutError(Exception):passdeftimeout(seconds=10,error_message='Timeout'):defdecorator(func):defwrapper(*args,**kwargs):def_handle_timeout(signum,frame):raiseTi......
  • http 和 https区别,自动携带cookie的session对象,响应response,下载图片视频到本地,编码
    1.1自动携带cookie的session对象#session对象----》已经模拟登录上了一些网站---》单独把cookie取出来 -res.cookies-转成字典res.cookies.get_dict()#请求头和数据importrequestsheader={'Referer':'http://www.aa7a.cn/user.php?&ref=http%3A%2F%2......
  • springcloud - consul的简单使用和配置
    第一步:导入依赖 <!--   consul-->     <dependency>       <groupId>org.springframework.cloud</groupId>       <artifactId>spring-cloud-starter-consul-discovery</artifactId>     </dependency>第二......
  • 利用ansible批量部署node客户端,并注册consul,实现主机自动发现
      1.在管理机器上搭建consul并上传 node_exoporter软件包,system服务配置文件,注册脚本 2.利用ansible对指定机器去分发软件包并启动服务,并curl注册到consul  编写为node-exporter.yml 3.prometheus配置consul地址,获取主机信息,自动发现并配合grafana展示  system......
  • kubesphere consul搭建与测试
    1.部署不用改变参数,直接安装就行了2.部署情况部署以后,各个模块的数据应用:服务:这里有2个服务:consul-headless/consul-ui,consul-headless是主服务,后面测试会用到工作负载:容器: 3.测试在KubeSphere上搭建的Consul集群,可以使用以下方式测试是否正常工作:3.......
  • Springboot : 连接ldap超时问题
    Err:java.net.ConnectException:Connectiontimedoutwhenconnectingtoldap使用springbootldap连接账号所属ldap目录验证时,出现如上报错经检查,host,username,password等信息均无误,如下为代码中的配置信息示例hashEnv.put(Context.SECURITY_AUTHENTICATION,"simple"......
  • finalshell连接超时的解决方法
    CentOS图形管理中的NetworkManager接管了网络配置,可以尝试执行以下命令恢复:systemctlstopNetworkManager临时关闭systemctldisableNetworkManager永久关闭网络管理命令systemctlstartnetwork.service开启网络服务然后在本机中再次使用ping命令,发现可以ping通虚拟机ip,这时......
  • HTTP调用:你考虑到超时、重试、并发了吗?
    今天,我们一起聊聊进行HTTP调用需要注意的超时、重试、并发等问题。与执行本地方法不同,进行HTTP调用本质上是通过HTTP协议进行一次网络请求。网络请求必然有超时的可能性,因此我们必须考虑到这三点:首先,框架设置的默认超时是否合理;其次,考虑到网络的不稳定,超时后的请求重试是一个......
  • 拓端tecdat|R语言贝叶斯Metropolis-Hastings Gibbs 吉布斯采样器估计变点指数分布分析
    原文链接:http://tecdat.cn/?p=26578 原文出处:拓端数据部落公众号最近我们被客户要求撰写关于吉布斯采样器的研究报告,包括一些图形和统计输出。指数分布是泊松过程中事件之间时间的概率分布,因此它用于预测到下一个事件的等待时间,例如,您需要在公共汽车站等待的时间,直到下一班车......