假设当前服务器的ip是:192.168.56.130

允许 所有ip 注册

  consul agent -server -ui -bootstrap-expect=1 -data-dir=/usr/local/consul -node=devmaster -advertise=192.168.56.130 -bind=0.0.0.0 -client=0.0.0.0

只允许 当前ip 注册

  consul agent -server -ui -bootstrap-expect=1 -data-dir=/usr/local/consul -node=devmaster -advertise=192.168.56.130 -bind=192.168.56.130 -client=127.0.0.1

  此时,若别的ip的项目想要连接这个Consul,那么启动就会报错:
  com.ecwid.consul.transport.TransportException: org.apache.http.conn.HttpHostConnectException: Connect to 192.168.56.130:8500 [/192.168.56.130] failed: Connection refused: connect

需要注意:
       1、-bind要用完整ip地址,如果使用127.0.0.1,否则虽然consul能启动,但是consul日志会不停地打印如下信息
    2018/12/17 15:56:14 [WARN] consul: error getting server health from "devmaster": context deadline exceeded
    2018/12/17 15:56:15 [WARN] consul: error getting server health from "devmaster": rpc error getting client: failed to get conn: dial tcp 127.0.0.1:0->192.168.56.130:8300: connect: connection refused
    2018/12/17 15:56:16 [WARN] consul: error getting server health from "devmaster": context deadline exceeded
    2018/12/17 15:56:17 [WARN] consul: error getting server health from "devmaster": rpc error getting client: failed to get conn: dial tcp 127.0.0.1:0->192.168.56.130:8300: connect: connection refused

2、-client 需要用127.0.0.1,如果用完整的ip地址,consul都启动不起来

3、consul agent -dev 也是只允许当前ip注册,但这个是本地开发时用的,正式服务器往往不用

4、这时项目中的配置文件也要相应的更改,使用127.0.0.1 ,而不是完整ip地址。否则,项目在服务器端也启动不起来了,囧

spring:
  cloud:
    consul:
      host: 127.0.0.1
      port: 8500

原创文章,欢迎转载,转载请注明出处!

consul如何限制注册的ip的更多相关文章

  1. 简单RPC框架-基于Consul的服务注册与发现

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  2. SpringBoot系列: 使用 consul 作为服务注册组件

    本文基本上摘自纯洁的微笑的博客 http://www.ityouknow.com/springcloud/2018/07/20/spring-cloud-consul.html . 感谢作者的付出. ...

  3. .net core grpc consul 实现服务注册 服务发现 负载均衡(二)

    在上一篇 .net core grpc 实现通信(一) 中,我们实现的grpc通信在.net core中的可行性,但要在微服务中真正使用,还缺少 服务注册,服务发现及负载均衡等,本篇我们将在 .net ...

  4. .netcore consul实现服务注册与发现-集群完整版

    原文:.netcore consul实现服务注册与发现-集群完整版 一.Consul的集群介绍    Consul Agent有两种运行模式:Server和Client.这里的Server和Clien ...

  5. .netcore consul实现服务注册与发现-单节点部署

    原文:.netcore consul实现服务注册与发现-单节点部署 一.Consul的基础介绍     Consul是HashiCorp公司推出的开源工具,用于实现分布式系统的服务发现与配置.与其他分 ...

  6. .netcore consul实现服务注册与发现-集群部署

    一.Consul的集群介绍 Consul Agent有两种运行模式:Server和Client.这里的Server和Client只是Consul集群层面的区分,与搭建在Cluster之上的应用服务无关 ...

  7. .Net Core Grpc Consul 实现服务注册 服务发现 负载均衡

    本文是基于..net core grpc consul 实现服务注册 服务发现 负载均衡(二)的,很多内容是直接复制过来的,..net core grpc consul 实现服务注册 服务发现 负载均 ...

  8. Spring Cloud Consul 实现服务注册和发现

    Spring Cloud 是一个基于 Spring Boot 实现的云应用开发工具,它为基于 JVM 的云应用开发中涉及的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全局锁.决策竞选.分布 ...

  9. Spring Cloud Consul使用——服务注册与发现(注册中心)

    整理自该文章 一.Consul 服务端接下来我们开发 Consul 的服务端,创建一个 spring-cloud-consul-producer 项目 1.添加依赖包 <dependencies ...

随机推荐

  1. Vs2017 xaramin mac build agent部署后记

                    换了四种黑苹果,最终成功了                 步骤: 1.升级vs2017, 2.安装XCODE 8.3 3.安装vs2017 for mac 企业版 4 ...

  2. ArcGIS JavaScriptAPI----- 缓冲区操作

    描述 使用ArcGIS Server 几何服务(geometry service)来对绘制在地图上的图形生成缓冲区.几何服务能够在基于浏览器的应用程序中执行缓冲操作(buffering),投影要素(p ...

  3. 阿里云 API调用实践(python语言)

    1.结论:阿里云的SDK开发,其实就是远程调用API,python的代码就是一个外壳,核心是封装成一个http报文,利用json格式,进行RPC调用. 2.SDK调用API的套路如下: # -*- c ...

  4. Paint.FontMetrics

    要了解TextView对文本的绘制,那么就需要了解Paint.FontMetircs. 官方对该类的解释是:Class that describes the various metrics for a ...

  5. Android为TV端助力 进制互相转换

    byte转换为16进制 public static String GetByte2Str(byte b) { byte[] buff = new byte[2]; buff[0] = mHex[(b ...

  6. Java基础static的探究

    static方法就是没有this的方法. 在static方法内部不能调用非静态方法, 但是在非静态的方法中可以调用静态的方法和变量. 而且可以在没有创建任何对象的前提下,仅仅通过类本身来调用stati ...

  7. 使用django 中间件在所有请求前执行功能

    django中间是一个轻级,低耦合的插件,用来改变全局的输入和输出. 一 如何使用中间件 定义中间件 注册中间件 # 这是一个中间件代码片段的说明,在各个位置的代码将在何时执行 def simple_ ...

  8. mssql sqlserver 指定特定值排在表前面

    转自:http://www.maomao365.com/?p=7141 摘要: 下文讲述sql脚本编写中,将 特定值排在最前面的方法分享, 实验环境:sqlserver 2008 R2 例:将数据表中 ...

  9. 安装Linux内核源代码

    系统:Ubuntu 18 CPU架构:AMD64 1,在终端输入:sudo apt install linux-source 命令 2,进入/usr/src/linux-source-4.15.0目录 ...

  10. LeetCode算法题-Design LinkedList(Java实现)

    这是悦乐书的第300次更新,第319篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第168题(顺位题号是707).设计链表的实现.您可以选择使用单链表或双链表.单链表中的 ...