假设当前服务器的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. 【面向对象设计原则】之单一职责原则(SRP)

    单一职责原则是面向对象原则五大原则中最简单,也是最重要的一个原则, 他的字面定义如下: 单一职责原则(Single Responsibility Principle, SRP): 一个类只负责一个功能 ...

  2. iOS----------计算一段代码执行时间

    CFAbsoluteTime start = CFAbsoluteTimeGetCurrent(); //在这写入要计算时间的代码 // do something CFAbsoluteTime end ...

  3. 面板JPanel,滚动面板JScrollPane,文本域JTextArea

    [面板JPanel] 面板就是一个容器 每一个容器都可以有一个自己的独立的布局和组件,这些容器之间也不会互相干扰 //导入Java类 import javax.swing.*; import java ...

  4. windows10禁用更新方法

    本方法由本人在无意中发现,实测有效 1.第一步 打开文件管理器路径进入到win10的下载更新文件的目录 C:\Windows\SoftwareDistribution ​ 选中Download文件夹 ...

  5. python3 deque(双向队列)

    创建双向队列 import collections d = collections.deque() append(往右边添加一个元素) import collections d = collectio ...

  6. JavaScript -- 原型:prototype的使用

    JavaScript -- 原型:prototype的使用 在 JavaScript 中,prototype 是函数的一个属性,同时也是由构造函数创建的对象的一个属性. 函数的原型为对象. 它主要在函 ...

  7. There Are Now 3 Apache Spark APIs. Here’s How to Choose the Right One

    See Apache Spark 2.0 API Improvements: RDD, DataFrame, DataSet and SQL here. Apache Spark is evolvin ...

  8. excel poi导出demo

    最近做了一个excel 导出的demo,是抄写老大的(嘻嘻嘻),现在把demo源码放在这里 链接:https://pan.baidu.com/s/1_xj0hej-1xwX5JF39acEOg 提取码 ...

  9. [LeetCode] 12,13 整数和罗马数互转

    12. 整数转罗马数字 题目链接:https://leetcode-cn.com/problems/integer-to-roman/ 题目描述: 罗马数字包含以下七种字符: I, V, X, L,C ...

  10. Linux后台命令的使用说明

    1)ctrl+Z:停止当前进程 首先先将一个程序运行起来,这个时候如果你需要去干别的事情,需要暂停运行,可以使用ctrl+Z: user@mine:/opt/user/pytorch-gender$ ...