consul使用

Consul簡介:

Consul是一套開源的分佈式服務發現和配置管理系統,由HashiCorp公司用Go語言開發。

提供了微服務系統中的服務治理、配置中心、控制總線等功能。這些功能中的每一個都可以根據需要單獨使用,也可以一起使用以構建全方位的服務網絡,總之Consul提供了一種完整的服務網格解決方案。

它具有很多優點。包括:基於 raft 協議,比較簡潔;支持健康檢查,同時支持 HTTP 和 DNS 協議 支持跨數據中心的 WAN 集羣 提供圖形界面 跨平臺,支持Linux、Mac、Windows

Consul功能:

服務發現:提供 HTTP 和 DNS 兩種發現方式
健康監測:支持多種方式,HTTP、TCP、Docker、Shell腳本定製化
KV存儲:Key、Value的存儲方式
多數據中心:Consul支持多數據中心
可視化界面

Consul中文文檔:https://www.springcloud.cc/spring-cloud-consul.html

先安裝consul:

進入官網:https://www.consul.io/intro/index.html

下載安裝包並安裝。

然後解壓後cmd進入consul的目錄;

可以通過consul --version查看consul的版本信息

通過consul agent -dev 啓動consul

關閉consul很簡單,把cmd窗口關閉consul自然關閉。

1、application.yml

###consull服務端口號
server:
  port: 8006

spring:
  application:
    name: consul-provider-peyment
###consul註冊中心地址
  cloud:
    consul:
      host: localhost
      port: 8500
      discovery:
        #hostname: 127.0.0.1
        service-name: ${spring.application.name}

2、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.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>cloud2020</artifactId>
        <groupId>com.atguigu.springcloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>cloud-providerconsul-payment8006</artifactId>

    <dependencies>
        <!--springcloud consul-server-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-discovery</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--日常通用jar包-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

其餘的和zookeeper一樣。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章