consul

SpringCloud-Consul开发环境配置

不想你离开。 提交于 2019-12-10 14:56:10
一、consul安装 1、下载: https://www.consul.io/downloads.html ; 2、选择版本:本人开发环境是windows,所以选择win64; 3、安装:保存至D:/SpringCloud/consul(自定义路径,linux将保存路径加到PATH),执行consul -v,没报错说明安装成功; 4、启动consul:搭建集群环境至少需要3个节点,本次只介绍本地开发调试,使用开发者模式启动即可,进入consul文件夹,执行consul agent -dev; 5、检验是否启动成功:打开浏览器,访问 http://localhost:8500 从界面可以看到consul能做什么:服务发现、健康检查、K/V存储、多数据中心; 二、新建Srping Cloud Consul项目(此文仅为记录,以下源码参考重新定义springcloud示例) 1、创建Maven父级pom工程 <? xml version ="1.0" encoding ="UTF-8" ?> <project xmlns ="http://maven.apache.org/POM/4.0.0" xmlns: xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi :schemaLocation ="http://maven.apache

Spring Cloud自动推送配置到Consul配置中心

三世轮回 提交于 2019-12-10 06:10:57
Consul 是一个集配置管理、服务注册和发现于一体的微服务基础组件,它提供的这些功能我们在微服务开发中都用到了。在实践中,我们发现 Spring Cloud 没有提供在启动时自动加载某一个配置文件到 Consul 配置中心的功能,于是参照 Consul 社区的一个开源项目 cfg4j-pusher 进行了二次开发,实现了 Spring Boot 应用启动时自动加载指定配置文件到 Consul 配置中心的功能。以下是软件环境: JDK 1.8 Maven 3.3.9 Spring Boot 2.0.0.RELEASE Spring Cloud Finchley.M8 Consul 1.2.2 实现过程 在这里我新建一个工程来说明实现过程,整个工程的结构如下: 整个工程依照 Spring Boot 工程的目录结构创建,在 com.consul.pusher 包下有四个类,其中 ConsulApplication 的作用就不用说了,它是整个服务的启动类。剩下的三个类说明如下: ConsulConfig :提供加载配置到 Consul 中的操作。它定义了一个私有的 init 方法,这个方法被 @PostConstruct 注解所标记,主要作用是在 ConsulConfig 依赖注入完成之后读取指定配置文件,将文件里的配置信息推送到 Consul 配置中心中

Eureka服务发现---SpringCloud(一)

五迷三道 提交于 2019-12-10 06:10:44
Eureka服务发现 (一)前言 服务治理是微服务架构中最为核心的基础模块,主要用来实现各个微服务实例的自动化注册和发现; 在微服务最开始的时候,服务并不多,我们可以通过静态配置来完成服务间的调用;若A服务调用B服务,对B服务做了HA,我们可以手动维护一份B实例的清单, 当B服务某些实例不可用,还可以手动去清除部分不可用的实例;但随着业务的发展,需要维护的B实例越来越多,系统功能也越来越复杂,维护难度可想而知;而且相同 服务不同实例很可能会命名冲突,配置冲突等,如port; 因此我们需要一个服务治理框架和产品,来对不同服务的多个实例进行自动化的维护; 目前服务治理框架有Netflix的Eureka,alibaba的Dubbo等,这些框架的实现都围绕着服务注册与服务发现机制来完成对微服务应用实例的自动化管理; (二)搭建服务注册中心 我们使用project-module的形式创建项目; 我们创建一个CloudServer的项目, <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven

Spring Cloud(二) Consul 服务治理实现

雨燕双飞 提交于 2019-12-10 06:03:29
Spring Cloud Consul 项目是针对Consul的服务治理实现。Consul是一个分布式高可用的系统,具有分布式、高可用、高扩展性。 Consul 简介 Consul 是 HashiCorp 公司推出的开源工具,用于实现分布式系统的服务发现与配置。与其他分布式服务注册与发现的方案,Consul的方案更“一站式” ,内置了服务注册与发现框 架、 具有以下性质: 分布一致性协议实现、 健康检查、 Key/Value存储、 多数据中心方案, 不再需要依赖其他工具(比如ZooKeeper等)。 使用起来也较 为简单。Consul使用Go语言编写,因此具有天然可移植性(支持Linux、windows和Mac OS X);安装包仅包含一个可执行文件,方便部署,与Docker等轻量级容器可无缝配合 。 基于 Mozilla Public License 2.0 的协议进行开源. Consul 支持健康检查,并允许 HTTP 和 DNS 协议调用 API 存储键值对. 一致性协议采用 Raft 算法,用来保证服务的高可用. 使用 GOSSIP 协议管理成员和广播消息, 并且支持 ACL 访问控制. Consul 的使用场景 docker 实例的注册与配置共享 coreos 实例的注册与配置共享 vitess 集群 SaaS 应用的配置共享 与 confd 服务集成,动态生成

Spring Cloud Finchley.SR1 的学习与应用 8

时间秒杀一切 提交于 2019-12-10 05:50:15
基于consul和git的配置中心 在《Spring Cloud Finchley.SR1 的学习与应用 2 - Consul》中讲述来consul和git2consul的安装。这边文章讲述以下基于基于consul和git的配置中心。 准备工作 启动consul server 和 git2consul,在git仓库中新建common-server-config-respo模块,用来存储配置文件。将common-server-config-respo/business-a-woqu/application.yml文件推送至git仓库。application.yml内容如下: extend: info: desc: i am business a dev modify 关于配置文件,请看 这里 添加配置中心模块 以server-businessa-woqu为例,添加配置中心模块 POM 在pom.xml中加入以下依赖: <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-consul-config</artifactId> </dependency> 配置文件 分离配置文件,建立application.yml、bootstrap.yml两个配置文件

Spring Cloud Finchley.SR1 的学习与应用 2

随声附和 提交于 2019-12-10 05:39:51
Spring Cloud Consul 简介 consul是google开源的一个使用go语言开发的服务发现、配置管理中心服务。内置了服务注册与发现框 架、分布一致性协议实现、健康检查、Key/Value存储、多数据中心方案,不再需要依赖其他工具(比如ZooKeeper等)。服务部署简单,只有一个可运行的二进制的包。每个节点都需要运行agent,他有两种运行模式server和client。每个数据中心官方建议需要3或5个server节点以保证数据安全,同时保证server-leader的选举能够正确的进行。 Consul的安装 1.安装 mkdir -p /opt/consul cd /opt/consul/ wget https://releases.hashicorp.com/consul/1.2.0/consul_1.2.0_linux_amd64.zip unzip consul_1.2.0_linux_amd64.zip 2.启动consul mkdir -p /opt/consul/config mkdir -p /opt/consul/data #启用Gossip加密方式,只需要在启动Agent时设置加密密钥。通过encrypt参数设置密钥:设置的值是包含密钥的配置文件。 $ ./consul keygen xZpdVT6DUTzQrYyf2B2uCQ== vim

consul & registrator & consul-template 使用

末鹿安然 提交于 2019-12-10 03:56:07
consul & registrator & consul-template 使用 参考这里的文章: https://www.jianshu.com/p/a4c04a3eeb57 docker-compose.yml version: '3' services: web: image: liberalman/helloworld:latest environment: SERVICE_80_NAME: my-web-server SERVICE_TAGS: backend-1 MY_HOST: host-1 ports: - "80" lb: image: liberalman/nginx-consul-template:latest hostname: lb links: - consulserver:consul ports: - "80:80" consulserver: image: progrium/consul:latest environment: SERVICE_TAGS: consul servers hostname: consulserver ports: - "8300" - "8400" - "8500:8500" - "53" command: -server -ui-dir /ui -data-dir /tmp/consul -bootstrap

Linux下Consul集群配置实践

点点圈 提交于 2019-12-09 16:28:57
一、Consul官网 地址: https://www.consul.io 说明: https://www.consul.io/intro/ 文档: https://www.consul.io/docs/commands/ 二、Consul功能 Service Discovery 服务发现 Failure Detection 故障探测 Multi Datacenter 多数据中心 Key/Value Storage KV存储 三、配置环境 操作系统:CentOS 7.0 软件版本:consul-0.7.5 采用3节点consul server 192.168.1.101 192.168.1.102 192.168.1.103 192.168.1.104 101,102,103做server,104做client (一).Server端 https://www.consul.io/intro/getting-started/agent.html 1.安装(所有节点) wget https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_linux_amd64.zip wget https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_web_ui.zip mkdir /home

consul golang

荒凉一梦 提交于 2019-12-08 19:23:29
服务注册: package main import ( "log" "github.com/gin-gonic/gin" consulapi "github.com/hashicorp/consul/api" "fmt" "net/http" ) func main() { // 服务注册 registerServer() r := gin.Default() r.GET("/ping", heathCheck) r.Run() } // consul 服务注册 func registerServer() { // 创建consul客户端 config := consulapi.DefaultConfig() config.Address = "172.16.30.129:8500" client, err := consulapi.NewClient(config) if err != nil { log.Fatal("consul client error : ", err) } registration := new(consulapi.AgentServiceRegistration) registration.ID = "c1" // 服务节点的名称 registration.Name = "wsp" // 服务名称 registration.Port = 8080 //

how to define HTTP health check in a consul container for a service on the same host?

眉间皱痕 提交于 2019-12-08 13:22:36
We are using a consul agent on a host that also runs a service. (RabbitMQ) To verify that the service is ready we have defined a curl based health check. however, we are using the registrator to inject this check using env variable. SERVICE_CHECK_SCRIPT=curl hostname :15672/.... problem is, we've also told the consul-agent that its hostname is the same as the host. (We must have this feature since we want to see the correct hostname registered with the consul cluster. When the consul agent runs the health check, it looks for the URL on its own container... this obviously fails... does anybody