`
sillycat
  • 浏览: 2564741 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Spring Cloud Consul(2)Cluster

 
阅读更多
Spring Cloud Consul(2)Cluster
Install on Ubuntu
> wget https://releases.hashicorp.com/consul/1.4.0/consul_1.4.0_linux_amd64.zip
> unzip consul_1.4.0_linux_amd64.zip
Prepare the working directory
> mkdir ~/tool/consul-1.4.0
> mkdir ~/tool/consul-1.4.0/bin
Add to the PATH and check the installation
> consul version
Consul v1.4.0
Install on CentOS
> wget https://releases.hashicorp.com/consul/1.4.0/consul_1.4.0_linux_amd64.zip
Unzip and prepare the working directory
> mkdir -p ~/tool/consul-1.4.0/bin
> vi ~/.bash_profile
Check version on CentOS
> consul version
Consul v1.4.0
Prepare the Data directory, Start Master with -server Mode
> mkdir /opt/consul/data
> mkdir /opt/consul/conf
> consul agent -server -bootstrap -data-dir /opt/consul/data -node=agent-1 -bind=192.168.56.101 -advertise=192.168.56.101 -client=0.0.0.0 -config-dir /opt/consul/conf -datacenter dc1 -ui
Prepare the data and conf directory and start the Second Node Joining the Cluster
> consul agent -server -data-dir /opt/consul/data -node=agent-2 -bind=192.168.56.102 -advertise=192.168.56.102 -client=0.0.0.0 -config-dir /opt/consul/conf -datacenter dc1 -ui -retry-join "192.168.56.101"
Only one machine can start in -bootstrap mode, then We can visit the cluster in
http://ubuntu-master:8500/ui/dc1/services
Check members
> consul members
Node     Address              Status  Type    Build  Protocol  DC   Segment
agent-1  192.168.56.101:8301  alive   server  1.4.0  2         dc1  <all>
agent-2  192.168.56.102:8301  alive   server  1.4.0  2         dc1  <all>
Check IP on the ubuntu-master machine
> local_ip="`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`"
>  echo $local_ip
172.17.0.1 10.0.2.15 192.168.56.101
This can set up the default health check
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
/actuator/health
We can also implement the health check controller ourselves.
We can change the Producer API and Consumer API to connect to the cluster and Customer the Health Check if we need to.
Producer API 1
spring:
application:
  name: springcloud-consul-producer
cloud:
  consul:
   host: ubuntu-master
   port: 8500
   discovery:
    hostname: ubuntu-master
    enabled: true
    serviceName: consul-producer
    health-check-interval: 10s
    register: true
    health-check-path: /health
    tags: owner=Sillycat
server:
port: 8501
Health Check
    @GetMapping("/health")
    public String health(){
        return "hello consul";
    }
Producer API 2
spring:
application:
  name: springcloud-consul-producer
cloud:
  consul:
   host: ubuntu-master
   port: 8500
   discovery:
    hostname: centos-dev1
    enabled: true
    serviceName: consul-producer
    health-check-interval: 10s
    register: true
    health-check-path: /health
    tags: owner=Kiko
server:
port: 8502
Health Check
    @GetMapping("/health")
    public String health(){
        return "hello consul";
    }
More Configuration
https://www.imooc.com/article/22441
Check the Cluster from my Local
> consul members -http-addr=ubuntu-master:8500
Node     Address              Status  Type    Build  Protocol  DC   Segment
agent-1  192.168.56.101:8301  alive   server  1.4.0  2         dc1  <all>
agent-2  192.168.56.102:8301  alive   server  1.4.0  2         dc1  <all>
It can be used as the configuration sharing center
https://gitbook.cn/books/5b38d875d00fdd680bb774e8/index.html

References:
https://my.oschina.net/tree/blog/1594206

分享到:
评论

相关推荐

    springCloud demo

    SpringCloud Demo 亲测可用 Spring Cloud是一系列框架的有序集合. 主要的小弟有:Spring Cloud Config、Spring Cloud Netflix(Eureka、Hystrix、Zuul、Archaius…)、Spring Cloud Bus、Spring Cloud for Cloud ...

    springcloud学习笔记.docx

    2. **Spring Cloud Netflix**:这是 SpringCloud 的核心组件,它整合了 Netflix 的多个开源组件,如: - **Eureka**:作为服务治理组件,Eureka 提供服务注册与发现功能,可以让服务提供者自动注册到 Eureka 服务器...

    SpringCloud示例代码

    7. **一次性 Token** (OAuth2): Spring Cloud Security 提供了 OAuth2 的支持,用于生成一次性 Token,确保请求的安全性,防止未授权访问。 8. **全局锁** (Distributed Lock): 在分布式系统中,全局锁用于保证在多...

    Spring Cloud 微服务架构详细指南.docx

    - **集群状态管理**:利用 Spring Cloud Cluster 管理集群状态。 #### 三、环境搭建 1. **安装 JDK 和 Maven** - 确保已经安装了 JDK 8 或更高版本。 - 安装 Maven 进行项目管理和构建。 ```bash sudo apt-...

    Spring Cloud实战指南:构建微服务架构的配置、教程与源代码分析.pdf

    - **领导选举**:利用Spring Cloud Cluster实现。 - **分布式会话**:通过Spring Session实现跨服务的会话共享。 - **集群状态**:例如使用Consul进行服务的状态管理。 #### 二、Spring Cloud配置中心 Spring ...

    springCloud.docx

    Spring Cloud 提供了 Ribbon,这是一个客户端负载均衡器,它可以与 Eureka、Consul 等服务发现组件结合使用。Ribbon 提供了多种负载均衡策略,例如轮询(Round Robin)、随机(Random)、最不常使用(Least ...

    hope-cloud:Hope-Cloud是一个Java微服务项目

    第三个开源作品地址: : 技术栈Spring Cloud Config,Spring Cloud Netflix(Eureka,Hystrix,Zuul,Archaius…),Spring Cloud Bus,Spring Cloud for Foundry,Spring Cloud Cluster,Spring Cloud Consul,...

    微服务技术体系.docx

    - **Spring Cloud Consul**:使用Consul进行服务发现和配置管理。 - **Spring Cloud Security**:实现安全认证和授权。 - **Spring Cloud Sleuth**:跟踪分布式系统中的请求链路。 - **Spring Cloud Data Flow**...

    微服务搭建集成Spring Cloud Turbine详解

    Turbine使用了Spring Cloud的DiscoveryClient接口,这意味着它可以与Eureka、Consul等服务发现组件集成,自动发现并聚合所有提供Hystrix Metrics Stream的服务。 在实际的微服务环境中,我们通常会有如下的服务配置...

    Cloud分布式

    16. **Spring Cloud Cluster**: 提供领导选举机制,支持多种集群管理模式。 17. **Spring Cloud Starters**: 提供了一系列预配置的依赖项,简化了项目的搭建过程。 #### 五、总结 通过上述介绍可以看出,**Spring ...

    Java面试题全集(REDIS+数据库+框架+微服务+nnetty)

    对于Spring Cloud,重点在于服务发现(Eureka、Consul)、熔断机制(Hystrix)、负载均衡(Ribbon、Feign)以及API网关(Zuul、Gateway)等微服务治理组件。 微服务篇则会深入探讨微服务架构的优点、挑战及其实践。...

    架构师最新面试专题.zip

    2. Spring Cloud:为微服务提供一套完整的解决方案,包括服务发现、配置中心、断路器、路由、熔断等。 3. Spring Data:简化数据库操作,支持JPA、MyBatis等持久层框架。 4. Spring AOP:实现切面编程,进行非业务...

    面试题.zip

    了解服务发现(如Eureka、Consul),API Gateway(如Zuul、Spring Cloud Gateway),以及服务间的通信方式(RESTful API、gRPC、Dubbo等)。理解Docker容器化和Kubernetes编排系统在微服务部署中的作用。 【消息...

    Dubbo面试题(2022最新版)

    2. **Dubbo和SpringCloud有什么关系?** Dubbo和Spring Cloud都是用于构建分布式系统的框架,但它们的设计理念有所不同。Dubbo更专注于服务治理,而Spring Cloud则侧重于微服务架构的整体解决方案。 3. **Dubbo和...

    nacos-server-1.2.1.tar.gz

    1. **Spring Cloud集成**:Nacos可以很好地与Spring Cloud生态结合,作为服务注册与发现的组件,简化微服务的构建。 2. **配置中心**:在微服务架构中,Nacos可以替代传统的配置管理工具如Zookeeper或Consul,提供...

    sentinel windows下的管理控制台

    6. **数据源适配**:Sentinel 控制台可以接入不同数据源,如 Spring Cloud Config、Consul 等,实现规则的集中化管理。 **安装 Sentinel 控制台步骤:** 1. 首先,从 Sentinel 的官方仓库或 Maven 中心仓库下载...

    Java面试 Java分布式知识点 Java微服务知识点 面试知识点

    Dubbo专注于RPC调用,强调服务治理,而Spring Cloud是基于Spring Boot的全面微服务解决方案,包括配置管理、服务发现、断路器、智能路由、微代理等更多功能。 **Dubbo支持的协议** Dubbo支持多种通信协议,如Dubbo...

    分布式Java应用基础与实践_文字版__中文

    例如,使用Atomikos或Seata等工具解决分布式事务的一致性问题,采用Spring Cloud或Service Mesh来构建微服务架构,以及使用Docker和Kubernetes进行应用的自动化部署和管理。 总的来说,分布式Java应用基础与实践...

    apache-dubbo-2.7.5-src.zip

    例如,2.7.x版本引入了更多的微服务特性,如Spring Cloud集成、熔断机制、配置中心等,这些都是现代分布式系统中不可或缺的部分。 总的来说,分析和学习Apache Dubbo 2.7.5的源码,不仅可以加深对RPC框架的理解,还...

Global site tag (gtag.js) - Google Analytics